Commit 8ee29e44 authored by 不吃草的咩's avatar 不吃草的咩

微信支付

parent e44af9bb
...@@ -36,6 +36,12 @@ Page({ ...@@ -36,6 +36,12 @@ Page({
//如果返回成功手机号,就随机生成一串字符串存进去 //如果返回成功手机号,就随机生成一串字符串存进去
if(e.detail.code !== undefined){ if(e.detail.code !== undefined){
console.log(e.detail); console.log(e.detail);
wx.login({
timeout: 30000,
success:function(res){
console.log(res);
}
})
app.colorUISdk.request({ app.colorUISdk.request({
url:`wx/gt?code=${e.detail.code}`, url:`wx/gt?code=${e.detail.code}`,
method: 'POST' method: 'POST'
......
...@@ -124,6 +124,74 @@ Page({ ...@@ -124,6 +124,74 @@ Page({
} }
}); });
}, },
sendMeans(){
const toast = Toast.loading({
message: '订单生成中,请稍候。。。',
forbidClick: true,
loadingType: 'spinner',
});
app.colorUISdk.request({
url:`wx/gt?code=${e.detail.code}`, //上传课程价格接口
method: 'POST',
data:{
price:price,
courseName:''
}
}).then(({data})=> {
//创建订单成功,返回给我一些必要参数,然后调起微信支付
Toast.clear();
//唤起微信支付
let time = (new Date().getTime().toString()).substring(0,10)
wx.requestPayment({
appId:'wx95ac219beca2f34f',
timeStamp:time,
nonceStr:this.randomWord(true,parseInt((Math.random() * 20)),parseInt((Math.random() * 30))), //生成长度为20~30的随机字符串
package:'prepay_id=wx201410272009395522657a690389285100', //等待回传结果
signType:"RSA",
paySign:'', //后台加密计算好给我
fail:function(){
Toast.fail('您已取消支付')
},
})
if(data.errcode == 0){
let random = this.randomWord(false, 43);
// let random = Math.random().toString(36).substr(2);
try {
wx.setStorageSync('token', random+data.phone_info.phoneNumber);
app.phone = data.phone_info.phoneNumber;
Toast.success('登录成功');
this.setData({
show:false,
title:data.phone_info.phoneNumber,
})
} catch (e) {
wx.showToast({
title: '数据存储失败!',
icon: 'none'
})
}
}
this.setData({courseData: res.data.records})
}).catch(err=>{
console.log(err)
})
},
randomWord(randomFlag, min, max){
let str = "",
range = min,
arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
// 随机产生
if(randomFlag){
range = Math.round(Math.random() * (max-min)) + min;
}
for(var i=0; i<range; i++){
let pos = Math.round(Math.random() * (arr.length-1));
str += arr[pos];
}
return str;
},
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
</view> </view>
</view> </view>
<view class="subbtn"> <view class="subbtn">
<van-button type="primary" block color="#1989fa">提交资料</van-button> <van-button type="primary" block color="#1989fa" bindtap="sendMeans">提交资料</van-button>
</view> </view>
</view> </view>
<van-toast id="van-toast" /> <van-toast id="van-toast" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment