|
@@ -133,17 +133,59 @@ Page({
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
-
|
|
|
+
|
|
|
/** 支付按钮点击事件 */
|
|
|
toPay() {
|
|
|
+ var that = this;
|
|
|
api.request_wechatPay(this.data.order.orderId).then(res => {
|
|
|
console.log("支付结果", res)
|
|
|
- this.pay()
|
|
|
+ this.subMessage()
|
|
|
+ // this.pay()
|
|
|
}).catch(err => {
|
|
|
console.log("支付失败", err)
|
|
|
})
|
|
|
+ },
|
|
|
+ /** 订阅消息模板 */
|
|
|
+ subMessage() {
|
|
|
+ const that = this;
|
|
|
+ wx.requestSubscribeMessage({
|
|
|
+ tmplIds: ['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'], // 最多支持3条
|
|
|
+ success(res) {
|
|
|
+ that.pay()
|
|
|
+ // 'accept'表示用户同意订阅该条id对应的模板消息
|
|
|
+ if (res['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'] === 'accept') {
|
|
|
+ // 用户同意订阅,调用云函数或服务器接口发送订阅消息
|
|
|
+ // wx.cloud.callFunction({
|
|
|
+ // name: 'sendSubscribeMessage',
|
|
|
+ // data: {
|
|
|
+ // templateId: '配置好的模板ID',
|
|
|
+ // openid: 'o8pFb5cWH1KkBDvGls2X7yMiFkGA',
|
|
|
+ // data: {
|
|
|
+ // thing1: {
|
|
|
+ // value: '活动名称'
|
|
|
+ // },
|
|
|
+ // // 其他参数...
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // success(res) {
|
|
|
+ // console.log('订阅消息发送成功', res)
|
|
|
+ // },
|
|
|
+ // fail(err) {
|
|
|
+ // console.error('订阅消息发送失败', err)
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ that.pay()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
},
|
|
|
pay() {
|
|
|
+ const that = this;
|
|
|
api.request_wechatPay(this.data.order.orderId)
|
|
|
.then(res => {
|
|
|
wx.requestPayment({
|
|
@@ -154,14 +196,9 @@ Page({
|
|
|
paySign: res.data.data.unifiedOrderResult.paySign,
|
|
|
success: res => {
|
|
|
wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '支付成功!',
|
|
|
- })
|
|
|
- setTimeout(function () {
|
|
|
- wx.redirectTo({
|
|
|
- url: '../scan/scan',
|
|
|
- })
|
|
|
- }, 2000)
|
|
|
+ that.sendMessage()
|
|
|
+ that.toPayResult()
|
|
|
+
|
|
|
},
|
|
|
fail: res => {
|
|
|
wx.hideLoading()
|
|
@@ -177,4 +214,35 @@ Page({
|
|
|
})
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
+ /** 发送消息模板 */
|
|
|
+ sendMessage() {
|
|
|
+ const message = {
|
|
|
+ trxid:this.data.order.orderId,
|
|
|
+ orderType:'支付成功'
|
|
|
+ }
|
|
|
+ api.request_sendMessage(message).then(res => {
|
|
|
+ console.log("发送消息模板结果",res)
|
|
|
+ }).catch(err => {
|
|
|
+ console.log("发送消息模板失败",err)
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 跳转到支付结果页 */
|
|
|
+ toPayResult(){
|
|
|
+ const that = this;
|
|
|
+ setTimeout(function () {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '../payResult/payResult?nozzle=' + that.data.nozzleId,
|
|
|
+ events: {
|
|
|
+ acceptOrderFromPayResult: function (data) {
|
|
|
+ console.log("获取到来自result页面传送过来的订单", data)
|
|
|
+ that.setData({
|
|
|
+ order: data
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, 500)
|
|
|
+ }
|
|
|
})
|