微信小程序实现微信支付功能

时间:2023-02-22 09:59:53

详解:

wx.requestPayment(OBJECT)

发起微信支付。

Object参数说明:

参数 类型 必填 说明
timeStamp String 时间戳从1970年1月1日00:00:00至今的秒数,即当前的时间
nonceStr String 随机字符串,长度为32个字符以下。
package String 统一下单接口返回的 prepay_id 参数值,提交格式如:prepay_id=*
signType String 签名算法,暂支持 MD5
paySign String 签名,具体签名方案参见小程序支付接口文档;
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

了解更多信息,请查看微信支付接口文档

回调结果:

回调类型 errMsg 说明
success requestPayment:ok 调用支付成功
fail requestPayment:fail cancel 用户取消支付
fail requestPayment:fail (detail message) 调用支付失败,其中 detail message 为后台返回的详细失败原因

demo

    wx.requestPayment({
      'timeStamp': pbj.timeStamp,
      'nonceStr': pbj.nonceStr.toString(),
      'package': pbj.package,
      'signType': 'MD5',
      'paySign': pbj.paySign,
      'success': function (res) {
        console.log("吊起支付:" + res)

      },
      'fail': function (res) {
        console.log("失败" + JSON.stringify(pbj.nonceStr))
      },
      'complete': function (res) { console.log("res" + JSON.stringify(res)) },

    })