优化方法

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 token 从cookie中获取,判断从[_m_h5_c,_m_h5_tk]中取值,优先判断第一个
* @param appKey 取值 24815441或者12574478 * @param appKey 取值window.mtopConfig
* @param t 时间戳
* @param formData formData中的data * @param formData formData中的data
* @returns {*} * @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) { function t(e, t) {
return e << t | e >>> 32 - t return e << t | e >>> 32 - t
} }
@@ -155,3 +157,4 @@ export const getSign = (token, appKey = "12574478", t, formData) => {
return (s(f) + s(h) + s(g) + s(m)).toLowerCase() return (s(f) + s(h) + s(g) + s(m)).toLowerCase()
}(token + "&" + t + "&" + appKey + "&" + formData) }(token + "&" + t + "&" + appKey + "&" + formData)
} }
}

View File

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