标签:oba fun == 分享图片 ade storage sync 获取 stp
//index.js
//获取应用实例
var app = getApp()
Page({
data: {
paydata: { title: "支付测试", total_fee:1},
userInfo: {}
},
onLoad: function () {
console.log(‘onLoad‘);
//判断是否获取到了详细信息
if (!wx.getStorageSync("userInfo")) {
wx.navigateTo({ url: ‘/pages/login/index‘})
}
},
// 监听输入
bindKeyInput: function (e) {
console.log(e.detail.value);
this.setData({
‘paydata.total_fee‘: e.detail.value
})
},
//
payoff: function(e){
var that = this;
//获取openid
app.wxlogin(function (re) {
console.log(re);
//判断有无openid
if (re) {
that.setData({ ‘paydata.openid‘:re })
//下单
that.xiadan();
}
});
},
//下单
xiadan: function (){
var that = this;
wx.request({
url: app.globalData.apiurl+‘c=payorder‘,
method: ‘POST‘,
header: { ‘content-type‘: ‘application/x-www-form-urlencoded‘ },
data: that.data.paydata,
success: function(res) {
console.log(res);
if(res.data.code=="0"){
//发起支付
that.requestPayment(res.data.data);
}else{
wx.showModal({
title: ‘提示‘,
content: ‘支付发起失败‘,
showCancel:false
});
}
}
})
},
//申请支付
requestPayment: function(obj){
console.log(obj);
var that=this;
wx.requestPayment({
‘timeStamp‘: obj.timeStamp,
‘nonceStr‘: obj.nonceStr,
‘package‘: obj.package,
‘signType‘: obj.signType,
‘paySign‘: obj.paySign,
‘success‘:function(res){
wx.showModal({
title: ‘提示‘,
content: ‘成功支付:‘ + that.data.paydata.total_fee+‘分‘,
showCancel: false
});
},
‘fail‘:function(res){
wx.showModal({
title: ‘提示‘,
content: ‘支付失败‘,
showCancel: false
});
}
})
},
})
=============================================
互相学习电话微信:18611436777(加微信注明事由)
标签:oba fun == 分享图片 ade storage sync 获取 stp
原文地址:https://www.cnblogs.com/lytocnc/p/9855593.html