const cloud = require('wx-server-sdk')
const fs=require('fs')
const {Wechatpay, Formatter} = require('wechatpay-axios-plugin')
const cert = fs.readFileSync('./apiclient_cert.pem', 'ascii')
const prikey = fs.readFileSync('./apiclient_key.pem', 'ascii')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
const wxpay = new Wechatpay({
mchid: '16********72',// 商户号
// 商户证书序列号
serial: '41217B61*****************C2D771C',
// 商户API私钥 PEM格式的文本字符串或者文件buffer
privateKey: prikey,
certs: {
//平台证书序列号
'38******************A74': cert,
},
secret: 'fa*****************************36a',
merchant: {
cert: cert,
key: prikey,
},
})
return wxpay.v3.transfer.batches.post({
appid: 'w**********44',
out_batch_no:"3f19*********************ea22",
batch_name:"test",
batch_remark:'测试一下',
total_amount:10,
total_num:1,
transfer_detail_list:[
{
out_detail_no:'kakatf001',
transfer_amount:3,
transfer_remark:'测试3分',
openid:wxContext.OPENID,
user_name:'名字'
}
]
}).then(res=>{
console.log(res.data)
return res
})
.catch(({response: {status, statusText, data}}) => console.error(status, statusText, data))
}
执行后报错
"{\"code\":\"PARAM_ERROR\",\"message\":\"HTTP header缺少微信支付平台证书序列号(Wechatpay-Serial)\"}"