解决token获取
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const getSign = (token, appKey, formData) => {
|
export const getSign = (token, appKey, formData) => {
|
||||||
|
console.log("获取到的token:%s", token)
|
||||||
token = token?.split("_")[0]
|
token = token?.split("_")[0]
|
||||||
const t = (new Date()).getTime();
|
const t = (new Date()).getTime();
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -31,14 +31,12 @@ function getImageBlob(imageUrl) {
|
|||||||
* @returns {{}}
|
* @returns {{}}
|
||||||
*/
|
*/
|
||||||
function cookie2Obj(cookieString) {
|
function cookie2Obj(cookieString) {
|
||||||
const cookieArray = cookieString.split('; ');
|
const cookieArray = cookieString.split(';');
|
||||||
const cookieObj = {};
|
const cookieObj = {};
|
||||||
|
|
||||||
for (let i = 0; i < cookieArray.length; i++) {
|
for (let i = 0; i < cookieArray.length; i++) {
|
||||||
const [key, value] = cookieArray[i].split('=');
|
const [key, value] = cookieArray[i].split('=');
|
||||||
cookieObj[key] = value;
|
cookieObj[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cookieObj;
|
return cookieObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,10 +124,10 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||||||
});
|
});
|
||||||
}).then(sendResponse);
|
}).then(sendResponse);
|
||||||
} else if (request.type == 'aliexpress') {
|
} else if (request.type == 'aliexpress') {
|
||||||
new Promise((resolve) => {
|
new Promise(async (resolve) => {
|
||||||
let headers = {};
|
let headers = {};
|
||||||
headers['Content-Type'] = 'text/html';
|
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 {_m_h5_c, _m_h5_tk} = cookie2Obj(headers.cookie)
|
||||||
const {appKey, formData} = request
|
const {appKey, formData} = request
|
||||||
const {sign, t} = getSign(_m_h5_c || _m_h5_tk, appKey, formData)
|
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/") {
|
function getAliexpressCookie(link = "https://csp.aliexpress.com/") {
|
||||||
const url = new URL(link);
|
|
||||||
let cStr = '';
|
let cStr = '';
|
||||||
chrome.cookies.getAll({domain: url.host}, (cookie) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
chrome.cookies.getAll({url: link}, (cookie) => {
|
||||||
cookie.map((c) => {
|
cookie.map((c) => {
|
||||||
cStr += c.name + '=' + c.value + ';';
|
cStr += c.name + '=' + c.value + ';';
|
||||||
});
|
});
|
||||||
|
resolve(cStr);
|
||||||
});
|
});
|
||||||
return cStr;
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatParams(data) {
|
function formatParams(data) {
|
||||||
|
|||||||
Reference in New Issue
Block a user