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
93a3dbac
Commit
93a3dbac
authored
Oct 26, 2019
by
fengzhaoyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MOD:线上版,解决刷新token后ios报错
parent
20563565
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
76 additions
and
92 deletions
+76
-92
http.js
API/http.js
+17
-10
login.js
API/login.js
+12
-6
action.js
pages/action/action.js
+6
-44
alipayRecharge.axml
pages/alipayRecharge/alipayRecharge.axml
+1
-1
index.axml
pages/index/index.axml
+1
-1
index.js
pages/index/index.js
+1
-1
payment.js
pages/payment/payment.js
+38
-29
No files found.
API/http.js
View file @
93a3dbac
...
...
@@ -7,14 +7,14 @@ const $http = (url, data, type, loadingType) => {
// content: '加载中...'
// });
// }
dd
.
showLoading
({
content
:
'加载中...'
});
let
hasToken
=
dd
.
getStorageSync
({
key
:
'token'
}).
data
;
// token
let
expires_in
=
hasToken
.
expires_in
||
''
;
// 过期时效
let
loginTime
=
hasToken
.
expires_in
||
''
;
// 用户登陆时间
let
loginTime
=
hasToken
.
loginTime
||
''
;
// 用户登陆时间
let
token
=
hasToken
.
access_token
||
''
;
let
refresh_token
=
hasToken
.
refresh_token
// 刷新token
let
mingUserId
=
dd
.
getStorageSync
({
key
:
'mingUserId'
}).
data
// 时间戳未过期
// if(!!hasToken && ((new Date()).getTime() - hasToken.loginTime < hasToken.expires_in * 1000)){
if
(
!!
hasToken
&&
((
new
Date
()).
getTime
()
-
hasToken
.
loginTime
)
<
(
hasToken
.
expires_in
-
300
)
*
1000
){
data
.
orgId
=
dd
.
corpId
;
let
sendData
=
''
;
...
...
@@ -35,6 +35,14 @@ const $http = (url, data, type, loadingType) => {
if
(
res
.
data
.
resultCode
===
0
)
{
console
.
log
(
res
.
data
.
data
)
return
resolve
(
res
.
data
.
data
)
dd
.
hideLoading
()
}
else
if
(
res
.
data
.
code
==
401
)
{
dd
.
removeStorageSync
({
key
:
'token'
})
dd
.
hideLoading
()
dd
.
redirectTo
({
url
:
'/pages/reTry/reTry'
})
}
else
{
// 修改系统繁忙时loading隐藏
...
...
@@ -69,8 +77,8 @@ const $http = (url, data, type, loadingType) => {
refresh_token
:
res
.
data
.
refresh_token
,
loginTime
:
(
new
Date
()).
getTime
()
}
})
dd
.
hideLoading
()
$http
(
url
,
data
,
type
).
then
(
res
=>
{
return
resolve
(
res
)
})
...
...
@@ -78,12 +86,10 @@ const $http = (url, data, type, loadingType) => {
fail
:
function
(
err
)
{
dd
.
hideLoading
()
if
(
err
.
status
==
426
)
{
dd
.
removeStorageSync
({
key
:
'token'
})
dd
.
redirectTo
({
url
:
'/pages/reTry/reTry'
})
dd
.
removeStorageSync
({
key
:
'token'
})
dd
.
redirectTo
({
url
:
'/pages/reTry/reTry'
})
}
else
{
dd
.
alert
({
...
...
@@ -125,7 +131,7 @@ const $http = (url, data, type, loadingType) => {
url
:
`
${
app
.
globalData
.
globalUrl
}
/auth/oauth/token`
,
method
:
'POST'
,
success
:
function
(
res
)
{
dd
.
removeStorage
({
dd
.
removeStorage
Sync
({
key
:
'token'
})
dd
.
setStorageSync
({
...
...
@@ -137,6 +143,7 @@ const $http = (url, data, type, loadingType) => {
loginTime
:
(
new
Date
()).
getTime
()
}
})
dd
.
hideLoading
()
$http
(
url
,
data
,
type
).
then
(
res
=>
{
return
resolve
(
res
)
})
...
...
API/login.js
View file @
93a3dbac
...
...
@@ -5,15 +5,16 @@ const login = () => {
if
(
dd
.
getStorageSync
({
key
:
'token'
}).
data
&&
dd
.
getStorageSync
({
key
:
'token'
}).
data
.
access_token
)
{
let
hasToken
=
dd
.
getStorageSync
({
key
:
'token'
}).
data
;
// token
let
expires_in
=
hasToken
.
expires_in
||
''
;
// 过期时效
let
loginTime
=
hasToken
.
expires_in
||
''
;
// 用户登陆时间
let
loginTime
=
hasToken
.
loginTime
||
''
;
// 用户登陆时间
let
token
=
hasToken
.
access_token
||
''
;
let
refresh_token
=
hasToken
.
refresh_token
// 刷新token
// 判断token没有过期
if
(
((
new
Date
()).
getTime
()
-
hasToken
.
loginTime
<
hasToken
.
expires_in
*
1000
)
)
{
if
(
new
Date
().
getTime
()
-
hasToken
.
loginTime
<
(
hasToken
.
expires_in
-
300
)
*
1000
)
{
// if(((new Date()).getTime() - hasToken.loginTime < 30 * 1000)) {
dd
.
redirectTo
({
url
:
'/pages/index/index'
})
dd
.
hideLoading
()
dd
.
redirectTo
({
url
:
'/pages/index/index'
})
}
// 判断token过期
else
{
...
...
@@ -45,6 +46,7 @@ const login = () => {
loginTime
:
(
new
Date
()).
getTime
()
}
})
dd
.
hideLoading
()
login
()
}
},
...
...
@@ -53,10 +55,12 @@ const login = () => {
dd
.
removeStorageSync
({
key
:
'token'
})
login
()
dd
.
hideLoading
()
login
()
}
else
{
dd
.
hideLoading
()
dd
.
removeStorageSync
({
key
:
'token'
})
dd
.
redirectTo
({
url
:
'/pages/reTry/reTry'
})
...
...
@@ -66,6 +70,7 @@ const login = () => {
}
else
{
dd
.
hideLoading
()
dd
.
removeStorageSync
({
key
:
'token'
})
dd
.
redirectTo
({
url
:
'/pages/reTry/reTry'
})
...
...
@@ -105,6 +110,7 @@ const login = () => {
loginTime
:
(
new
Date
()).
getTime
()
}
})
dd
.
hideLoading
()
dd
.
redirectTo
({
url
:
'/pages/index/index'
})
...
...
pages/action/action.js
View file @
93a3dbac
...
...
@@ -32,10 +32,11 @@ Page({
})
}
else
{
dd
.
hideLoading
()
dd
.
removeStorageSync
({
key
:
'token'
})
dd
.
redirectTo
({
url
:
'/pages/reTry/reTry'
})
dd
.
hideLoading
()
}
}
}
...
...
@@ -71,10 +72,11 @@ Page({
$login
.
login
()
}
else
{
dd
.
hideLoading
()
dd
.
removeStorageSync
({
key
:
'token'
})
dd
.
redirectTo
({
url
:
'/pages/reTry/reTry'
})
dd
.
hideLoading
()
}
},
fail
:
function
(
res
)
{
...
...
@@ -87,6 +89,8 @@ Page({
})
}
else
{
dd
.
hideLoading
()
dd
.
removeStorageSync
({
key
:
'token'
})
dd
.
redirectTo
({
url
:
'/pages/reTry/reTry'
})
...
...
@@ -95,48 +99,6 @@ Page({
})
},
// 获取token接口
getUserToken
(
mingUserId
)
{
dd
.
httpRequest
({
headers
:
{
'Authorization'
:
'Basic bWluZ3BheS1waG9uZTptaW5ncGF5LXBob25l'
,
'Content-Type'
:
'application/x-www-form-urlencoded'
},
data
:
{
username
:
mingUserId
,
password
:
mingUserId
,
scope
:
'server'
,
grant_type
:
'password'
},
url
:
`
${
app
.
globalData
.
globalUrl
}
/auth/oauth/token`
,
// url:`${app.globalData.globalUrl}/auth/oauth/`,
method
:
'POST'
,
dataType
:
'json'
,
success
:
function
(
res
)
{
dd
.
setStorageSync
({
key
:
'token'
,
data
:
{
access_token
:
res
.
data
.
access_token
,
expires_in
:
res
.
data
.
expires_in
,
refresh_token
:
res
.
data
.
refresh_token
,
loginTime
:
(
new
Date
()).
getTime
()
}
})
dd
.
hideLoading
()
dd
.
redirectTo
({
url
:
'/pages/index/index'
})
},
fail
:
function
(
res
)
{
console
.
log
(
'err'
,
res
)
dd
.
redirectTo
({
url
:
'/pages/reTry/reTry'
})
dd
.
hideLoading
()
}
})
},
onReady
()
{
// 页面加载完成
},
...
...
pages/alipayRecharge/alipayRecharge.axml
View file @
93a3dbac
...
...
@@ -10,7 +10,7 @@
<view class="{{type === '6' ? 'clickTabs' : ''}}" data-num="300" onTap="changeRechargeNum">300元</view>
</view>
<view class="rechargeInput">
¥<input Screenshot value="{{inputValue}}" type="number" style="font-size:48rpx;height: 60rpx" onInput="bindKeyInput" placeholder="请输入充值金额"/>
¥<input
Screenshot value="{{inputValue}}" type="number" style="font-size:48rpx;height: 60rpx" onInput="bindKeyInput" placeholder="请输入充值金额"/>
</view>
<text>{{messagedetail}}</text>
</view>
...
...
pages/index/index.axml
View file @
93a3dbac
...
...
@@ -11,7 +11,7 @@
</view>
<view class="balanceBox">
<view class="balancetitle">账户余额</view>
<view>¥ <view class="balanceNum">{{
realityBalance
? realityBalance.toFixed(2) : '--'}}</view></view>
<view>¥ <view class="balanceNum">{{
`${realityBalance}`
? realityBalance.toFixed(2) : '--'}}</view></view>
</view>
<view class="indexItemList">
<view touchStart="touchStyle" touchEnd="touchEnd" onTap="toPayment"><image mode="scaleToFill" src="./../../assets/QRcode.png"/>付款</view>
...
...
pages/index/index.js
View file @
93a3dbac
...
...
@@ -16,7 +16,7 @@ Page({
// },
onLoad
(
query
)
{
dd
.
hideLoading
()
const
_that
=
this
;
dd
.
setNavigationBar
({
title
:
'一卡通'
,
...
...
pages/payment/payment.js
View file @
93a3dbac
...
...
@@ -13,7 +13,8 @@ Page({
size
:
272
,
url
:
''
,
ecc
:
2
,
isTimeOut
:
true
isTimeOut
:
true
,
ma
:
''
},
onLoad
(
query
)
{
// 页面加载
...
...
@@ -33,15 +34,33 @@ Page({
},
// 生成二维码
refreshQRcode
(){
webSocket
.
closeSocket
();
dd
.
getNetworkType
({
success
:
(
res
)
=>
{
// 有网络状态
if
(
res
.
networkAvailable
)
{
// 获取免登授权码
webSocket
.
connectSocket
();
webSocket
.
onSocketMessageCallback
=
this
.
onSocketMessageCallback
;
}
}
});
const
_that
=
this
;
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 < 1* 1000)) {
console
.
log
(
dd
.
getStorageSync
({
key
:
'token'
}).
data
.
refresh_token
,
1111111111
)
if
(
!!
hasToken
&&
(
new
Date
().
getTime
()
-
hasToken
.
loginTime
<
(
hasToken
.
expires_in
-
300
)
*
1000
))
{
// if(!!hasToken && ((new Date()).getTime() - hasToken.loginTime < 30* 1000)) {
this
.
setData
({
isTimeOut
:
true
})
let
timestamp
=
(
new
Date
()).
getTime
();
let
url
=
aes
.
getAES
(
JSON
.
stringify
({
"token"
:
token
,
...
...
@@ -52,15 +71,14 @@ Page({
let
name
=
'myQrcode'
const
ctx
=
dd
.
createCanvasContext
(
name
);
QR
.
draw
(
url
,
ctx
,
size
,
Number
(
ecc
));
dd
.
hideLoading
()
}
else
{
dd
.
getNetworkType
({
success
:
(
res
=>
{
// 网络可用的情况下 刷新token
if
(
res
.
networkAvailable
)
{
dd
.
showLoading
({
content
:
'加载中...'
});
dd
.
httpRequest
({
headers
:
{
'Authorization'
:
'Basic bWluZ3BheS1waG9uZTptaW5ncGF5LXBob25l'
,
...
...
@@ -74,9 +92,9 @@ Page({
},
method
:
'POST'
,
success
:
function
(
res
)
{
dd
.
removeStorage
({
key
:
'token'
})
// dd.removeStorageSync
({
//
key:'token'
//
})
dd
.
setStorageSync
({
key
:
'token'
,
data
:
{
...
...
@@ -90,14 +108,9 @@ Page({
_that
.
setData
({
isTimeOut
:
true
})
// hasToken = dd.getStorageSync({ key: 'token' }).data;
// token = dd.getStorageSync({ key: 'token' }).data.access_token;
// expires_in = dd.getStorageSync({ key: 'token' }).data.expires_in;
// refresh_token = dd.getStorageSync({ key: 'token' }).data.refresh_token;
let
timestamp
=
(
new
Date
()).
getTime
();
let
url
=
aes
.
getAES
(
JSON
.
stringify
({
"token"
:
token
,
"token"
:
res
.
data
.
access_
token
,
"timestamp"
:
timestamp
,
}))
let
size
=
272
...
...
@@ -109,15 +122,20 @@ Page({
},
fail
:
function
(
err
)
{
if
(
err
.
status
==
426
)
{
dd
.
redirectTo
({
url
:
'/pages/reTry/reTry'
})
dd
.
hideLoading
()
dd
.
removeStorageSync
({
key
:
'token'
})
dd
.
redirectTo
({
url
:
'/pages/reTry/reTry'
})
}
else
{
dd
.
alert
({
content
:
'请检查网络并下拉重试'
,
buttonText
:
'确定'
})
_that
.
setData
({
isTimeOut
:
false
})
dd
.
hideLoading
()
}
}
...
...
@@ -153,16 +171,7 @@ Page({
_that
.
refreshQRcode
();
},
55000
);
},
500
)
dd
.
getNetworkType
({
success
:
(
res
)
=>
{
// 有网络状态
if
(
res
.
networkAvailable
)
{
// 获取免登授权码
webSocket
.
connectSocket
();
webSocket
.
onSocketMessageCallback
=
this
.
onSocketMessageCallback
;
}
}
});
},
// socket收到的信息回调
onSocketMessageCallback
:
function
(
res
)
{
...
...
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