1、函数paypay
const cloud = require('wx-server-sdk')
cloud.init({
env: 'xxxxxxxx'
})
exports.main = async (event, context) => {
const res = await cloud.cloudPay.unifiedOrder({
"body" : "小秋TIT店-超市22",
"outTradeNo" :event.outTradeNo,
"spbillCreateIp" : "127.0.0.1",
"subMchId" : "xxxxxxx",
"totalFee" :event.totalFee,
"envId": "xxxxxxxxx",
"functionName": "pay",
"nonceStr": event.nonceStr
})
return res
}
2、index.js
Page({
onchick:function(){
var code=dkjfdkfjkdj
var codestr=kdjfkdjfkjdflkjdfkjdfkj
wx.cloud.callFunction({
name: 'paypay',
data: {
totalFee:5,
outTradeNo:code,
nonceStr: codestr
},
success: res => {
const payment = res.result.payment
wx.requestPayment({
...payment
,
success (res) {
console.log('pay success', res)
},
fail (res) {
console.error('pay fail_1', err)
}
})
},
fail:console.log('pay fail_2'),
})
}
})
3、index.wxml
<button class="mf" ' bindtap='onchick'>支付</button>
------------------------------------------------------------------------------------------
云函数调用支付成功,但怎样让支付浮窗倒计时呀?长时间不支付时,需要让浮窗消失,退出支付。
那怎样限定,点到支付浮窗,用户长时间不支付呢,有其他算法吗?