WeChat "Share to Moments" customizes the jssdk interface for sharing content. For some reason, the result is not the set title description and picture.
√The official account has been certified.
√The js safe domain name in the function settings is the same as the domain name of the opened page.
√debug: true When turned on, there is no problem with the configuration.
√checkJsApi also pops up the support interface.
but! ! ! The results turned out to be incompatible! The result is that the title description and image are not set.
Who knows? ?
code show as below:
var wechat_img={$wechat_share}[0];
var wechat_title={$wechat_share}[1];
var wechat_desc={$wechat_share}[2];
wx.config({
debug: true,
appId: {$signPackage}["appid"],
timestamp: {$signPackage}["timestamp"]+'',
nonceStr: {$signPackage}["nonceStr"],
signature: {$signPackage}["signature"],
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage'
]
});
wx.ready(function(){
wx.checkJsApi({
jsApiList: ['onMenuShareTimeline'], // 需要檢測(cè)的JS接口列表,所有JS接口列表見(jiàn)附錄2,
});
wx.onMenuShareTimeline({
title: wechat_tile, // 分享標(biāo)題
link: {$signPackage}["url"], // 分享鏈接
imgUrl: wechat_img, // 分享圖標(biāo)
success: function () {
alert('thanks for share');
},
cancel: function () {
// 用戶(hù)取消分享后執(zhí)行的回調(diào)函數(shù)
}
});
wx.onMenuShareAppMessage({
title: wechat_tile, // 分享標(biāo)題
desc: wechat_desc, // 分享描述
link: {$signPackage}["url"], // 分享鏈接
imgUrl: wechat_img, // 分享圖標(biāo)
type: '', // 分享類(lèi)型,music、video或link,不填默認(rèn)為link
dataUrl: '', // 如果type是music或video,則要提供數(shù)據(jù)鏈接,默認(rèn)為空
success: function () {
alert('thanks for share');
},
cancel: function () {
// 用戶(hù)取消分享后執(zhí)行的回調(diào)函數(shù)
}
});
});
##
The final solution to the problem is to use multiple different events to trigger wx.onMenuShareAppMessage.
Every imaginable event is used, windows.onoad, document.ontouchstart...
Is link also a safe domain name?
My situation was similar to yours before, that is, the link was not a secure domain name set by the official account.
First check if there is any problem with the waiting time
Directly adjust the share method in ready to see if it has any effect