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
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
49 deletions
+44
-49
app.js
app.js
+1
-1
payment.js
pages/payment/payment.js
+42
-48
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,27 +24,16 @@ Page({
...
@@ -24,27 +24,16 @@ 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
:
'加载中...'
...
@@ -54,10 +43,9 @@ Page({
...
@@ -54,10 +43,9 @@ Page({
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
();
...
@@ -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
:
{
...
@@ -117,12 +101,11 @@ Page({
...
@@ -117,12 +101,11 @@ Page({
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,16 +144,27 @@ Page({
...
@@ -161,16 +144,27 @@ Page({
},
},
onShow
()
{
onShow
()
{
console
.
log
(
'进入onshow'
)
console
.
log
(
'进入onshow'
)
//刷新二维码
const
_that
=
this
;
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
);
clearInterval
(
timeRefreshQRcode
);
_that
.
refreshQRcode
();
_that
.
refreshQRcode
();
timeRefreshQRcode
=
setInterval
(
function
()
{
timeRefreshQRcode
=
setInterval
(
function
()
{
_that
.
refreshQRcode
();
_that
.
refreshQRcode
();
},
55000
);
},
55000
);
},
500
)
},
500
)
},
},
// socket收到的信息回调
// socket收到的信息回调
onSocketMessageCallback
:
function
(
res
)
{
onSocketMessageCallback
:
function
(
res
)
{
...
@@ -179,27 +173,27 @@ Page({
...
@@ -179,27 +173,27 @@ Page({
}
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
();
_that
.
refreshQRcode
();
timeRefreshQRcode
=
setInterval
(
function
()
{
timeRefreshQRcode
=
setInterval
(
function
()
{
_that
.
refreshQRcode
();
_that
.
refreshQRcode
();
},
55000
);
},
55000
);
},
500
)
},
500
)
dd
.
getNetworkType
({
//
dd.getNetworkType({
success
:
(
res
)
=>
{
//
success: (res) => {
// 有网络状态
//
// 有网络状态
if
(
res
.
networkAvailable
)
{
//
if (res.networkAvailable) {
// 获取免登授权码
//
// 获取免登授权码
webSocket
.
connectSocket
();
//
webSocket.connectSocket();
webSocket
.
onSocketMessageCallback
=
this
.
onSocketMessageCallback
;
//
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