本时支付宝小程序

This commit is contained in:
唐明明
2020-09-24 11:08:03 +08:00
parent 11e0df1cc8
commit 6a67082c25
510 changed files with 20316 additions and 2 deletions

101
pages/payCode/payCode.js Executable file
View File

@@ -0,0 +1,101 @@
const api = require("../../api/api")
const app = getApp()
Page({
data: {
codeBase : "",
atOrderId: "",
phase : "0.00",
total : "0.00",
every : "0.00",
type : ""
},
onLoad(e) {
my.showLoading();
if(e.orderid){
this.setData({
atOrderId: e.orderid,
type : e.paytype || ""
})
}
let url = "pay/order"
if(e.paytype == "gasPay"){
url = "gas/pay"
}else if(e.paytype == "installment"){
url = "installment/pay"
}else if(e.paytype == "icePay"){
url = "preferential/payment"
}
api.request({
url : url,
header : {
"Authorization": app.globalData.token
},
method : 'POST',
data : {
orderid : e.orderid
}
}).then(res=>{
let every = res.data.total / res.data.phase
this.setData({
codeBase: "data:image/png;base64," + res.data.qr_base,
phase : res.data.phase,
total : res.data.total,
every : every.toFixed(2)
})
// 打开Socket
this.openSocket()
my.hideLoading();
}).catch(err=>{
my.showToast({
content: err.data.message
})
my.hideLoading
})
},
// Socket
openSocket(){
my.connectSocket({
url : 'wss://www.ysd-bs.com/wss'
})
my.onSocketOpen(res=> {
console.log("建立链接")
});
my.onSocketError(res=>{
my.showToast({
content: "连接服务器失败"
});
});
my.onSocketMessage(res=> {
let dataType = JSON.parse(res.data)
if(dataType.type == 'connect'){
let dataInfo = JSON.stringify({'type':'BIND','data':{'user_id': app.globalData.userInfo.user_id}})
my.sendSocketMessage({
data : dataInfo
});
}else if(dataType.type == 'paysuccess'){
if(dataType.order_id == this.data.atOrderId){
my.redirectTo({
url: "../results/results"
})
}
}
})
},
// 离开页面
onUnload(){
my.closeSocket()
}
});