Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mingPayMobile
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fengzhaoyu
mingPayMobile
Commits
99f1466f
Commit
99f1466f
authored
Oct 28, 2019
by
fengzhaoyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MOD: 修改websocket连接问题
parent
14bfed81
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
61 deletions
+56
-61
app.js
app.js
+1
-1
payment.js
pages/payment/payment.js
+54
-60
socket.js
utils/socket.js
+1
-0
No files found.
app.js
View file @
99f1466f
...
@@ -15,6 +15,6 @@ App({
...
@@ -15,6 +15,6 @@ App({
globalData
:
{
globalData
:
{
loadingType
:
0
,
loadingType
:
0
,
// globalUrl: 'http://192.168.1.101:9999'
// globalUrl: 'http://192.168.1.101:9999'
globalUrl
:
'https://gateway.mingwork.com'
globalUrl
:
'https://gateway.mingwork.com'
}
}
});
});
pages/payment/payment.js
View file @
99f1466f
...
@@ -24,44 +24,32 @@ Page({
...
@@ -24,44 +24,32 @@ Page({
});
});
},
},
// 点击刷新二维码
// 点击刷新二维码
clickRefreshQRcode
(){
clickRefreshQRcode
()
{
const
_that
=
this
;
const
_that
=
this
;
clearInterval
(
timeRefreshQRcode
);
clearInterval
(
timeRefreshQRcode
);
_that
.
refreshQRcode
();
_that
.
refreshQRcode
();
timeRefreshQRcode
=
setInterval
(
function
()
{
timeRefreshQRcode
=
setInterval
(
function
()
{
_that
.
refreshQRcode
();
_that
.
refreshQRcode
();
},
55000
);
},
55000
);
},
},
// 生成二维码
// 生成二维码
refreshQRcode
(){
refreshQRcode
()
{
webSocket
.
closeSocket
();
dd
.
getNetworkType
({
success
:
(
res
)
=>
{
// 有网络状态
if
(
res
.
networkAvailable
)
{
// 获取免登授权码
webSocket
.
connectSocket
();
webSocket
.
onSocketMessageCallback
=
this
.
onSocketMessageCallback
;
}
}
});
const
_that
=
this
;
const
_that
=
this
;
dd
.
showLoading
({
dd
.
showLoading
({
content
:
'加载中...'
content
:
'加载中...'
});
});
let
hasToken
=
dd
.
getStorageSync
({
key
:
'token'
}).
data
;
let
hasToken
=
dd
.
getStorageSync
({
key
:
'token'
}).
data
;
let
token
=
dd
.
getStorageSync
({
key
:
'token'
}).
data
.
access_token
;
let
token
=
dd
.
getStorageSync
({
key
:
'token'
}).
data
.
access_token
;
let
expires_in
=
dd
.
getStorageSync
({
key
:
'token'
}).
data
.
expires_in
;
let
expires_in
=
dd
.
getStorageSync
({
key
:
'token'
}).
data
.
expires_in
;
let
refresh_token
=
dd
.
getStorageSync
({
key
:
'token'
}).
data
.
refresh_token
;
let
refresh_token
=
dd
.
getStorageSync
({
key
:
'token'
}).
data
.
refresh_token
;
let
mingUserId
=
dd
.
getStorageSync
({
key
:
'mingUserId'
}).
data
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)) {
// if(!!hasToken && ((new Date()).getTime() - hasToken.loginTime < 30* 1000)) {
this
.
setData
({
_that
.
setData
({
isTimeOut
:
true
isTimeOut
:
true
})
})
let
timestamp
=
(
new
Date
()).
getTime
();
let
timestamp
=
(
new
Date
()).
getTime
();
let
url
=
aes
.
getAES
(
JSON
.
stringify
({
let
url
=
aes
.
getAES
(
JSON
.
stringify
({
"token"
:
token
,
"token"
:
token
,
"timestamp"
:
timestamp
"timestamp"
:
timestamp
}))
}))
...
@@ -76,8 +64,7 @@ Page({
...
@@ -76,8 +64,7 @@ Page({
dd
.
getNetworkType
({
dd
.
getNetworkType
({
success
:
(
res
=>
{
success
:
(
res
=>
{
// 网络可用的情况下 刷新token
// 网络可用的情况下 刷新token
if
(
res
.
networkAvailable
)
{
if
(
res
.
networkAvailable
)
{
dd
.
httpRequest
({
dd
.
httpRequest
({
headers
:
{
headers
:
{
'Authorization'
:
'Basic bWluZ3BheS1waG9uZTptaW5ncGF5LXBob25l'
,
'Authorization'
:
'Basic bWluZ3BheS1waG9uZTptaW5ncGF5LXBob25l'
,
...
@@ -91,9 +78,6 @@ Page({
...
@@ -91,9 +78,6 @@ Page({
},
},
method
:
'POST'
,
method
:
'POST'
,
success
:
function
(
res
)
{
success
:
function
(
res
)
{
// dd.removeStorageSync({
// key:'token'
// })
dd
.
setStorageSync
({
dd
.
setStorageSync
({
key
:
'token'
,
key
:
'token'
,
data
:
{
data
:
{
...
@@ -108,21 +92,20 @@ Page({
...
@@ -108,21 +92,20 @@ Page({
isTimeOut
:
true
isTimeOut
:
true
})
})
let
timestamp
=
(
new
Date
()).
getTime
();
let
timestamp
=
(
new
Date
()).
getTime
();
let
url
=
aes
.
getAES
(
JSON
.
stringify
({
let
url
=
aes
.
getAES
(
JSON
.
stringify
({
"token"
:
res
.
data
.
access_token
,
"token"
:
res
.
data
.
access_token
,
"timestamp"
:
timestamp
,
"timestamp"
:
timestamp
,
}))
}))
let
size
=
272
let
size
=
272
let
ecc
=
2
let
ecc
=
2
let
name
=
'myQrcode'
let
name
=
'myQrcode'
const
ctx
=
dd
.
createCanvasContext
(
name
);
const
ctx
=
dd
.
createCanvasContext
(
name
);
QR
.
draw
(
url
,
ctx
,
size
,
Number
(
ecc
));
QR
.
draw
(
url
,
ctx
,
size
,
Number
(
ecc
));
},
},
fail
:
function
(
err
)
{
fail
:
function
(
err
)
{
if
(
err
.
status
==
426
)
{
if
(
err
.
status
==
426
)
{
dd
.
hideLoading
()
dd
.
hideLoading
()
dd
.
removeStorageSync
({
key
:
'token'
})
dd
.
removeStorageSync
({
key
:
'token'
})
dd
.
redirectTo
({
dd
.
redirectTo
({
url
:
'/pages/reTry/reTry'
url
:
'/pages/reTry/reTry'
})
})
...
@@ -161,45 +144,56 @@ Page({
...
@@ -161,45 +144,56 @@ Page({
},
},
onShow
()
{
onShow
()
{
console
.
log
(
'进入onshow'
)
console
.
log
(
'进入onshow'
)
//刷新二维码
const
_that
=
this
;
const
_that
=
this
;
setTimeout
(
function
(){
setTimeout
(
function
(
res
)
{
clearInterval
(
timeRefreshQRcode
);
dd
.
getNetworkType
({
_that
.
refreshQRcode
();
success
:
(
res
)
=>
{
timeRefreshQRcode
=
setInterval
(
function
()
{
// 有网络状态
if
(
res
.
networkAvailable
)
{
// 获取免登授权码
webSocket
.
connectSocket
();
webSocket
.
onSocketMessageCallback
=
_that
.
onSocketMessageCallback
;
}
}
});
},
1000
)
//刷新二维码
setTimeout
(
function
()
{
clearInterval
(
timeRefreshQRcode
);
_that
.
refreshQRcode
();
_that
.
refreshQRcode
();
},
55000
);
timeRefreshQRcode
=
setInterval
(
function
()
{
},
500
)
_that
.
refreshQRcode
();
},
55000
);
},
500
)
},
},
// socket收到的信息回调
// socket收到的信息回调
onSocketMessageCallback
:
function
(
res
)
{
onSocketMessageCallback
:
function
(
res
)
{
if
(
res
===
'isHeart!!'
)
{
if
(
res
===
'isHeart!!'
)
{
console
.
log
(
res
)
console
.
log
(
res
)
}
else
{
}
else
{
let
resData
=
JSON
.
parse
(
res
)
let
resData
=
JSON
.
parse
(
res
)
console
.
log
(
resData
)
console
.
log
(
resData
)
if
(
resData
.
paymentCode
===
0
)
{
if
(
resData
.
paymentCode
===
0
)
{
// dd.closeSocket();
// dd.closeSocket();
dd
.
navigateTo
({
dd
.
navigateTo
({
url
:
`./../paySuccess/paySuccess?money=
${(
resData
.
orderAmount
.
toFixed
(
2
))}
`
url
:
`./../paySuccess/paySuccess?money=
${(
resData
.
orderAmount
.
toFixed
(
2
))}
`
})
})
}
else
if
(
resData
.
paymentCode
===
10001
)
{
}
else
if
(
resData
.
paymentCode
===
10001
)
{
dd
.
alert
({
dd
.
alert
({
content
:
'账户状态异常'
,
content
:
'账户状态异常'
,
buttonText
:
'确定'
buttonText
:
'确定'
});
});
}
else
if
(
resData
.
paymentCode
===
10002
)
{
}
else
if
(
resData
.
paymentCode
===
10002
)
{
dd
.
alert
({
dd
.
alert
({
content
:
'卡片状态异常'
,
content
:
'卡片状态异常'
,
buttonText
:
'确定'
buttonText
:
'确定'
});
});
}
else
if
(
resData
.
paymentCode
===
10003
)
{
}
else
if
(
resData
.
paymentCode
===
10003
)
{
dd
.
alert
({
dd
.
alert
({
content
:
'账户余额不足'
,
content
:
'账户余额不足'
,
buttonText
:
'确定'
buttonText
:
'确定'
});
});
}
else
if
(
resData
.
paymentCode
===
10004
)
{
}
else
if
(
resData
.
paymentCode
===
10004
)
{
dd
.
alert
({
dd
.
alert
({
content
:
'二维码失效'
,
content
:
'二维码失效'
,
buttonText
:
'确定'
buttonText
:
'确定'
...
@@ -235,23 +229,23 @@ Page({
...
@@ -235,23 +229,23 @@ Page({
isTimeOut
:
true
isTimeOut
:
true
})
})
const
_that
=
this
;
const
_that
=
this
;
setTimeout
(
function
()
{
setTimeout
(
function
()
{
clearInterval
(
timeRefreshQRcode
);
clearInterval
(
timeRefreshQRcode
);
_that
.
refreshQRcode
();
timeRefreshQRcode
=
setInterval
(
function
()
{
_that
.
refreshQRcode
();
_that
.
refreshQRcode
();
},
55000
);
timeRefreshQRcode
=
setInterval
(
function
()
{
},
500
)
_that
.
refreshQRcode
();
dd
.
getNetworkType
({
},
55000
);
success
:
(
res
)
=>
{
},
500
)
// 有网络状态
// dd.getNetworkType({
if
(
res
.
networkAvailable
)
{
// success: (res) => {
// 获取免登授权码
// // 有网络状态
webSocket
.
connectSocket
();
// if (res.networkAvailable) {
webSocket
.
onSocketMessageCallback
=
this
.
onSocketMessageCallback
;
// // 获取免登授权码
}
// webSocket.connectSocket();
}
// webSocket.onSocketMessageCallback = this.onSocketMessageCallback;
});
// }
// }
// });
dd
.
stopPullDownRefresh
()
dd
.
stopPullDownRefresh
()
},
},
onReachBottom
()
{
onReachBottom
()
{
...
...
utils/socket.js
View file @
99f1466f
...
@@ -36,6 +36,7 @@ var webSocket = {
...
@@ -36,6 +36,7 @@ var webSocket = {
socketMsgQueue
=
[]
socketMsgQueue
=
[]
dd
.
connectSocket
({
dd
.
connectSocket
({
url
:
`wss://mingpay-websocket.mingwork.com/v1/mingpaywebsocket?param=
${
dd
.
corpId
}
_
${
dd
.
getStorageSync
({
key
:
'userId'
}).
data
}
`
,
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
:
{},
data
:
{},
header
:{
header
:{
'content-type'
:
'application/json'
'content-type'
:
'application/json'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment