提交 35669278 authored 作者: 钟是志's avatar 钟是志

修改鉴权代码, 让时间戳不再使用定时器获取

上级 6c05fb2d
...@@ -9,9 +9,8 @@ const isTest = getUrlInfo().test; ...@@ -9,9 +9,8 @@ const isTest = getUrlInfo().test;
export function getHeaders(url = '') { export function getHeaders(url = '') {
const token = getToken(); const token = getToken();
const currentInfo = getCurrentUser(); const currentInfo = getCurrentUser();
const timestamp = window.serviceCurrentDate || new Date().getTime(); const timestamp = new Date().getTime() + window.differenceBetweenServerAndClientTime;
const secretString = token + currentInfo.xgUserId + timestamp; const secretString = token + currentInfo.xgUserId + timestamp;
// const secretString = token + '112233' + timestamp;
const res = { const res = {
headers: { headers: {
...@@ -29,6 +28,7 @@ export function getHeaders(url = '') { ...@@ -29,6 +28,7 @@ export function getHeaders(url = '') {
timestamp, timestamp,
xgUserId: currentInfo.xgUserId, xgUserId: currentInfo.xgUserId,
typeString: currentInfo.typeString, typeString: currentInfo.typeString,
differenceBetweenServerAndClientTime: window.differenceBetweenServerAndClientTime,
}, },
); );
} }
......
import request from '@/webPublic/zyd_public/request/request'; import request from '@/webPublic/zyd_public/request/request';
import config from '@/config/config'; import config from '@/config/config';
window.differenceBetweenServerAndClientTime = 0;
const getTime = () => { const getTime = () => {
return request(`${config.mockServer}/${config.gateWayUrl.zydxg}/InstructorConfigApi/getCurrentDate`, { return request(`${config.mockServer}/${config.gateWayUrl.zydxg}/InstructorConfigApi/getCurrentDate`, {
method: 'POST', method: 'POST',
...@@ -11,10 +11,7 @@ const getTime = () => { ...@@ -11,10 +11,7 @@ const getTime = () => {
export async function queryCurrent() { export async function queryCurrent() {
let t = await getTime(); let t = await getTime();
if (t) { if (t) {
window.serviceCurrentDate = t; // 服务器时间 window.differenceBetweenServerAndClientTime = t - new Date().getTime(); // 服务器时间 与 客户端时间的差值
setInterval(() => {
window.serviceCurrentDate += 1000;
}, 1000);
} }
return request(`${config.mockServer}/${config.gateWayUrl.zydxg}/UserApi/queryCurrent`, { return request(`${config.mockServer}/${config.gateWayUrl.zydxg}/UserApi/queryCurrent`, {
method: 'POST', method: 'POST',
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论