feat(M08-B): 接入保洁微信转账适配器
This commit is contained in:
@@ -10,6 +10,9 @@ export interface WechatPayCredential {
|
||||
apiV3Key: string;
|
||||
platformCertificates: Record<string, string>;
|
||||
profitShareReceivers?: Record<string, string>;
|
||||
transferSceneId?: string;
|
||||
transferSceneReportInfos?: Array<{ infoType: string; infoContent: string }>;
|
||||
transferNotifyUrl?: string;
|
||||
}
|
||||
|
||||
export interface WechatPayTransport {
|
||||
@@ -173,6 +176,40 @@ export class WechatPayClient {
|
||||
});
|
||||
}
|
||||
|
||||
async createMerchantTransfer(
|
||||
credential: WechatPayCredential,
|
||||
input: {
|
||||
outBillNo: string;
|
||||
openid: string;
|
||||
amountCents: number;
|
||||
remark: string;
|
||||
sceneId: string;
|
||||
notifyUrl?: string;
|
||||
reportInfos: Array<{ infoType: string; infoContent: string }>;
|
||||
}
|
||||
) {
|
||||
const result = await this.apiRequest(credential, 'POST', '/v3/fund-app/mch-transfer/transfer-bills', {
|
||||
appid: credential.appId,
|
||||
out_bill_no: input.outBillNo,
|
||||
transfer_scene_id: input.sceneId,
|
||||
openid: input.openid,
|
||||
transfer_amount: input.amountCents,
|
||||
transfer_remark: input.remark.slice(0, 32),
|
||||
notify_url: input.notifyUrl,
|
||||
transfer_scene_report_infos: input.reportInfos.length > 0 ? input.reportInfos.map((item) => ({
|
||||
info_type: item.infoType.slice(0, 15),
|
||||
info_content: item.infoContent.slice(0, 32)
|
||||
})) : undefined
|
||||
});
|
||||
return {
|
||||
outBillNo: stringField(result, 'out_bill_no'),
|
||||
transferBillNo: optionalStringField(result, 'transfer_bill_no'),
|
||||
state: stringField(result, 'state'),
|
||||
failReason: optionalStringField(result, 'fail_reason'),
|
||||
packageInfo: optionalStringField(result, 'package_info')
|
||||
};
|
||||
}
|
||||
|
||||
verifyAndDecrypt(
|
||||
credential: WechatPayCredential,
|
||||
headers: WechatNotificationHeaders,
|
||||
@@ -279,7 +316,10 @@ export function parseWechatPayCredentials(value: string) {
|
||||
}
|
||||
return [reference, account];
|
||||
})
|
||||
) : {}
|
||||
) : {},
|
||||
transferSceneId: optionalStringField(item, 'transferSceneId'),
|
||||
transferSceneReportInfos: parseTransferReportInfos(item.transferSceneReportInfos),
|
||||
transferNotifyUrl: optionalStringField(item, 'transferNotifyUrl')
|
||||
});
|
||||
}
|
||||
return credentials;
|
||||
@@ -327,3 +367,17 @@ function optionalStringField(value: Record<string, unknown>, key: string) {
|
||||
const field = value[key];
|
||||
return typeof field === 'string' ? field : '';
|
||||
}
|
||||
|
||||
function parseTransferReportInfos(value: unknown) {
|
||||
if (!Array.isArray(value)) return undefined;
|
||||
return value.map((item) => {
|
||||
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
||||
throw new WechatPayError('WECHAT_TRANSFER_REPORT_INVALID');
|
||||
}
|
||||
const raw = item as Record<string, unknown>;
|
||||
return {
|
||||
infoType: stringField(raw, 'infoType'),
|
||||
infoContent: stringField(raw, 'infoContent')
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user