Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CFFP-HB
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chao Sun
CFFP-HB
Commits
af0f6fd9
Commit
af0f6fd9
authored
Mar 02, 2023
by
wenyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化H5用支付宝支付时跳转浏览器打开的Token问题
parent
4d691bd4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
59 deletions
+65
-59
api/api.ts
+0
-0
pages/orderConfirm/orderConfirm.vue
+0
-0
util/interceptor.ts
+65
-59
No files found.
api/api.ts
View file @
af0f6fd9
This diff is collapsed.
Click to expand it.
pages/orderConfirm/orderConfirm.vue
View file @
af0f6fd9
This diff is collapsed.
Click to expand it.
util/interceptor.ts
View file @
af0f6fd9
// import {baseURL,apiURL,cffpURL} from "../environments/environment";
// import {baseURL,apiURL,cffpURL} from "../environments/environment";
// 白名单,不需要携带token就允许被访问的接口
// 白名单,不需要携带token就允许被访问的接口
const
whiteApiList
=
[
`/api/authorize/obtainToken`
,
`/api/authorize/checkToken`
];
const
whiteApiList
=
[
`/api/authorize/obtainToken`
,
`/api/authorize/checkToken`
];
export
const
interceptor
=
()
=>
{
export
const
interceptor
=
()
=>
{
uni
.
addInterceptor
(
'request'
,
{
uni
.
addInterceptor
(
'request'
,
{
// 请求拦截器
// 请求拦截器
invoke
(
args
)
{
invoke
(
args
)
{
// console.log('请求拦截器',args);
// console.log('请求拦截器',args);
// 加载loading
// 加载loading
// uni.showLoading({
// uni.showLoading({
// title: '加载中...'
// title: '加载中...'
// });
// });
// 当本地没有token,并且接口地址没在白名单内,需要重新获取token
// 当本地没有token,并且接口地址没在白名单内,需要重新获取token
if
(
!
uni
.
getStorageSync
(
'uni-token'
)
&&
!
whiteApiList
.
includes
(
args
.
url
))
{
if
(
!
uni
.
getStorageSync
(
'uni-token'
)
&&
!
whiteApiList
.
includes
(
args
.
url
))
{
uni
.
request
({
const
params
=
{
url
:
'/api/authorize/obtainToken'
,
ticket
:
'uni-app'
,
method
:
'POST'
,
loginId
:
null
data
:
{
ticket
:
'uni-app'
},
}
success
:
(
res
)
=>
{
let
h5userId
=
uni
.
getStorageSync
(
'cffp_userId'
);
if
(
res
.
statusCode
===
200
)
{
if
(
h5userId
)
{
uni
.
setStorageSync
(
'uni-token'
,
res
.
data
[
'data'
][
'token'
]);
params
.
loginId
=
h5userId
;
window
.
location
.
href
=
window
.
location
.
href
+
'?'
+
't_reload='
+
new
Date
().
getTime
();
}
}
uni
.
request
({
// console.log(res)
url
:
'/api/authorize/obtainToken'
,
}
method
:
'POST'
,
})
data
:
params
,
// uni.hideLoading();
success
:
(
res
)
=>
{
}
if
(
res
.
statusCode
===
200
)
{
// request 触发前拼接 url
uni
.
setStorageSync
(
'uni-token'
,
res
.
data
[
'data'
][
'token'
]);
window
.
location
.
href
=
window
.
location
.
href
+
'?'
+
't_reload='
+
new
Date
().
getTime
();
//设置请求头及token
}
args
.
header
=
{
}
'content-type'
:
args
.
method
===
'POST'
?
'application/json'
:
'application/x-www-form-urlencoded'
,
})
'X-Authorization'
:
uni
.
getStorageSync
(
'uni-token'
)
?
uni
.
getStorageSync
(
'uni-token'
)
:
''
,
}
// 'Access-Control-Allow-Headers': 'appId',
// request 触发前拼接 url
// 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
// 'Access-Control-Max-Age': 86400,
//设置请求头及token
}
args
.
header
=
{
// console.log(args.header)
'content-type'
:
args
.
method
===
'POST'
?
'application/json'
:
'application/x-www-form-urlencoded'
,
},
'X-Authorization'
:
uni
.
getStorageSync
(
'uni-token'
)
?
uni
.
getStorageSync
(
'uni-token'
)
:
''
,
// 'Access-Control-Allow-Headers': 'appId',
// 响应拦截器,可以对数据进行预处理
// 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
success
()
{
// 'Access-Control-Max-Age': 86400,
// uni.hideLoading()
}
// console.log(args);
// console.log(args.header)
},
},
fail
()
{
// console.log('interceptor-fail', err)
// 响应拦截器,可以对数据进行预处理
// console.log('请求失败')
success
()
{
// uni.hideLoading()
// uni.hideLoading()
},
// console.log(args);
complete
()
{
},
// uni.hideLoading()
fail
()
{
}
// console.log('interceptor-fail', err)
})
// console.log('请求失败')
}
// uni.hideLoading()
},
complete
()
{
// uni.hideLoading()
}
})
}
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