141 lines
2.7 KiB
JavaScript
141 lines
2.7 KiB
JavaScript
// pages/pay/index.js
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
id: '',
|
||
uid: '',
|
||
isback: '',
|
||
code: ''
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
this.data.id = options.id
|
||
this.data.uid = options.uid
|
||
this.data.isback = options.isback
|
||
let _this = this
|
||
wx.showLoading({
|
||
title: '支付中,请稍等!',
|
||
})
|
||
if (this.data.id && this.data.uid) {
|
||
wx.login({
|
||
success(res) {
|
||
_this.data.code = res.code
|
||
if (_this.data.code) {
|
||
_this.payClick()
|
||
}
|
||
}
|
||
})
|
||
}
|
||
|
||
|
||
},
|
||
|
||
|
||
|
||
|
||
|
||
payClick: function payClick() {
|
||
const info = wx.getSystemInfoSync();
|
||
if (info.platform === 'ios') {
|
||
wx.showToast({
|
||
title: '由于相关规定,ios暂时不支持支付',
|
||
})
|
||
return;
|
||
// android 需要执行的代码
|
||
}
|
||
var that = this;
|
||
wx.request({
|
||
url: 'https://tiktokh5code1.csguyanwl.cn/getTiktokpay',
|
||
data: {
|
||
uid: that.data.uid,
|
||
id: that.data.id,
|
||
isback: that.data.isback,
|
||
code: that.data.code
|
||
},
|
||
success: function success(res) {
|
||
// console.log(res);
|
||
that.pay(res.data.data)
|
||
|
||
}
|
||
});
|
||
},
|
||
pay(data) {
|
||
console.log(data);
|
||
let that = this
|
||
wx.hideLoading()
|
||
wx.requestPayment({
|
||
provider: 'wxpay',
|
||
timeStamp: data.timeStamp,
|
||
nonceStr: data.nonceStr,
|
||
package: data.package,
|
||
signType: data.signType,
|
||
paySign: data.paySign,
|
||
|
||
success: function (res) {
|
||
if (res.errMsg == 'requestPayment:ok') {
|
||
|
||
}
|
||
|
||
|
||
},
|
||
fail: function (err) {
|
||
that.pay(data)
|
||
}
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage() {
|
||
|
||
}
|
||
}) |