feat: 积分商城-供应商-对账
This commit is contained in:
@@ -2,7 +2,7 @@ import { supplierDao } from '../dao/supplier.dao.js'
|
||||
import { bridgeFetchWithAuth, findSupplierByIdentification, getBridgeApiBase, getBridgeToken, warmBridgeToken } from '../utils/bridge-auth.js'
|
||||
import { sha256 } from '../utils/crypto.js'
|
||||
import { logger } from '../utils/logger.js'
|
||||
import { createSupplierOpenSignature } from '../utils/supplier-open-crypto.js'
|
||||
import { createSupplierOpenSignature, sm4CbcDecrypt } from '../utils/supplier-open-crypto.js'
|
||||
import { serviceFail, serviceOk } from '../types/service-result.js'
|
||||
|
||||
type BridgePointsResponse = {
|
||||
@@ -33,11 +33,29 @@ export const supplierService = {
|
||||
})
|
||||
},
|
||||
|
||||
async warmSupplierToken(userId: string, supplierIdentification: string) {
|
||||
logger.info('supplier token warmup', { userId, supplierIdentification })
|
||||
async warmSupplierToken(encryptedParam: string, supplierIdentification: string) {
|
||||
logger.info('supplier token warmup', { supplierIdentification })
|
||||
|
||||
if (!userId || !supplierIdentification) {
|
||||
return serviceFail('用户信息和供应商唯一标识不能为空')
|
||||
if (!encryptedParam || !supplierIdentification) {
|
||||
return serviceFail('加密用户参数和供应商唯一标识不能为空')
|
||||
}
|
||||
|
||||
const keyHex = process.env.SUPPLIER_OPEN_SM4_KEY_HEX || process.env.SM4CBC_KEY_HEX || ''
|
||||
const ivHex = process.env.SUPPLIER_OPEN_SM4_IV_HEX || process.env.SM4CBC_IV_HEX || ''
|
||||
if (!keyHex || !ivHex) {
|
||||
return serviceFail('供应商开放接口SM4配置缺失', 500, 'SM4_CONFIG_MISSING')
|
||||
}
|
||||
|
||||
let userId = ''
|
||||
try {
|
||||
const decrypted = sm4CbcDecrypt(encryptedParam.replace(/ /g, '+'), keyHex, ivHex)
|
||||
const params = JSON.parse(decrypted) as { userId?: string }
|
||||
userId = String(params.userId || '').trim()
|
||||
} catch (error) {
|
||||
return serviceFail('用户参数解密失败', 400, 'INVALID_USER_PARAM')
|
||||
}
|
||||
if (!userId) {
|
||||
return serviceFail('用户信息不能为空', 400, 'USER_ID_MISSING')
|
||||
}
|
||||
|
||||
const supplier = await findSupplierByIdentification(supplierIdentification).catch(error => error)
|
||||
|
||||
Reference in New Issue
Block a user