From b08adb03666ef117ac9832524e57414deabe0c4f Mon Sep 17 00:00:00 2001 From: jixudong Date: Mon, 11 Dec 2023 16:37:36 +0800 Subject: [PATCH] Replace 创作平台请求header.md --- gameditor/前端接口/创作平台请求header.md | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 97 insertions(+), 12 deletions(-) diff --git "a/gameditor/\345\211\215\347\253\257\346\216\245\345\217\243/\345\210\233\344\275\234\345\271\263\345\217\260\350\257\267\346\261\202header.md" "b/gameditor/\345\211\215\347\253\257\346\216\245\345\217\243/\345\210\233\344\275\234\345\271\263\345\217\260\350\257\267\346\261\202header.md" index e6c5083..016c28c 100644 --- "a/gameditor/\345\211\215\347\253\257\346\216\245\345\217\243/\345\210\233\344\275\234\345\271\263\345\217\260\350\257\267\346\261\202header.md" +++ "b/gameditor/\345\211\215\347\253\257\346\216\245\345\217\243/\345\210\233\344\275\234\345\271\263\345\217\260\350\257\267\346\261\202header.md" @@ -1,13 +1,98 @@ -**请求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); + } + ); +``` -- libgit2 0.27.1