feat: 积分商城-供应商-对账-发票
This commit is contained in:
@@ -12,6 +12,44 @@ type BridgePointsResponse = {
|
||||
}
|
||||
|
||||
export const supplierService = {
|
||||
decryptSupplierSession(keyword: string) {
|
||||
if (!keyword) {
|
||||
return serviceFail('用户参数不能为空')
|
||||
}
|
||||
|
||||
const keyHex = process.env.SM4CBC_KEY_HEX || 'a1b2c3d4e5f60718293a4b5c6d7e8f90'
|
||||
const ivHex = process.env.SM4CBC_IV_HEX || 'f9e8d7c6b5a49382716f0e1d2c3b4a5f'
|
||||
const sessionKeyword = keyword.replace(/ /g, '+')
|
||||
|
||||
logger.info('supplier session decrypt input', {
|
||||
keyword,
|
||||
sessionKeyword,
|
||||
hasKey: Boolean(keyHex),
|
||||
hasIv: Boolean(ivHex),
|
||||
keyLength: keyHex.length,
|
||||
ivLength: ivHex.length
|
||||
})
|
||||
|
||||
try {
|
||||
const decryptedText = sm4CbcDecrypt(sessionKeyword, keyHex, ivHex)
|
||||
logger.info('supplier session decrypt text', { decryptedText })
|
||||
const payload = JSON.parse(decryptedText) as { userId?: unknown }
|
||||
const userId = String(payload.userId || '').trim()
|
||||
|
||||
if (!userId) {
|
||||
logger.warn('supplier session userId empty', { payload })
|
||||
return serviceFail('用户参数无效')
|
||||
}
|
||||
|
||||
return serviceOk({ userId })
|
||||
} catch (error) {
|
||||
logger.warn('supplier session decrypt failed', {
|
||||
message: error instanceof Error ? error.message : String(error)
|
||||
})
|
||||
return serviceFail('用户参数无效')
|
||||
}
|
||||
},
|
||||
|
||||
async getSupplierInfo(supplierIdentification: string) {
|
||||
logger.info('supplier info query', { supplierIdentification })
|
||||
|
||||
@@ -33,29 +71,11 @@ export const supplierService = {
|
||||
})
|
||||
},
|
||||
|
||||
async warmSupplierToken(encryptedParam: string, supplierIdentification: string) {
|
||||
logger.info('supplier token warmup', { supplierIdentification })
|
||||
async warmSupplierToken(userId: string, supplierIdentification: string) {
|
||||
logger.info('supplier token warmup', { userId, supplierIdentification })
|
||||
|
||||
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')
|
||||
if (!userId || !supplierIdentification) {
|
||||
return serviceFail('用户信息和供应商唯一标识不能为空')
|
||||
}
|
||||
|
||||
const supplier = await findSupplierByIdentification(supplierIdentification).catch(error => error)
|
||||
|
||||
Reference in New Issue
Block a user