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,27 +24,16 @@ 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: '加载中...'
......@@ -54,10 +43,9 @@ Page({
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();
......@@ -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: {
......@@ -117,12 +101,11 @@ Page({
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,16 +144,27 @@ Page({
},
onShow() {
console.log('进入onshow')
//刷新二维码
const _that = this;
setTimeout(function (){
setTimeout(function(res) {
dd.getNetworkType({
success: (res) => {
// 有网络状态
if (res.networkAvailable) {
// 获取免登授权码
webSocket.connectSocket();
webSocket.onSocketMessageCallback = _that.onSocketMessageCallback;
}
}
});
},1000)
//刷新二维码
setTimeout(function() {
clearInterval(timeRefreshQRcode);
_that.refreshQRcode();
timeRefreshQRcode = setInterval(function () {
timeRefreshQRcode = setInterval(function() {
_that.refreshQRcode();
}, 55000);
},500)
}, 500)
},
// socket收到的信息回调
onSocketMessageCallback: function(res) {
......@@ -179,27 +173,27 @@ Page({
} 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 () {
timeRefreshQRcode = setInterval(function() {
_that.refreshQRcode();
}, 55000);
},500)
dd.getNetworkType({
success: (res) => {
// 有网络状态
if (res.networkAvailable) {
// 获取免登授权码
webSocket.connectSocket();
webSocket.onSocketMessageCallback = this.onSocketMessageCallback;
}
}
});
}, 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