首先,創建一個被分享出去的頁面。頁面中用script來設置被分享出去的內容
tilte:標題,desc:內容,imgUrl:圖片路徑,link:頁面路徑
微信接口配置
debug:調試模式,appId:公眾號的唯一標識,timestamp:生成簽名的時間戳,nonceStr:生產簽名的隨機串,signature:簽名
var shareData = {
title : '這個夏天讓大明星帶著寶貝去旅行',
desc : '樂可旅行x浙江少兒頻道大型旅行真人秀招募中!',
imgUrl : 'http://ww3.sinaimg.cn/mw690/86bf5c21gw1f4x9x8x0cuj205k05kwf2.jpg',
link : '<%=browserUrl%>' + '/index'
};
var wxConfig = {
appId : '<%=appId%>',
timestamp : '<%=timestamp%>',
nonceStr : '<%=nonceStr%>',
signature : '<%=signature%>'
}
最后通過設置base.js
wx.config({
debug: false,
appId: wxConfig.appId,
timestamp: wxConfig.timestamp,
nonceStr: wxConfig.nonceStr,
signature: wxConfig.signature,
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
// 'hideMenuItems',
'showMenuItems',
// 'hideAllNonBaseMenuItem',
'showAllNonBaseMenuItem',
'translateVoice',
'startRecord',
'stopRecord',
'onRecordEnd',
'playVoice',
'pauseVoice',
'stopVoice',
'uploadVoice',
'downloadVoice',
'chooseImage',
'previewImage',
'uploadImage',
'downloadImage',
'getNetworkType',
'openLocation',
'getLocation',
'hideOptionMenu',
'showOptionMenu',
'closeWindow',
'scanQRCode',
'chooseWXPay',
'openProductSpecificView',
'addCard',
'chooseCard',
'openCard'
]
});
//成功驗證之后,分享到朋友圈和好友
wx.ready(function() {
wx.onMenuShareAppMessage(shareData);
wx.onMenuShareTimeline(shareData);
wx.hideMenuItems({
menuList: ['menuItem:originPage', 'menuItem:openWithQQBrowser',
'menuItem:copyUrl', 'menuItem:openWithSafari'
],
});
});
wx.error(function(res) {
// alert(res.errMsg);
});