diff --git a/Scripts/authorization&cartId.js b/Scripts/authorization&cartId.js index da7f257..288b353 100644 --- a/Scripts/authorization&cartId.js +++ b/Scripts/authorization&cartId.js @@ -6,14 +6,34 @@ * - 把每次捕获追加到 cart_records 数组(cartId 去重) */ -const pattern = /^https:\/\/cart\.production\.store-web\.dynamics\.com\/v1\.0\/Cart\/eligibilityCheck\?/; -const url = $request.url; +const patterns = [ + /^https:\/\/cart\.production\.store-web\.dynamics\.com\/v1\.0\/cart\/eligibilityCheck\?/i, + /^https:\/\/cart\.production\.store-web\.dynamics\.com\/cart\/v1\.0\/cart\/eligibilityCheck\?/i, + /^https:\/\/cart\.production\.store-web\.dynamics\.com\/.*eligibilityCheck\?/i +]; + +const url = $request.url || ""; +const matched = patterns.some(p => p.test(url)); const MAX_RECORDS = 10; // cart 记录保留最近 10 条 -if ($request.method === "PUT" && pattern.test(url)) { +// 兼容不同平台 Header 大小写差异 +function getHeader(name) { + const headers = $request.headers || {}; + const target = name.toLowerCase(); + + for (const key in headers) { + if (key.toLowerCase() === target) { + return headers[key]; + } + } + + return undefined; +} + +if (($request.method || "").toUpperCase() === "PUT" && matched) { try { - const authorization = $request.headers['authorization']; + const authorization = getHeader('authorization'); const urlObj = new URL(url); const cartId = urlObj.searchParams.get('cartId'); const now = Date.now(); @@ -63,4 +83,4 @@ function appendCartRecord(entry) { console.log(`[cart] ✅ 已记录 cartId=${entry.cartId}, total=${records.length}`); } -$done({}); +$done({}); \ No newline at end of file