Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jiaoyou_doc
Project
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
李进峰
jiaoyou_doc
Commits
b08adb03
Commit
b08adb03
authored
Dec 11, 2023
by
jixudong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace 创作平台请求header.md
parent
d517b8fe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
13 deletions
+98
-13
创作平台请求header.md
gameditor/前端接口/创作平台请求header.md
+98
-13
No files found.
gameditor/前端接口/创作平台请求header.md
View file @
b08adb03
**请求header已经在所有接口请求时统一携带,在前端创作平台项目http文件下的intercept.js文件的请求拦截器中封装**
### 请求header
**请求header已经在所有接口请求时统一携带,在前端创作平台项目http文件下的intercept.js文件的请求拦截器中封装**
#### 请求header
| key | value |
| :------------ | :----------------------------- |
| Content-Type | application/json;charset=utf-8 |
| Authorization | 用户认证签名 |
| Botaccount | 作品帐号 |
| Groupid | 项目组ID |
| Mul | true(默认值写死) |
| Projectid | 项目ID(默认值写死) |
### 请求header
**请求header已经在所有接口请求时统一携带,具体接口发请求时不用考虑header,在前端创作平台项目http文件下的intercept.js文件的请求拦截器中进行了封装**
通用配置
| key | value |
| :----------- | :----------------------------- |
| Content-Type | application/json;charset=utf-8 |
如果用户进入到某个作品后,统一在请求头加上如下参数
| key | value |
| :------------ | :------------------------------- |
| Content-Type | application/json;charset=utf-8 |
| Authorization | 用户认证签名(用户登录后统一携带) |
| Botaccount | 作品帐号 |
| Groupid | 项目组ID |
| Mul | true(默认值写死) |
| Projectid | 项目ID(默认值写死) |
代码
```
js
// 通用配置
var
instance
=
axios
.
create
({
headers
:
{
"Content-Type"
:
"application/json;charset=UTF-8"
,
},
timeout
:
60
*
1000
*
5
// 5分钟ajax请求超时
});
let
isheadrsinfo
=
JSON
.
parse
(
sessionStorage
.
getItem
(
"headrsinfo"
));
// 如果用户进入到某个作品后,统一在请求头加上如下参数
if
(
isheadrsinfo
)
{
var
instance
=
axios
.
create
({
headers
:
{
"Content-Type"
:
"application/json;charset=UTF-8"
,
projectId
:
isheadrsinfo
.
projectId
,
mul
:
isheadrsinfo
.
mul
,
groupId
:
isheadrsinfo
.
groupId
,
botAccount
:
isheadrsinfo
.
botAccount
,
// "Origin":'hw-gz54.heyqiwu.cn'
},
timeout
:
60
*
1000
*
5
// 5分钟超时
});
}
// 请求前拦截
instance
.
interceptors
.
request
.
use
(
async
function
(
config
)
{
// console.log(config)
let
nextChecked
=
window
.
localStorage
.
getItem
(
"nextChecked"
);
let
now
=
new
Date
().
getTime
();
let
overTime
=
window
.
localStorage
.
getItem
(
"duration"
)
-
5000
;
if
(
mask
)
{
// 加上蒙层等待效果
maskDialog
.
createMask
(
mask
);
}
//勾选保持登录 过期处理
if
(
nextChecked
===
"1"
&&
now
>=
overTime
&&
clockIt
)
{
clockIt
=
false
;
let
password
=
window
.
localStorage
.
getItem
(
"loginPassWord"
);
let
userName
=
window
.
localStorage
.
getItem
(
"loginName"
);
let
parme
=
{
username
:
decodeURI
(
userName
),
password
:
window
.
atob
(
window
.
atob
(
password
))
};
const
res
=
await
toLogin
(
parme
)
if
(
res
.
data
.
code
===
1
)
{
var
duration
=
res
.
data
.
data
.
duration
;
//超时时间
let
overTimes
=
new
Date
().
getTime
()
+
duration
;
localStorage
.
setItem
(
"duration"
,
overTimes
);
console
.
log
(
new
Date
(
overTimes
),
"超时时间"
);
console
.
log
(
res
.
data
.
data
,
"2222"
);
cookie
.
setCookie
(
"platform_token"
,
res
.
data
.
data
.
token
,
duration
);
// 存入localStorage
window
.
localStorage
.
setItem
(
"platform_token"
,
res
.
data
.
data
.
token
);
config
.
auth
.
username
=
res
.
data
.
data
.
token
;
config
.
headers
.
Authorization
=
"Basic "
+
btoa
(
res
.
data
.
data
.
token
+
":"
+
"s00pers3cret"
);
location
.
reload
()
}
clockIt
=
true
;
// resolve()
// });
}
// console.log(config);
return
config
;
},
function
(
error
)
{
return
Promise
.
reject
(
error
);
}
);
```
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