一、可自訂的資訊
二、使用方法
引入以下微信分享通用程式碼,呼叫 _WXShare() 即可:
/*******************************
* Author: Mr.Think
* Description: 微信分享通用代碼
* 使用方法:_WXShare('分享顯示的LOGO','LOGO寬度','LOGO高度','分享標題','分享描述','分享鏈接','微信APPID(一般不用填)');
*******************************/
function _WXShare(img, width, height, title, desc, url, appid) {
// 初始化參數
img = img || 'https://a.zhixun.in/plug/img/ico-share.png';
width = width || 100;
height = height || 100;
title = title || document.title;
desc = desc || document.title;
url = url || document.location.href;
appid = appid || '';
// 分享給好友
function _ShareFriend() {
WeixinJSBridge.invoke('sendAppMessage', {
'appid': appid,
'img_url': img,
'img_width': width,
'img_height': height,
'link': url,
'desc': desc,
'title': title
}, function(res){
_report('send_msg', res.err_msg);
})
}
// 分享到朋友圈
function _ShareTL() {
WeixinJSBridge.invoke('shareTimeline', {
'img_url': img,
'img_width': width,
'img_height': height,
'link': url,
'desc': desc,
'title': title
}, function(res) {
_report('timeline', res.err_msg);
});
}
// 分享到微博
function _ShareWB() {
WeixinJSBridge.invoke('shareWeibo', {
'content': desc,
'url': url
}, function(res) {
_report('weibo', res.err_msg);
});
}
// 微信內建瀏覽器初始化後會觸發 WeixinJSBridgeReady 事件
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
// 發送給好友
WeixinJSBridge.on('menu:share:appmessage', function(argv){
_ShareFriend();
});
// 分享到朋友圈
WeixinJSBridge.on('menu:share:timeline', function(argv){
_ShareTL();
});
// 分享到微博
WeixinJSBridge.on('menu:share:weibo', function(argv){
_ShareWB();
});
}, false);
}