|
|
@@ -1869,6 +1869,87 @@
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 调试 querySecondGoodsDetailWithOutJWT:微信内异步 alert 常被拦截,用页面弹层兜底。
|
|
|
+ * URL 加 apiDebug=0 可关闭。
|
|
|
+ */
|
|
|
+ function isSecondGoodsApiDebugOn() {
|
|
|
+ if (q('apiDebug') === '0') return false;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ function showSecondGoodsDetailDebugPanel(title, payload, onClose) {
|
|
|
+ if (!isSecondGoodsApiDebugOn()) {
|
|
|
+ if (typeof onClose === 'function') onClose();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var text;
|
|
|
+ try {
|
|
|
+ text =
|
|
|
+ typeof payload === 'string'
|
|
|
+ ? payload
|
|
|
+ : JSON.stringify(payload, null, 2);
|
|
|
+ } catch (serErr) {
|
|
|
+ text = String(payload);
|
|
|
+ }
|
|
|
+ if (text.length > 16000) {
|
|
|
+ text = text.slice(0, 16000) + '\n…(已截断)';
|
|
|
+ }
|
|
|
+
|
|
|
+ var old = document.getElementById('secondGoodsApiDebug');
|
|
|
+ if (old) old.remove();
|
|
|
+
|
|
|
+ var wrap = document.createElement('div');
|
|
|
+ wrap.id = 'secondGoodsApiDebug';
|
|
|
+ wrap.setAttribute('role', 'dialog');
|
|
|
+ wrap.style.cssText =
|
|
|
+ 'position:fixed;inset:0;z-index:99999;background:rgba(0,0,0,.72);' +
|
|
|
+ 'padding:10px;box-sizing:border-box;display:flex;align-items:center;justify-content:center;';
|
|
|
+
|
|
|
+ var card = document.createElement('div');
|
|
|
+ card.style.cssText =
|
|
|
+ 'background:#fff;border-radius:10px;width:100%;max-width:520px;max-height:88vh;' +
|
|
|
+ 'display:flex;flex-direction:column;overflow:hidden;';
|
|
|
+
|
|
|
+ var head = document.createElement('div');
|
|
|
+ head.style.cssText =
|
|
|
+ 'padding:10px 12px;font-size:14px;font-weight:700;border-bottom:1px solid #eee;';
|
|
|
+ head.textContent = title;
|
|
|
+
|
|
|
+ var pre = document.createElement('pre');
|
|
|
+ pre.style.cssText =
|
|
|
+ 'margin:0;padding:10px 12px;overflow:auto;font-size:11px;line-height:1.45;' +
|
|
|
+ 'flex:1;white-space:pre-wrap;word-break:break-all;';
|
|
|
+ pre.textContent = text;
|
|
|
+
|
|
|
+ var btn = document.createElement('button');
|
|
|
+ btn.type = 'button';
|
|
|
+ btn.textContent = '关闭';
|
|
|
+ btn.style.cssText =
|
|
|
+ 'margin:10px 12px 12px;padding:10px;border:0;border-radius:6px;' +
|
|
|
+ 'background:#F47D1F;color:#fff;font-size:15px;';
|
|
|
+ btn.onclick = function () {
|
|
|
+ wrap.remove();
|
|
|
+ if (typeof onClose === 'function') onClose();
|
|
|
+ };
|
|
|
+
|
|
|
+ card.appendChild(head);
|
|
|
+ card.appendChild(pre);
|
|
|
+ card.appendChild(btn);
|
|
|
+ wrap.appendChild(card);
|
|
|
+ document.body.appendChild(wrap);
|
|
|
+
|
|
|
+ console.log('[querySecondGoodsDetailWithOutJWT]', title, payload);
|
|
|
+
|
|
|
+ setTimeout(function () {
|
|
|
+ try {
|
|
|
+ window.alert(title + '\n(详情见页面白色弹层,点「关闭」继续)');
|
|
|
+ } catch (alertErr) {
|
|
|
+ showFabToast(title, 4000);
|
|
|
+ }
|
|
|
+ }, 80);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 仅用 querySecondGoodsDetailWithOutJWT 判断商品是否存在,不渲染接口返回的详情字段
|
|
|
* @returns {Promise<{redirected:boolean, exists:boolean}>}
|
|
|
*/
|
|
|
@@ -1913,28 +1994,23 @@
|
|
|
body: formStr
|
|
|
})
|
|
|
.then(function (res) {
|
|
|
- if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
|
+ if (!res.ok) {
|
|
|
+ var err = new Error('HTTP ' + res.status);
|
|
|
+ err.httpStatus = res.status;
|
|
|
+ err.requestUrl = detailUrl;
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
return res.json();
|
|
|
})
|
|
|
.then(function (res) {
|
|
|
- try {
|
|
|
- var alertText = JSON.stringify(res, null, 2);
|
|
|
- if (alertText.length > 3500) {
|
|
|
- alertText =
|
|
|
- alertText.slice(0, 3500) + '\n…(已截断,完整见控制台)';
|
|
|
- }
|
|
|
- window.alert(
|
|
|
- 'querySecondGoodsDetailWithOutJWT 返回:\n' + alertText
|
|
|
- );
|
|
|
- console.log('[querySecondGoodsDetailWithOutJWT]', res);
|
|
|
- } catch (alertErr) {
|
|
|
- window.alert(
|
|
|
- 'querySecondGoodsDetailWithOutJWT 返回(无法序列化,见控制台)'
|
|
|
- );
|
|
|
- console.log('[querySecondGoodsDetailWithOutJWT]', res, alertErr);
|
|
|
- }
|
|
|
redirectCtx = redirectCtx || {};
|
|
|
var d = pickSecondGoodsDetailData(res);
|
|
|
+ var debugPayload = {
|
|
|
+ requestUrl: detailUrl,
|
|
|
+ requestBody: formBody,
|
|
|
+ response: res
|
|
|
+ };
|
|
|
+
|
|
|
if (isDetailResponseGoodsUnavailable(res)) {
|
|
|
console.warn(
|
|
|
'[querySecondGoodsDetailWithOutJWT] unavailable',
|
|
|
@@ -1942,10 +2018,41 @@
|
|
|
res && res.msg,
|
|
|
d
|
|
|
);
|
|
|
- redirectToShareUndefined(null, redirectCtx);
|
|
|
- return { redirected: true, exists: false };
|
|
|
+ return new Promise(function (resolve) {
|
|
|
+ showSecondGoodsDetailDebugPanel(
|
|
|
+ 'querySecondGoodsDetailWithOutJWT(将跳转不可用页)',
|
|
|
+ debugPayload,
|
|
|
+ function () {
|
|
|
+ redirectToShareUndefined(null, redirectCtx);
|
|
|
+ resolve({ redirected: true, exists: false });
|
|
|
+ }
|
|
|
+ );
|
|
|
+ });
|
|
|
}
|
|
|
+
|
|
|
+ showSecondGoodsDetailDebugPanel(
|
|
|
+ 'querySecondGoodsDetailWithOutJWT 返回',
|
|
|
+ debugPayload
|
|
|
+ );
|
|
|
return { redirected: false, exists: true };
|
|
|
+ })
|
|
|
+ .catch(function (e) {
|
|
|
+ showSecondGoodsDetailDebugPanel(
|
|
|
+ 'querySecondGoodsDetailWithOutJWT 请求失败',
|
|
|
+ {
|
|
|
+ message: e && e.message ? e.message : String(e),
|
|
|
+ requestUrl: detailUrl,
|
|
|
+ requestBody: formBody,
|
|
|
+ pageProtocol: location.protocol,
|
|
|
+ apiBaseSecond: API_BASE_SECOND,
|
|
|
+ hint:
|
|
|
+ location.protocol === 'https:' &&
|
|
|
+ /^http:\/\//i.test(String(API_BASE_SECOND))
|
|
|
+ ? 'HTTPS 页面请求 HTTP 接口可能被 iOS/微信拦截(混合内容)'
|
|
|
+ : ''
|
|
|
+ }
|
|
|
+ );
|
|
|
+ throw e;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -2006,6 +2113,14 @@
|
|
|
}
|
|
|
|
|
|
if (!goodsId) {
|
|
|
+ showSecondGoodsDetailDebugPanel(
|
|
|
+ '未调用 querySecondGoodsDetailWithOutJWT',
|
|
|
+ {
|
|
|
+ reason: 'URL 缺少 goodsId / id / sourceId',
|
|
|
+ search: location.search,
|
|
|
+ hash: location.hash
|
|
|
+ }
|
|
|
+ );
|
|
|
applyFromUrl();
|
|
|
return;
|
|
|
}
|