Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mingPayPc
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
mingPayPc
Commits
1644de7d
Commit
1644de7d
authored
Oct 23, 2019
by
liang ce
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
token更新
parent
e7ef8652
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
135 additions
and
80 deletions
+135
-80
axios.js
src/api/axios.js
+24
-34
config.js
src/api/config.js
+9
-39
constant.js
src/api/constant.js
+1
-7
generateOrRefreshToken.js
src/api/generateOrRefreshToken.js
+96
-0
AccountManagement.vue
src/components/pages/PaymentManagement/AccountManagement.vue
+2
-0
CashierManagement.vue
src/components/pages/PaymentManagement/CashierManagement.vue
+1
-0
PaymentManagementSetting.vue
...ents/pages/PaymentManagement/PaymentManagementSetting.vue
+1
-0
SetAdministrators.vue
src/components/pages/PaymentManagement/SetAdministrators.vue
+1
-0
No files found.
src/api/axios.js
View file @
1644de7d
import
axios
from
'axios'
import
qs
from
'qs'
var
instance
=
axios
.
create
()
// axios.defaults.baseURL = 'http://192.168.1.106:8300/v1/isv' // 本地荣
// axios.defaults.baseURL = 'http://192.168.1.102:8300/v1/isv' // 本地钱
// axios.defaults.baseURL = 'http://139.196.213.18:8300/v1/isv' // beta环境
import
{
getToken
,
refreshToken
}
from
'./generateOrRefreshToken'
const
BASE_URL
=
process
.
env
.
VUE_APP_API_URL
let
loadingInstance
// 创建Loading 的实例
// 配置发送请求前的拦截器
可以
设置token信息
// 配置发送请求前的拦截器
,
设置token信息
axios
.
interceptors
.
request
.
use
((
config
)
=>
{
// loading开始loadingInstance.start()
let
isRefreshToken
=
new
Date
().
getTime
()
-
sessionStorage
.
getItem
(
'start_time'
)
<
session
Storage
.
getItem
(
'expires_in'
)
-
5
*
60
*
1000
let
isRefreshToken
=
new
Date
().
getTime
()
-
localStorage
.
getItem
(
'start_time'
)
<
local
Storage
.
getItem
(
'expires_in'
)
-
5
*
60
*
1000
if
(
isRefreshToken
)
{
config
.
headers
[
'Authorization'
]
=
`Bearer
${
session
Storage
.
getItem
(
'access_token'
)}
`
config
.
headers
[
'Authorization'
]
=
`Bearer
${
local
Storage
.
getItem
(
'access_token'
)}
`
return
config
}
else
{
return
new
Promise
((
resolve
,
reject
)
=>
{
getToken
().
then
((
response
)
=>
{
sessionStorage
.
setItem
(
'access_token'
,
response
.
data
.
access_token
)
sessionStorage
.
setItem
(
'refresh_token'
,
response
.
data
.
refresh_token
)
sessionStorage
.
setItem
(
'expires_in'
,
response
.
data
.
expires_in
*
1000
)
sessionStorage
.
setItem
(
'start_time'
,
new
Date
().
getTime
())
resolve
(
config
)
return
config
refreshToken
().
then
((
res
)
=>
{
console
.
log
(
'res'
,
res
)
}).
catch
((
err
)
=>
{
console
.
log
(
err
)
})
...
...
@@ -32,24 +23,27 @@ axios.interceptors.request.use((config) => {
loadingInstance
.
close
()
return
Promise
.
reject
(
error
)
})
function
getToken
()
{
let
loginData
=
qs
.
stringify
(
{
refresh_token
:
sessionStorage
.
getItem
(
'refresh_token'
),
grant_type
:
'refresh_token'
})
// 配置请求返回的拦截器,
axios
.
interceptors
.
response
.
use
(
res
=>
{
return
Promise
.
resolve
(
res
)
},
err
=>
{
debugger
return
new
Promise
((
resolve
,
reject
)
=>
{
instance
.
post
(
`
${
BASE_URL
}
/auth/oauth/token`
,
loginData
,
{
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8'
,
'Authorization'
:
'Basic bWluZ3BheS13ZWI6bWluZ3BheS13ZWI='
}
}).
then
((
res
)
=>
{
resolve
(
res
)
}).
catch
((
err
)
=>
{
console
.
log
(
err
)
if
(
err
&&
err
.
response
.
data
.
code
===
401
)
{
refreshToken
().
then
(
res
=>
{
console
.
log
(
'refreshToken1'
,
res
)
resolve
(
err
)
})
}
else
if
(
err
&&
err
.
response
.
data
.
code
===
426
)
{
getToken
().
then
((
res
)
=>
{
console
.
log
(
'getToken1'
,
res
)
resolve
(
err
)
})
}
}
else
{
reject
(
new
Error
(
err
))
}
})
})
const
$http
=
{
post
:
(
url
,
data
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
@@ -59,8 +53,6 @@ const $http = {
}
}).
then
((
res
)
=>
{
return
resolve
(
res
)
}).
catch
((
error
)
=>
{
return
reject
(
error
)
})
})
},
...
...
@@ -68,8 +60,6 @@ const $http = {
return
new
Promise
((
resolve
,
reject
)
=>
{
axios
.
get
(
`
${
BASE_URL
}${
url
}
`
).
then
((
res
)
=>
{
return
resolve
(
res
)
}).
catch
((
error
)
=>
{
return
reject
(
error
)
})
})
}
...
...
src/api/config.js
View file @
1644de7d
import
*
as
dd
from
'dingtalk-jsapi'
import
axios
from
'axios'
import
qs
from
'qs'
import
{
MINGPAY_CONSTANT
}
from
'./constant
'
import
{
getToken
,
refreshToken
}
from
'./generateOrRefreshToken
'
let
basurl
=
process
.
env
.
VUE_APP_API_URL
// axios.defaults.headers['Authorization'] = `Bearer ${localStorage.getItem('token')}`
const
config
=
{
...
...
@@ -45,49 +45,19 @@ const config = {
ddpermission
:
()
=>
{
// dd.ready参数为回调函数,在环境准备就绪时触发,jsapi的调用需要保证在该回调函数触发后调用,否则无效。
return
new
Promise
((
resolve
,
reject
)
=>
{
dd
.
runtime
.
permission
.
requestAuthCode
({
corpId
:
localStorage
.
getItem
(
'orgId'
),
// 企业id
onSuccess
:
function
(
info
)
{
let
senddate
=
qs
.
stringify
({
// version: 'v1',
code
:
info
.
code
,
orgId
:
localStorage
.
getItem
(
'orgId'
)
})
return
axios
.
post
(
`
${
basurl
}
/mingpay/v1/skipAuth/getUserInfoByCode?
${
senddate
}
`
).
then
((
res
)
=>
{
console
.
log
(
res
.
data
.
resultCode
)
if
(
res
.
data
.
resultCode
===
0
)
{
return
res
.
data
.
data
.
mingUserId
}
}).
then
((
mingUserId
)
=>
{
let
loginData
=
qs
.
stringify
({
username
:
mingUserId
,
password
:
mingUserId
,
scope
:
'server'
,
grant_type
:
'password'
})
return
axios
.
post
(
`
${
basurl
}
/auth/oauth/token`
,
loginData
,
{
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8'
,
'Authorization'
:
'Basic bWluZ3BheS13ZWI6bWluZ3BheS13ZWI='
}
}).
then
((
response
)
=>
{
console
.
log
(
response
)
sessionStorage
.
setItem
(
'access_token'
,
response
.
data
.
access_token
)
sessionStorage
.
setItem
(
'refresh_token'
,
response
.
data
.
refresh_token
)
sessionStorage
.
setItem
(
'expires_in'
,
response
.
data
.
expires_in
*
1000
)
sessionStorage
.
setItem
(
'start_time'
,
new
Date
().
getTime
())
let
isRefreshToken
=
new
Date
().
getTime
()
-
localStorage
.
getItem
(
'start_time'
)
<
localStorage
.
getItem
(
'expires_in'
)
-
5
*
60
*
1000
if
(
localStorage
.
getItem
(
'access_token'
)
&&
isRefreshToken
)
{
resolve
(
'ok'
)
}
else
if
(
localStorage
.
getItem
(
'refresh_token'
))
{
refreshToken
().
then
((
res
)
=>
{
resolve
(
'ok'
)
}).
catch
(()
=>
{
resolve
(
'noPermission'
)
})
}
else
{
getToken
().
then
(()
=>
{
resolve
(
'ok'
)
})
},
onFail
:
function
(
err
)
{
console
.
log
(
err
)
}
})
})
},
ddchooseOne
:
()
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
src/api/constant.js
View file @
1644de7d
const
MINGPAY_CONSTANT
=
{
MINGPAY_CONSTANT_URL
:
'http://mingpay-web-beta.mingwork.com:8888/'
,
// MINGPAY_CONSTANT_URL: 'http://ming.vaiwan.com/',
MINGPAY_CONSTANT_AGENTID
:
270198704
,
MINGPAY_CONSTANT_VERSION
:
'v1'
}
const
MINGPAY_ACCOUNT_STATUS
=
{
ACTIVE
:
'ACTIVE'
,
// 初始激活状态(冻结操作)
UNACTIVE
:
'UNACTIVE'
,
// 冻结状态(解冻操作 AND 注销操作)
...
...
@@ -31,4 +25,4 @@ const MINGPAY_SUBSIDY_STATUS = {
REFUSE_PERMIT
:
'REFUSE_PERMIT'
}
export
{
MINGPAY_
CONSTANT
,
MINGPAY_
ACCOUNT_STATUS
,
MINGPAY_CHARGE_ORDERSTATUS
,
MINGPAY_RECORDS_STATUS
,
MINGPAY_SUBSIDY_STATUS
}
export
{
MINGPAY_ACCOUNT_STATUS
,
MINGPAY_CHARGE_ORDERSTATUS
,
MINGPAY_RECORDS_STATUS
,
MINGPAY_SUBSIDY_STATUS
}
src/api/generateOrRefreshToken.js
0 → 100644
View file @
1644de7d
import
*
as
dd
from
'dingtalk-jsapi'
import
axios
from
'axios'
import
qs
from
'qs'
var
instance
=
axios
.
create
()
const
BASE_URL
=
process
.
env
.
VUE_APP_API_URL
// function generateOrRefreshToken () {
// }
instance
.
interceptors
.
response
.
use
(
res
=>
{
return
Promise
.
resolve
(
res
)
},
err
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
err
&&
err
.
response
.
status
===
401
&&
err
.
response
.
data
.
code
===
401
)
{
refreshToken
().
then
(
res
=>
{
console
.
log
(
'refreshToken1'
,
res
)
resolve
(
err
)
})
}
else
if
(
err
&&
err
.
response
.
status
===
426
&&
err
.
response
.
data
.
code
===
1
)
{
getToken
().
then
((
res
)
=>
{
console
.
log
(
'getToken1'
,
res
)
resolve
(
err
)
})
}
})
})
function
getToken
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
dd
.
runtime
.
permission
.
requestAuthCode
({
corpId
:
localStorage
.
getItem
(
'orgId'
),
// 企业id
onSuccess
:
function
(
info
)
{
let
senddate
=
qs
.
stringify
({
code
:
info
.
code
,
orgId
:
localStorage
.
getItem
(
'orgId'
)
})
return
instance
.
post
(
`
${
BASE_URL
}
/mingpay/v1/skipAuth/getUserInfoByCode?
${
senddate
}
`
).
then
((
res
)
=>
{
console
.
log
(
res
.
data
.
resultCode
)
if
(
res
.
data
.
resultCode
===
0
)
{
return
res
.
data
.
data
.
mingUserId
}
}).
then
((
mingUserId
)
=>
{
let
loginData
=
qs
.
stringify
({
username
:
mingUserId
,
password
:
mingUserId
,
scope
:
'server'
,
grant_type
:
'password'
})
return
instance
.
post
(
`
${
BASE_URL
}
/auth/oauth/token`
,
loginData
,
{
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8'
,
'Authorization'
:
'Basic bWluZ3BheS13ZWI6bWluZ3BheS13ZWI='
}
}).
then
((
response
)
=>
{
console
.
log
(
response
)
localStorage
.
setItem
(
'access_token'
,
response
.
data
.
access_token
)
localStorage
.
setItem
(
'refresh_token'
,
response
.
data
.
refresh_token
)
localStorage
.
setItem
(
'expires_in'
,
response
.
data
.
expires_in
*
1000
)
localStorage
.
setItem
(
'start_time'
,
new
Date
().
getTime
())
resolve
(
'ok'
)
}).
catch
(()
=>
{
resolve
(
'noPermission'
)
})
})
},
onFail
:
function
(
err
)
{
console
.
log
(
err
)
}
})
})
}
function
refreshToken
()
{
let
loginData
=
qs
.
stringify
({
refresh_token
:
localStorage
.
getItem
(
'refresh_token'
),
grant_type
:
'refresh_token'
})
return
new
Promise
((
resolve
,
reject
)
=>
{
instance
.
post
(
`
${
BASE_URL
}
/auth/oauth/token`
,
loginData
,
{
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8'
,
'Authorization'
:
'Basic bWluZ3BheS13ZWI6bWluZ3BheS13ZWI='
}
}).
then
((
res
)
=>
{
localStorage
.
setItem
(
'access_token'
,
res
.
data
.
access_token
)
localStorage
.
setItem
(
'refresh_token'
,
res
.
data
.
refresh_token
)
localStorage
.
setItem
(
'expires_in'
,
res
.
data
.
expires_in
*
1000
)
localStorage
.
setItem
(
'start_time'
,
new
Date
().
getTime
())
resolve
(
'ok'
)
}).
catch
((
err
)
=>
{
resolve
(
err
)
})
})
}
export
{
getToken
,
refreshToken
}
src/components/pages/PaymentManagement/AccountManagement.vue
View file @
1644de7d
...
...
@@ -221,6 +221,7 @@ export default {
_that
.
accountList
=
res
.
data
.
data
.
recordList
_that
.
pagination
.
total
=
parseInt
(
res
.
data
.
data
.
totalCount
)
}).
catch
((
err
)
=>
{
this
.
$message
.
error
(
'网络异常请重试'
)
console
.
log
(
err
)
})
},
...
...
@@ -480,6 +481,7 @@ export default {
this
.
$message
.
error
(
res
.
data
.
message
)
}
}).
catch
((
err
)
=>
{
this
.
$message
.
error
(
'网络异常请重试'
)
console
.
log
(
err
)
})
},
...
...
src/components/pages/PaymentManagement/CashierManagement.vue
View file @
1644de7d
...
...
@@ -133,6 +133,7 @@ export default {
this
.
$message
.
error
(
res
.
data
.
message
)
}
}).
catch
((
err
)
=>
{
this
.
$message
.
error
(
'网络异常请重试'
)
console
.
log
(
err
)
})
})
...
...
src/components/pages/PaymentManagement/PaymentManagementSetting.vue
View file @
1644de7d
...
...
@@ -73,6 +73,7 @@ export default {
console
.
log
(
res
)
this
.
OrgSettingData
=
res
.
data
.
data
}).
catch
((
err
)
=>
{
this
.
$message
.
error
(
'网络异常请重试'
)
console
.
log
(
err
)
})
},
...
...
src/components/pages/PaymentManagement/SetAdministrators.vue
View file @
1644de7d
...
...
@@ -133,6 +133,7 @@ export default {
this
.
$message
.
error
(
res
.
data
.
message
)
}
}).
catch
((
err
)
=>
{
this
.
$message
.
error
(
'网络异常请重试'
)
console
.
log
(
err
)
})
})
...
...
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