评论

V3统一下单二次签名nodejs云函数简单代码

V3统一下单二次签名

得到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')
}

最后一次编辑于  2021-12-17  
点赞 1
收藏
评论
登录 后发表内容