在云函数中(共享的云环境)使用tenpay库 调用企业付款接口进行提现,商户32位密钥已经指定,同时
pfx: require('fs').readFileSync('apiclient_cert.p12'), //证书初始化
const config = {
appid: 'xxx', //小程序Appid
envName: 'xxx', // 小程序云开发环境ID
mchid: 'xxx', //商户号
partnerKey: 'xxx', //此处填服务商密钥
pfx: require('fs').readFileSync('apiclient_cert.p12'), //证书初始化
actionName:'xxx',
rate:0
};
let result = await pay.transfers({
partner_trade_no: 'scorereflect' + Date.now() + num,
openid: userInfo._openid,
check_name: 'NO_CHECK',
amount: parseInt(num) * (100 - config.rate),
desc: config.actionName,
});
每次结果都报错:
报错:Error: cloud.callFunction:fail Error: errCode: -504002 functions execute fail | errMsg: Error: mac verify failure, POST https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers -1 (connected: false, keepalive socket: false, socketHandledRequests: 0, socketHandledResponses: 0)
headers: {}
at configSecureContext (node:internal/tls/secure-context:276:15)
at Object.createSecureContext (node:_tls_common:116:3)
at Object.connect (node:_tls_wrap:1621:48)
at Agent.createConnection (node:https:143:22)
at Agent.createSocket (node:_http_agent:341:26)
at Agent.addRequest (node:_http_agent:292:10)
at new ClientRequest (node:_http_client:305:16)
at Object.request (node:https:353:10)
at Object.requestWithCallback (/var/user/node_modules/urllib/lib/urllib.js:1051:19)
1.检查参数签名:
2.验证APPID和MCHID:
3.检查请求方法:
4.查看云函数日志: