解决token获取

This commit is contained in:
aixianling
2024-04-23 18:15:42 +08:00
parent f5c64d0800
commit c3ef37e184
2 changed files with 11 additions and 11 deletions

View File

@@ -7,6 +7,7 @@
*/
export const getSign = (token, appKey, formData) => {
console.log("获取到的token:%s", token)
token = token?.split("_")[0]
const t = (new Date()).getTime();
return {

View File

@@ -31,14 +31,12 @@ function getImageBlob(imageUrl) {
* @returns {{}}
*/
function cookie2Obj(cookieString) {
const cookieArray = cookieString.split('; ');
const cookieArray = cookieString.split(';');
const cookieObj = {};
for (let i = 0; i < cookieArray.length; i++) {
const [key, value] = cookieArray[i].split('=');
cookieObj[key] = value;
}
return cookieObj;
}
@@ -126,10 +124,10 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
});
}).then(sendResponse);
} else if (request.type == 'aliexpress') {
new Promise((resolve) => {
new Promise(async (resolve) => {
let headers = {};
headers['Content-Type'] = 'text/html';
headers.cookie = getAliexpressCookie(request.url);
headers.cookie = await getAliexpressCookie(request.url);
const {_m_h5_c, _m_h5_tk} = cookie2Obj(headers.cookie)
const {appKey, formData} = request
const {sign, t} = getSign(_m_h5_c || _m_h5_tk, appKey, formData)
@@ -252,14 +250,15 @@ function getSheinCookie() {
function getAliexpressCookie(link = "https://csp.aliexpress.com/") {
const url = new URL(link);
let cStr = '';
chrome.cookies.getAll({domain: url.host}, (cookie) => {
cookie.map((c) => {
cStr += c.name + '=' + c.value + ';';
return new Promise((resolve, reject) => {
chrome.cookies.getAll({url: link}, (cookie) => {
cookie.map((c) => {
cStr += c.name + '=' + c.value + ';';
});
resolve(cStr);
});
});
return cStr;
})
}
function formatParams(data) {