fix: 太阳码 scene 解析支持 &ch=渠道参数,identifier 用 split('&')[0] 分割
This commit is contained in:
@@ -119,9 +119,16 @@ export default {
|
|||||||
const sceneRaw = decodeURIComponent(option.scene || option.wxscene || '');
|
const sceneRaw = decodeURIComponent(option.scene || option.wxscene || '');
|
||||||
if (sceneRaw.indexOf('app=') === 0) {
|
if (sceneRaw.indexOf('app=') === 0) {
|
||||||
console.log('[DEBUG 太阳码] ✅ scene 匹配成功! 原始:', option.scene, '解码:', sceneRaw);
|
console.log('[DEBUG 太阳码] ✅ scene 匹配成功! 原始:', option.scene, '解码:', sceneRaw);
|
||||||
|
// scene 格式: "app=pregnancy" 或 "app=pregnancy&ch=YFMM"
|
||||||
const source = sceneRaw;
|
const source = sceneRaw;
|
||||||
const identifier = source.slice(4);
|
const identifier = source.slice(4).split('&')[0];
|
||||||
console.log('[web_view] 太阳码 scene 解析: identifier=' + identifier);
|
// 提取渠道码
|
||||||
|
let channel = '';
|
||||||
|
const chMatch = source.match(/&ch=([A-Z]+)/);
|
||||||
|
if (chMatch) channel = chMatch[1];
|
||||||
|
console.log('[web_view] 太阳码 scene 解析: identifier=' + identifier + (channel ? ' ch=' + channel : ''));
|
||||||
|
// 把 channel 存到 option 中传给 _resolveAppScene
|
||||||
|
option._channel = channel;
|
||||||
// 异步处理:uni.request 拿 H5 url,赋值给 option.url 走后续逻辑
|
// 异步处理:uni.request 拿 H5 url,赋值给 option.url 走后续逻辑
|
||||||
this._resolveAppScene(identifier, option);
|
this._resolveAppScene(identifier, option);
|
||||||
return;
|
return;
|
||||||
@@ -149,43 +156,43 @@ export default {
|
|||||||
/**
|
/**
|
||||||
* 太阳码 scene 解析:调 box_app /api/mp/apps 找 url,找到后注入到 option.url
|
* 太阳码 scene 解析:调 box_app /api/mp/apps 找 url,找到后注入到 option.url
|
||||||
* 然后调用 _initWebView(option) 走标准 web_view 加载流程
|
* 然后调用 _initWebView(option) 走标准 web_view 加载流程
|
||||||
*/
|
_resolveAppScene(identifier, option) {
|
||||||
_resolveAppScene(identifier, option) {
|
const appToken = store.state.app.token || '';
|
||||||
const appToken = store.state.app.token || '';
|
uni.request({
|
||||||
uni.request({
|
url: 'https://mp.yizhezhe.com/api/mp/apps?identifier=' + encodeURIComponent(identifier) + '&isPublished=1&pageSize=1',
|
||||||
url: 'https://mp.yizhezhe.com/api/mp/apps?identifier=' + encodeURIComponent(identifier) + '&isPublished=1&pageSize=1',
|
method: 'GET',
|
||||||
method: 'GET',
|
header: appToken ? { 'Authorization': 'Bearer ' + appToken } : {},
|
||||||
header: appToken ? { 'Authorization': 'Bearer ' + appToken } : {},
|
success: (res) => {
|
||||||
success: (res) => {
|
console.log('[web_view] 太阳码 scene 解析响应:', JSON.stringify(res.statusCode));
|
||||||
console.log('[web_view] 太阳码 scene 解析响应:', JSON.stringify(res.statusCode));
|
const items = res.data && res.data.result && res.data.result.items;
|
||||||
const items = res.data && res.data.result && res.data.result.items;
|
if (res.statusCode === 200 && items && items.length > 0) {
|
||||||
if (res.statusCode === 200 && items && items.length > 0) {
|
const app = items.find(it => it.identifier === identifier) || items[0];
|
||||||
// box_app /api/mp/apps 当前不支持 identifier 过滤,遍历找
|
if (app && app.url) {
|
||||||
const app = items.find(it => it.identifier === identifier) || items[0];
|
const appUrl = app.url;
|
||||||
if (app && app.url) {
|
let finalUrl = appUrl;
|
||||||
const appUrl = app.url;
|
if (option._channel) {
|
||||||
console.log('[web_view] 解析到 H5 url:', appUrl);
|
const separator = finalUrl.includes('?') ? '&' : '?';
|
||||||
// 编码到 option.url,复用标准流程
|
finalUrl += separator + 'ch=' + option._channel;
|
||||||
option.url = encodeURIComponent(appUrl);
|
}
|
||||||
} else {
|
console.log('[web_view] 解析到 H5 url:', appUrl, option._channel ? ' ch=' + option._channel : '');
|
||||||
// 解析失败:降级到 CRMEB 首页
|
option.url = encodeURIComponent(finalUrl);
|
||||||
console.warn('[DEBUG 太阳码] 降级到 CRMEB 首页');
|
} else {
|
||||||
option.url = encodeURIComponent('https://shop.douba.top');
|
console.warn('[DEBUG 太阳码] 降级到 CRMEB 首页');
|
||||||
}
|
option.url = encodeURIComponent('https://shop.douba.top');
|
||||||
} else {
|
}
|
||||||
// 响应异常:降级到 CRMEB 首页
|
} else {
|
||||||
console.warn('[web_view] 太阳码 scene 解析响应异常,降级到 CRMEB 首页');
|
console.warn('[web_view] 太阳码 scene 解析响应异常,降级到 CRMEB 首页');
|
||||||
option.url = encodeURIComponent('https://shop.douba.top');
|
option.url = encodeURIComponent('https://shop.douba.top');
|
||||||
}
|
}
|
||||||
this._initWebView(option);
|
this._initWebView(option);
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
console.error('[web_view] 太阳码 scene 网络请求失败:', err);
|
console.error('[web_view] 太阳码 scene 网络请求失败:', err);
|
||||||
option.url = encodeURIComponent('https://shop.douba.top');
|
option.url = encodeURIComponent('https://shop.douba.top');
|
||||||
this._initWebView(option);
|
this._initWebView(option);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_initWebView(option) {
|
_initWebView(option) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user