|
@@ -4,11 +4,19 @@ import axios from "axios";
|
|
|
import { loadProgressBar } from "axios-progress-bar";
|
|
|
import cachingGet from "./axiosCache";
|
|
|
import { notifyInvalidTokenThrottled } from "./axiosNotice";
|
|
|
-import { getToken, removeToken } from "../auth/auth";
|
|
|
+import { getToken, removeToken, getSessionId } from "../auth/auth";
|
|
|
import axiosRetry from "axios-retry";
|
|
|
import { PLATFORM, DEVICE_ID } from "@/constant/constants";
|
|
|
import { Notification } from "element-ui";
|
|
|
+import CryptoJS from "crypto-js";
|
|
|
|
|
|
+// console.log(btoa(CryptoJS.SHA1("pWWQ0qyaXL8QHni4ig9YiWYTKr8UVQd4")));
|
|
|
+// console.log(
|
|
|
+// CryptoJS.enc.Base64.stringify(
|
|
|
+// CryptoJS.SHA1("pWWQ0qyaXL8QHni4ig9YiWYTKr8UVQd4")
|
|
|
+// )
|
|
|
+// );
|
|
|
+//QpVbMSbQrMVCxQEKqks8+E34+W8=
|
|
|
// Full config: https://github.com/axios/axios#request-config
|
|
|
// axios.defaults.baseURL = process.env.BASE_URL || process.env.apiUrl || '';
|
|
|
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
@@ -23,33 +31,41 @@ const cacheGetUrls = [];
|
|
|
const _axiosApp = axios.create(config);
|
|
|
axiosRetry(_axiosApp);
|
|
|
|
|
|
-// function gToken(uri, token) {
|
|
|
-// const now = Date.now();
|
|
|
-// // console.log(`${uri}&${now}&${token}`);
|
|
|
-// const a = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
-// let randomStr = "";
|
|
|
-// for (let i = 0; i < 6; i++) {
|
|
|
-// const idx = Math.round(Math.random() * 100) % a.length;
|
|
|
-// randomStr += a[idx];
|
|
|
-// }
|
|
|
+function gToken(method, url, token, now) {
|
|
|
+ // const now = Date.now();
|
|
|
+ console.log(`${getSessionId()} ${method}&${url}&${now}&${token}`);
|
|
|
+ // const a = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
+ // let randomStr = "";
|
|
|
+ // for (let i = 0; i < 6; i++) {
|
|
|
+ // const idx = Math.round(Math.random() * 100) % a.length;
|
|
|
+ // randomStr += a[idx];
|
|
|
+ // }
|
|
|
|
|
|
-// const Authorization = `Token ${randomStr}${btoa(
|
|
|
-// uri + "&" + now + "&" + token
|
|
|
-// )}`;
|
|
|
+ const Authorization = `Token ${getSessionId()}:${CryptoJS.enc.Base64.stringify(
|
|
|
+ CryptoJS.SHA1("post&" + url + "&" + now + "&" + token)
|
|
|
+ )}`;
|
|
|
|
|
|
-// return Authorization;
|
|
|
-// }
|
|
|
+ return Authorization;
|
|
|
+}
|
|
|
|
|
|
_axiosApp.interceptors.request.use(
|
|
|
function (config) {
|
|
|
const wk_token = getToken();
|
|
|
+ const now = Date.now();
|
|
|
if (wk_token) {
|
|
|
- // config.headers.common["Authorization"] = gToken(config.url, wk_token);
|
|
|
- config.headers.common["Authorization"] = wk_token;
|
|
|
+ const completeURL = new URL("http://nasty.com" + config.url);
|
|
|
+ const path = completeURL.pathname;
|
|
|
+ config.headers.common["Authorization"] = gToken(
|
|
|
+ config.method,
|
|
|
+ path,
|
|
|
+ wk_token,
|
|
|
+ now
|
|
|
+ );
|
|
|
+ // config.headers.common["Authorization"] = wk_token;
|
|
|
}
|
|
|
config.headers.common["platform"] = PLATFORM;
|
|
|
config.headers.common["deviceId"] = DEVICE_ID;
|
|
|
- config.headers.common["time"] = Date.now();
|
|
|
+ config.headers.common["time"] = now;
|
|
|
return config;
|
|
|
},
|
|
|
function (error) {
|