/** * 鑫云东官网 · 微信 JS-SDK 自定义分享卡片 v20261120 * 与 v20261119 的差异: * 1) 缩略图改用 300×300 / 11KB(微信建议 ≤32KB) * 2) 同时调用新版 updateAppMessageShareData 与旧版 onMenuShareAppMessage * (部分安卓/鸿蒙微信只认旧接口) * 3) 额外监听菜单点击时机重新设置一次,避免设置过早被覆盖 */ (function () { 'use strict'; var SIG_URL = 'https://1505387801-2thvgkjuk3.ap-guangzhou.tencentscf.com'; var THUMB = 'https://www.xmydsp.com/assets/brand/share-thumb-300.jpg'; var UA = navigator.userAgent.toLowerCase(); if (UA.indexOf('micromessenger') === -1) return; function meta(name, fallback) { var m = document.querySelector('meta[property="' + name + '"],meta[name="' + name + '"]'); return (m && m.content && m.content.trim()) || fallback; } var url = location.href.split('#')[0]; var title = meta('og:title', '鑫云东 XINYUNDONG · 20年,只为做一根好爪'); var desc = meta('og:description', '厦门云东食品有限公司 · 中式卤泡休闲餐饮食品 · 招商热线 0592-2611672'); function applyShare() { var msg = { title: title, desc: desc, link: url, imgUrl: THUMB }; try { wx.updateAppMessageShareData(msg); } catch (e) {} try { wx.onMenuShareAppMessage({ title: title, desc: desc, link: url, imgUrl: THUMB }); } catch (e) {} try { wx.updateTimelineShareData({ title: title, link: url, imgUrl: THUMB }); } catch (e) {} try { wx.onMenuShareTimeline({ title: title, link: url, imgUrl: THUMB }); } catch (e) {} } fetch(SIG_URL + '?url=' + encodeURIComponent(url)) .then(function (r) { return r.json(); }) .then(function (d) { if (!d || !d.signature) return; var s = document.createElement('script'); s.src = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js'; s.onload = function () { wx.config({ debug: false, appId: d.appId, timestamp: d.timestamp, nonceStr: d.nonceStr, signature: d.signature, jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareAppMessage', 'onMenuShareTimeline'] }); wx.ready(function () { applyShare(); // 微信有时在 wx.ready 之后才真正挂载分享菜单,延迟再设置一次 setTimeout(applyShare, 1200); }); wx.error(function () { /* 保持默认卡片 */ }); }; document.head.appendChild(s); }) .catch(function () { /* 签名服务不可用时保持默认卡片 */ }); })();