得到prepay_id后,小程序支付二次签名:
function getPayment(prepay_id){
let wxContext = cloud.getWXContext()
let appid = wxContext.APPID
let package = 'prepay_id=' + prepay_id
let timestamp = parseInt(Date.now() / 1000) + ''
let nonce_str = Math.random().toString(36).substr(2, 15)
return {
appId: appid,
nonceStr: nonce_str,
package,
signType: 'RSA',
timeStamp: timestamp,
paySign: getSign([appid, timestamp, nonce_str, package], key)
}
}
function getSign(parts = [], key, str = '') {
parts.forEach(v => str += v + '\n')
return crypto.createSign('RSA-SHA256').update(str).sign(key, 'base64')
}