微信小程序调取支付


 

微信小程序调取支付功能,废话不多说,上代码

 

wxml:

 

1 <button bindtap="pay">立即支付</button>

  

js:

 1 pay () {
 2     const _this = this
 3     const sell_item_id = _this.data.id
 4     wx.request({
 5       url: _this.data.server + '/pay',  // 请求后端给的支付接口,返回生成订单信息
 6       method: 'post',
 7       data: { sell_item_id },
 8       header: { authorization: wx.getStorageSync('token') },
 9       success: function (res) {
10         const jsapi_config = res.data.data.jsapi_config
11         wx.requestPayment({  // 调取微信支付api,完成订单支付
12           timeStamp: jsapi_config.timeStamp,
13           nonceStr: jsapi_config.nonceStr,
14           package: jsapi_config.package,
15           signType: jsapi_config.signType,
16           paySign: jsapi_config.paySign,
17           success: function (res) {
18             wx.showToast({
19               title: '支付成功',
20               duration: 3000
21             })
22           },
23           fail: function (err) {
24             wx.showToast({
25               title: '支付失败',
26               duration: 3000
27             })
28           }
29         })
30       }
31     })
32   }

 

微信小程序支付文档:https://developers.weixin.qq.com/miniprogram/dev/api/open-api/payment/wx.requestPayment.html

posted @ 2021-02-19 10:25  地yu荒冢  阅读(166)  评论(0编辑  收藏  举报