兼容异常,并给出示例

This commit is contained in:
aixianling
2024-04-23 15:10:24 +08:00
parent 482391d6d3
commit 45f727ed7e
4 changed files with 20 additions and 8 deletions

View File

@@ -6,8 +6,8 @@
* @returns {*} * @returns {*}
*/ */
const getSign = (token, appKey, formData) => { export const getSign = (token, appKey, formData) => {
token = token.split("_")[0] token = token?.split("_")[0]
const t = (new Date()).getTime(); const t = (new Date()).getTime();
return { return {
t, sign: function (e) { t, sign: function (e) {
@@ -158,3 +158,4 @@ const getSign = (token, appKey, formData) => {
}(token + "&" + t + "&" + appKey + "&" + formData) }(token + "&" + t + "&" + appKey + "&" + formData)
} }
} }

View File

@@ -86,6 +86,8 @@ export function sendChromeNotification(message) {
*/ */
export function sendAliexpressAPIMessage(message) { export function sendAliexpressAPIMessage(message) {
message.type = 'aliexpress' message.type = 'aliexpress'
const {mtopConfig = {appKey: "12574478"}} = window
message.appKey = message.appKey || mtopConfig.appKey
return new Promise((resolve) => { return new Promise((resolve) => {
chrome.runtime.sendMessage(message, resolve) chrome.runtime.sendMessage(message, resolve)
}) })

View File

@@ -131,8 +131,7 @@ 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 {mtopConfig = {appKey: "12574478"}} = window const {appKey, formData} = request
const {appKey = mtopConfig.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)
const url = new URL(request.url) const url = new URL(request.url)
let params = new URLSearchParams(url.search); let params = new URLSearchParams(url.search);
@@ -253,7 +252,7 @@ function getSheinCookie() {
function getAliexpressCookie() { function getAliexpressCookie() {
const url = new URL("https://www.aliexpress.com/"); const url = new URL("https://csp.aliexpress.com/");
let cStr = ''; let cStr = '';
chrome.cookies.getAll({domain: url.host}, (cookie) => { chrome.cookies.getAll({domain: url.host}, (cookie) => {
cookie.map((c) => { cookie.map((c) => {

View File

@@ -69,8 +69,7 @@
<script> <script>
import AiCopyFromAliExpress from "@/components/AiCopyFromAliExpress.vue"; import AiCopyFromAliExpress from "@/components/AiCopyFromAliExpress.vue";
import {sendChromeAPIMessage} from '@/api/chromeApi' import {sendAliexpressAPIMessage} from '@/api/chromeApi'
import {getImageMd5} from "@/utils/image.js"
export default { export default {
name: 'NiubiCopy', name: 'NiubiCopy',
@@ -138,7 +137,7 @@ export default {
upload_sign: res4.result.signature upload_sign: res4.result.signature
} }
}))*/ }))*/
this.$http.post('/api/copyProduct/myPage', null, { this.$http.post('/api/copyProduct/myPage', null, {
params: { params: {
...this.search ...this.search
@@ -154,11 +153,22 @@ export default {
handleClose() { handleClose() {
this.copyFromDlgShow = false this.copyFromDlgShow = false
}, },
getAliexpressGoodsList() {
sendAliexpressAPIMessage({
type: "aliexpress",
url: "https://seller-acs.aliexpress.com/h5/mtop.global.merchant.self.product.manager.render.list/1.0/?jsv=2.7.2&appKey=30267743&v=1.0&timeout=15000&H5Request=true&url=mtop.global.merchant.self.product.manager.render.list&__channel-id__=701301&api=mtop.global.merchant.self.product.manager.render.list&type=originaljson&dataType=json&valueType=original&x-i18n-regionID=AE&data=%7B%22channelId%22%3A%22701301%22%2C%22jsonBody%22%3A%22%7B%5C%22tab%5C%22%3A%5C%22online_product%5C%22%2C%5C%22sort%5C%22%3A%7B%7D%2C%5C%22filter%5C%22%3A%7B%5C%22queryCategory%5C%22%3Anull%2C%5C%22lowerPrice%5C%22%3Anull%2C%5C%22upperPrice%5C%22%3Anull%2C%5C%22status%5C%22%3A%5C%220%5C%22%2C%5C%22productId%5C%22%3Anull%7D%2C%5C%22pagination%5C%22%3A%7B%5C%22pageSize%5C%22%3A10%2C%5C%22current%5C%22%3A2%7D%7D%22%2C%22from%22%3A%22SELF%22%2C%22bizParam%22%3A%22%7B%5C%22version%5C%22%3A%5C%22simple%5C%22%7D%22%7D"
}).then(res => {
console.log(res)
})
},
// 添加模板成功 // 添加模板成功
handleSuccess() { handleSuccess() {
this.copyFromDlgShow = false this.copyFromDlgShow = false
this.getList() this.getList()
} }
},
mounted() {
this.getAliexpressGoodsList()
} }
} }
</script> </script>