const cloud = require('wx-server-sdk')
cloud.init({
env: "zs-redpackage-0gbq2222433377t1200b6fd
})
function randomString(e) {
e = e || 32;
var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",
a = t.length,
n = "";
for (i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
return n
}
const wxContext = cloud.getWXContext()
exports.main = (event, context) => {
const timeStamp = new Date().getTime()
const randomSix = randomString(6)
const outTradeNo = `${randomSix}${timeStamp}`
return new Promise((resolve, reject) => {
cloud.cloudPay.unifiedOrder({
"functionName": "pay_cb",
"envId": 'zs-redpackage-0gbq2222433377t1200b6fd',
"subMchId": "1606636452",
"nonceStr": randomString(),
"body": event.name,
"detail": event.name,
"outTradeNo": outTradeNo,
"totalFee": event.price * 100,
"spbillCreateIp": "221.181.214.198",
"tradeType": "JSAPI",
"openid": wxContext.OPENID,
"subOpenid": wxContext.OPENID,
}).then(res => {
if (res.returnCode === 'SUCCESS') {
resolve({
success: 1,
...res,
body: event.name,
detail: event.name,
totalFee: event.price,
timeStamp: timeStamp,
outTradeNo: outTradeNo
})
} else {
reject({
success: 0,
...res
})
}
}).catch(err => {
reject(err)
})
})
}
这不是有成功的吗?
有的成功,有的失败,说明这个失败的参数有问题,
等再次复现这样问题再说,还需要贴出统一下单的参数。