Commit 99f1466f by fengzhaoyu

MOD: 修改websocket连接问题

parent 14bfed81
......@@ -15,6 +15,6 @@ App({
globalData: {
loadingType: 0,
// globalUrl: 'http://192.168.1.101:9999'
globalUrl: 'https://gateway.mingwork.com'
globalUrl:'https://gateway.mingwork.com'
}
});
......@@ -24,44 +24,32 @@ Page({
});
},
// 点击刷新二维码
clickRefreshQRcode(){
clickRefreshQRcode() {
const _that = this;
clearInterval(timeRefreshQRcode);
_that.refreshQRcode();
timeRefreshQRcode = setInterval(function () {
timeRefreshQRcode = setInterval(function() {
_that.refreshQRcode();
}, 55000);
},
// 生成二维码
refreshQRcode(){
webSocket.closeSocket();
dd.getNetworkType({
success: (res) => {
// 有网络状态
if (res.networkAvailable) {
// 获取免登授权码
webSocket.connectSocket();
webSocket.onSocketMessageCallback = this.onSocketMessageCallback;
}
}
});
refreshQRcode() {
const _that = this;
dd.showLoading({
content: '加载中...'
});
dd.showLoading({
content: '加载中...'
});
let hasToken = dd.getStorageSync({ key: 'token' }).data;
let token = dd.getStorageSync({ key: 'token' }).data.access_token;
let expires_in = dd.getStorageSync({ key: 'token' }).data.expires_in;
let refresh_token = dd.getStorageSync({ key: 'token' }).data.refresh_token;
let mingUserId = dd.getStorageSync({ key: 'mingUserId' }).data
if(!!hasToken && (new Date().getTime() - hasToken.loginTime < (hasToken.expires_in - 300) * 1000)) {
if (!!hasToken && (new Date().getTime() - hasToken.loginTime < (hasToken.expires_in - 300) * 1000)) {
// if(!!hasToken && ((new Date()).getTime() - hasToken.loginTime < 30* 1000)) {
this.setData({
_that.setData({
isTimeOut: true
})
let timestamp = (new Date()).getTime();
let url = aes.getAES(JSON.stringify({
let url = aes.getAES(JSON.stringify({
"token": token,
"timestamp": timestamp
}))
......@@ -76,8 +64,7 @@ Page({
dd.getNetworkType({
success: (res => {
// 网络可用的情况下 刷新token
if(res.networkAvailable) {
if (res.networkAvailable) {
dd.httpRequest({
headers: {
'Authorization': 'Basic bWluZ3BheS1waG9uZTptaW5ncGF5LXBob25l',
......@@ -91,9 +78,6 @@ Page({
},
method: 'POST',
success: function(res) {
// dd.removeStorageSync({
// key:'token'
// })
dd.setStorageSync({
key: 'token',
data: {
......@@ -108,21 +92,20 @@ Page({
isTimeOut: true
})
let timestamp = (new Date()).getTime();
let url = aes.getAES(JSON.stringify({
let url = aes.getAES(JSON.stringify({
"token": res.data.access_token,
"timestamp": timestamp,
}))
}))
let size = 272
let ecc = 2
let name = 'myQrcode'
const ctx = dd.createCanvasContext(name);
QR.draw(url, ctx, size, Number(ecc));
},
fail: function(err) {
if(err.status == 426) {
if (err.status == 426) {
dd.hideLoading()
dd.removeStorageSync({key:'token'})
dd.removeStorageSync({ key: 'token' })
dd.redirectTo({
url: '/pages/reTry/reTry'
})
......@@ -161,45 +144,56 @@ Page({
},
onShow() {
console.log('进入onshow')
//刷新二维码
const _that = this;
setTimeout(function (){
clearInterval(timeRefreshQRcode);
_that.refreshQRcode();
timeRefreshQRcode = setInterval(function () {
setTimeout(function(res) {
dd.getNetworkType({
success: (res) => {
// 有网络状态
if (res.networkAvailable) {
// 获取免登授权码
webSocket.connectSocket();
webSocket.onSocketMessageCallback = _that.onSocketMessageCallback;
}
}
});
},1000)
//刷新二维码
setTimeout(function() {
clearInterval(timeRefreshQRcode);
_that.refreshQRcode();
}, 55000);
},500)
timeRefreshQRcode = setInterval(function() {
_that.refreshQRcode();
}, 55000);
}, 500)
},
// socket收到的信息回调
// socket收到的信息回调
onSocketMessageCallback: function(res) {
if (res === 'isHeart!!') {
console.log(res)
} else {
let resData = JSON.parse(res)
console.log(resData)
if(resData.paymentCode === 0){
if (resData.paymentCode === 0) {
// dd.closeSocket();
dd.navigateTo({
url: `./../paySuccess/paySuccess?money=${(resData.orderAmount.toFixed(2))}`
})
}else if(resData.paymentCode === 10001){
} else if (resData.paymentCode === 10001) {
dd.alert({
content: '账户状态异常',
buttonText: '确定'
});
}else if(resData.paymentCode === 10002){
} else if (resData.paymentCode === 10002) {
dd.alert({
content: '卡片状态异常',
buttonText: '确定'
});
}else if(resData.paymentCode === 10003){
} else if (resData.paymentCode === 10003) {
dd.alert({
content: '账户余额不足',
buttonText: '确定'
});
}else if(resData.paymentCode === 10004){
} else if (resData.paymentCode === 10004) {
dd.alert({
content: '二维码失效',
buttonText: '确定'
......@@ -235,23 +229,23 @@ Page({
isTimeOut: true
})
const _that = this;
setTimeout(function (){
setTimeout(function() {
clearInterval(timeRefreshQRcode);
_that.refreshQRcode();
timeRefreshQRcode = setInterval(function () {
_that.refreshQRcode();
}, 55000);
},500)
dd.getNetworkType({
success: (res) => {
// 有网络状态
if (res.networkAvailable) {
// 获取免登授权码
webSocket.connectSocket();
webSocket.onSocketMessageCallback = this.onSocketMessageCallback;
}
}
});
timeRefreshQRcode = setInterval(function() {
_that.refreshQRcode();
}, 55000);
}, 500)
// dd.getNetworkType({
// success: (res) => {
// // 有网络状态
// if (res.networkAvailable) {
// // 获取免登授权码
// webSocket.connectSocket();
// webSocket.onSocketMessageCallback = this.onSocketMessageCallback;
// }
// }
// });
dd.stopPullDownRefresh()
},
onReachBottom() {
......
......@@ -36,6 +36,7 @@ var webSocket = {
socketMsgQueue = []
dd.connectSocket({
url: `wss://mingpay-websocket.mingwork.com/v1/mingpaywebsocket?param=${dd.corpId}_${dd.getStorageSync({ key: 'userId' }).data}`,
// url: `ws://192.168.1.102:8400/v1/mingpaywebsocket?param=${dd.corpId}_${dd.getStorageSync({ key: 'userId' }).data}`,
data: {},
header:{
'content-type': 'application/json'
......
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