优化方法

This commit is contained in:
aixianling
2024-04-23 14:02:12 +08:00
parent 845ceae3cd
commit 482391d6d3
2 changed files with 155 additions and 150 deletions

View File

@@ -1,14 +1,16 @@
/**
*
* @param token 从cookie中获取,判断从[_m_h5_c,_m_h5_tk]中取值,优先判断第一个
* @param appKey 取值 24815441或者12574478
* @param t 时间戳
* @param appKey 取值window.mtopConfig
* @param formData formData中的data
* @returns {*}
*/
export const getSign = (token, appKey = "12574478", t, formData) => {
return function (e) {
const getSign = (token, appKey, formData) => {
token = token.split("_")[0]
const t = (new Date()).getTime();
return {
t, sign: function (e) {
function t(e, t) {
return e << t | e >>> 32 - t
}
@@ -154,4 +156,5 @@ export const getSign = (token, appKey = "12574478", t, formData) => {
m = n(m, p);
return (s(f) + s(h) + s(g) + s(m)).toLowerCase()
}(token + "&" + t + "&" + appKey + "&" + formData)
}
}

View File

@@ -131,11 +131,13 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
headers['Content-Type'] = 'text/html';
headers.cookie = getAliexpressCookie();
const {_m_h5_c, _m_h5_tk} = cookie2Obj(headers.cookie)
const {appKey, t, formData} = request
const sign = getSign(_m_h5_c || _m_h5_tk, appKey, t, formData)
const {mtopConfig = {appKey: "12574478"}} = window
const {appKey = mtopConfig.appKey, formData} = request
const {sign, t} = getSign(_m_h5_c || _m_h5_tk, appKey, formData)
const url = new URL(request.url)
let params = new URLSearchParams(url.search);
params.append('sign', sign)
params.append('t', t)
url.search = params.toString()
Promise.resolve().then(() => fetch(url.toString(), {
'headers': headers, 'method': 'POST', 'referrerPolicy': 'no-referrer', 'credentials': 'include', 'mode': 'cors'