怎么在小程序支付完成后,传递数据给url后台?
支付可以正常运行,但是无法传递数据url到后台
button: function(e) {
let orderId = Date.now();
wx.cloud.callFunction({
name: "getOpenid"
data: {
orderid: orderId,
totalPrice: 0.1
},
success(res) {
console.log("提交成功101", res.result)
that.getOpenid(res.result)
},
fail(res) {
console.log("提交失败101", res)
},
complete: function () {
var uphone = wx.getStorageSync('uphone');
wx.request({
url: app.globalData.baseUrl + '/buyer/order/create'
method: "POST"
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
data: {
openid: app.globalData.openid,
name: app.globalData.userInfo.nickName
phone: uphone,
},
success: function (res) {
console.log("支付成功10001:", res.data)
if (res && res.data && res.data.data) {
// 支付方式关闭动画
that.animation.translate(, 285).step();
that.setData({
animationData: that.animation.export()
});
that.setData({
maskFlag: true
});
wx.setStorageSync('cart', ""
wx.switchTab({
url: '../index/index'
})
} else {
// 支付方式关闭动画
that.animation.translate(, 285).step();
that.setData({
animationData: that.animation.export()
});
that.setData({
maskFlag: true
});
}
}
})
}
})
},
getOpenid(payData) {
//console.log("入口支付成功11", res)
wx.requestPayment({
timeStamp: payData.timeStamp,
nonceStr: payData.nonceStr,
package: payData.package,
signType: 'MD5',
paySign: payData.paySign,
success(res) {
console.log("入口支付成功11", res.data)
},
fail(res) {
console.log("入口支付失败11", res)
}
})
}
求大佬
8 回复
报错很明显了:that.animation.translate中的that.animation是undefined。 我猜你这里应该是that.data.animation或者直接animation,看你这个animation变量是怎么定义的了
把wx.request({})放到 wx.cloud.callFunction({})外面,就不会报错;
但是是在支付完成前就已经传递参数到后台url了
button: function) {
let orderId = Date.now();
wx.cloud.callFunction({
name: "getOpenid"
data: {
orderid: orderId,
totalPrice: 0.1
},
success(res) {
console.log("提交成功101", res.result)
that.getOpenid(res.result)
},
fail(res) {
console.log("提交失败101", res)
},
})
var uphone = wx.getStorageSync('uphone');
wx.request({
url: app.globalData.baseUrl + '/buyer/order/create'
method: "POST"
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
data: {
openid: app.globalData.openid,
name: app.globalData.userInfo.nickName
phone: uphone,
},
success: function (res) {
console.log("支付成功10001:", res.data)
if (res && res.data && res.data.data) {
// 支付方式关闭动画
that.animation.translate(, 285).step();
that.setData({
animationData: that.animation.export()
});
that.setData({
maskFlag: true
});
wx.setStorageSync('cart', ""
wx.switchTab({
url: '../index/index'
})
} else {
// 支付方式关闭动画
that.animation.translate(, 285).step();
that.setData({
animationData: that.animation.export()
});
that.setData({
maskFlag: true
});
}
}
})
},
getOpenid(payData) {
//console.log("入口支付成功11", res)
wx.requestPayment({
timeStamp: payData.timeStamp,
nonceStr: payData.nonceStr,
package: payData.package,
signType: 'MD5',
paySign: payData.paySign,
success(res) {
console.log("入口支付成功11", res.data)
},
fail(res) {
console.log("入口支付失败11", res)
}
})
}