优化电子凭证接口日志和结果展示
This commit is contained in:
@@ -33,11 +33,12 @@ export async function requestKuaishouIndustryOpenApi(
|
||||
input: KuaishouIndustryOpenApiCallInput,
|
||||
): Promise<KuaishouIndustryOpenApiCallResult> {
|
||||
let config = getKuaishouIndustryConfig()
|
||||
const apiLabel = formatKuaishouOpenApiLabel(input.apiMethod)
|
||||
|
||||
if (!config.enabled) {
|
||||
logKuaishouOpenApi(
|
||||
input,
|
||||
`快手 OpenAPI 未启用,跳过 ${input.apiMethod}`,
|
||||
`快手 OpenAPI 未启用,跳过 ${apiLabel}`,
|
||||
undefined,
|
||||
)
|
||||
return { success: true, skippedReason: 'disabled' }
|
||||
@@ -56,7 +57,7 @@ export async function requestKuaishouIndustryOpenApi(
|
||||
} catch (error) {
|
||||
logKuaishouOpenApi(
|
||||
input,
|
||||
`快手 OpenAPI token 准备失败 ${input.apiMethod}`,
|
||||
`快手 OpenAPI token 准备失败 ${apiLabel}`,
|
||||
resolveKuaishouOpenApiErrorDetail(error),
|
||||
'warn',
|
||||
)
|
||||
@@ -71,7 +72,7 @@ export async function requestKuaishouIndustryOpenApi(
|
||||
if (!config.accessToken) {
|
||||
logKuaishouOpenApi(
|
||||
input,
|
||||
`快手 OpenAPI accessToken 缺失 ${input.apiMethod}`,
|
||||
`快手 OpenAPI accessToken 缺失 ${apiLabel}`,
|
||||
undefined,
|
||||
'warn',
|
||||
)
|
||||
@@ -110,7 +111,7 @@ export async function requestKuaishouIndustryOpenApi(
|
||||
})
|
||||
|
||||
input.onRequest?.(requestLog)
|
||||
logKuaishouOpenApi(input, `发起快手 OpenAPI ${input.apiMethod}`, requestLog)
|
||||
logKuaishouOpenApi(input, `发起快手 OpenAPI ${apiLabel}`, requestLog)
|
||||
|
||||
try {
|
||||
const startedAt = Date.now()
|
||||
@@ -134,8 +135,8 @@ export async function requestKuaishouIndustryOpenApi(
|
||||
logKuaishouOpenApi(
|
||||
input,
|
||||
success
|
||||
? `快手 OpenAPI 调用成功 ${input.apiMethod}`
|
||||
: `快手 OpenAPI 调用失败 ${input.apiMethod}`,
|
||||
? `快手 OpenAPI 调用成功 ${apiLabel}`
|
||||
: `快手 OpenAPI 调用失败 ${apiLabel}`,
|
||||
{
|
||||
durationMs,
|
||||
httpStatus: res.status,
|
||||
@@ -156,7 +157,7 @@ export async function requestKuaishouIndustryOpenApi(
|
||||
const errorDetail = resolveKuaishouOpenApiErrorDetail(error)
|
||||
logKuaishouOpenApi(
|
||||
input,
|
||||
`快手 OpenAPI 调用异常 ${input.apiMethod}`,
|
||||
`快手 OpenAPI 调用异常 ${apiLabel}`,
|
||||
{
|
||||
...errorDetail,
|
||||
request: requestLog,
|
||||
@@ -187,6 +188,7 @@ export function buildKuaishouOpenApiRequestLog({
|
||||
url,
|
||||
method: httpMethod || 'POST',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
apiName: resolveKuaishouOpenApiName(signParams.method),
|
||||
apiMethod: signParams.method,
|
||||
appkey: signParams.appkey,
|
||||
access_token: signParams.access_token,
|
||||
@@ -251,3 +253,25 @@ function logKuaishouOpenApi(
|
||||
|
||||
logIntegration('[kuaishou-industry/openapi]', message, detail, { level })
|
||||
}
|
||||
|
||||
function formatKuaishouOpenApiLabel(method: unknown): string {
|
||||
const apiMethod = String(method || '').trim()
|
||||
const apiName = resolveKuaishouOpenApiName(apiMethod)
|
||||
return apiName ? `${apiName}(${apiMethod})` : apiMethod
|
||||
}
|
||||
|
||||
function resolveKuaishouOpenApiName(method: unknown): string {
|
||||
const apiMethod = String(method || '').trim()
|
||||
const names: Record<string, string> = {
|
||||
'integration.callback.virtual.eticket.send': '电子凭证发货回调',
|
||||
'integration.callback.virtual.eticket.consume': '电子凭证核销回调',
|
||||
'integration.callback.virtual.eticket.destroy': '电子凭证销毁回调',
|
||||
'integration.callback.virtual.eticket.reverse': '电子凭证冲正回调',
|
||||
'open.virtual.eticket.checkavailable': '检查电子凭证有效性',
|
||||
'open.seller.order.refund.pcursor.list': '售后单列表',
|
||||
'open.seller.order.refund.approve': '商家同意退款',
|
||||
'open.seller.order.refund.disagree.refund': '商家不同意退款',
|
||||
}
|
||||
|
||||
return names[apiMethod] || ''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user