很奇怪的问题,H5链接,通过微信转发分享后,ios手机不显示卡片效果。android显示正常。
wx.config函数的debug=ture后,android显示success,ios弹出fail。
效果如下:
查了很多资料也无法解决。求助技术大佬!
基础配置如下:
1)微信服务号后台JS安全域配置OK
2),域名h5.daottec.cn支持SSL协议。
代码如下:
//weixin-js-sdk 版本1.6.0,打包放在本地,非远程访问
import config from '@/config';
import { useUserStore } from '@/store/user';
import { get } from '@/utils/request';
import wx from 'weixin-js-sdk';
const { HOST } = config;
const userStore = useUserStore();
export { wx };
//服务器接口,获取config签名相关参数
export const getWXConfigData = () => {
return get(`/v1/wxaapi/config`, {
url: location.href,
});
};
//jsApiList = ["onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ","onMenuShareWeibo", "onMenuShareQZone", "chooseWXPay"];
export const WXConfig = async (jsApiList: Array<string>) => {
const { WX_APPID } = userStore.getOrgConfig;
const { data: wxconfigData } = await getWXConfigData();
wx.config({
debug: false,
appId: WX_APPID,
...wxconfigData,
jsApiList,
});
};
export const WXConfigReady = async (jsApiList: Array<string>, action: Function) => {
await WXConfig(jsApiList);
wx.ready(action);
};
export const WXShareConfigReady = async ({
title,
desc,
link,
imgUrl,
}: {
title: string;
desc?: string;
link?: string;
imgUrl: string;
}) => {
if (link && !link.startsWith(HOST)) {
link = HOST + link;
}
await WXConfigReady(
[
'updateAppMessageShareData',
'updateTimelineShareData',
'onMenuShareAppMessage',
'onMenuShareTimeline',
'onMenuShareQQ',
'chooseWXPay',
],
() => {
console.log('updateAppMessageShareData', title, desc, link, imgUrl);
if (wx.updateAppMessageShareData) {
updateAppMessageShareData({
title,
desc,
link,
imgUrl,
success: () => {
console.log('updateAppMessageShareData...');
},
});
updateTimelineShareData({
title,
link,
imgUrl,
success: () => {
console.log('updateTimelineShareData...');
},
});
} else {
onMenuShareAppMessage({
title,
desc,
link,
imgUrl,
success: () => {
console.log('onMenuShareAppMessage...');
},
});
onMenuShareTimeline({
title,
link,
imgUrl,
success: () => {
console.log('onMenuShareTimeline...');
},
});
onMenuShareQQ({
title,
desc,
link,
imgUrl,
success: () => {
console.log('onMenuShareQQ...');
},
});
}
},
);
};