小程序微信支付偶现报错user code exception caught,代码如下,求大佬帮看看?
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)
})
})
}