微信分享介面修改文案方法
1.引入相關檔案
<script type="tet/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
2.微信分享方法封裝:
/**
微信分享
*/
var wxShare = (function (w) {
var webApiHost = "";
var shareData = { title: '', desc: '', img: '', link: '' };
function wxJSTools() {
}
/**
配置酒名片微信分享介面(需要傳入自定義標題等資訊)
*/
wxJSTools.prototype.configJMPShare = function (apiHost, title, desc, img, link) {
var _this_ = this;
webApiHost = apiHost;
shareData.title = title;
shareData.desc = desc;
shareData.img = img;
if (!link) {
shareData.link = 'http://m.ganjiuhui.com';
}
else {
shareData.link = link.indexOf("http:") >= 0 ? link : ('http://m.ganjiuhui.com' + link);
}
_this_.configWxJSSDK();
}
/**
配置微信JSSDK
*/
wxJSTools.prototype.configWxJSSDK = function () {
if (!wx)
{ return; }
$.get(webApiHost + "/api/weixin/jssignature", { url: w.location.href }, function (ret) {
if (ret && ret.IsSucceed) {
wx.config({
debug: false, // 開啟除錯模式,呼叫的所有api的返回值會在客戶端alert出來,若要檢視傳入的引數,可以在pc端開啟,引數資訊會通過log打出,僅在pc端時才會列印。
appId: ret.Data.AppId, // 必填,公眾號的唯一標識
timestamp: ret.Data.Timestamp, // 必填,生成簽名的時間戳
nonceStr: ret.Data.NonceStr, // 必填,生成簽名的隨機串
signature: ret.Data.Signature,// 必填,簽名,見附錄1
// 必填,需要使用的JS介面列表,所有JS介面列表見附錄2
jsApiList: [
"onMenuShareTimeline", //朋友圈
"onMenuShareAppMessage", //好友
"onMenuShareQQ", //QQ
"onMenuShareQZone" //QQ空間
]
});
wx.ready(function () {
wx.onMenuShareTimeline({
title: shareData.title,
link: shareData.link,
imgUrl: shareData.img,
success: function (res) { },
cancel: function (res) { }
});
wx.onMenuShareAppMessage({
title: shareData.title,
desc: shareData.desc,
link: shareData.link,
imgUrl: shareData.img,
success: function (res) { },
cancel: function (res) { }
});
wx.onMenuShareQQ({
title: shareData.title,
desc: shareData.desc,
link: shareData.link,
imgUrl: shareData.img,
success: function (res) { },
cancel: function (res) { }
});
wx.onMenuShareQZone({
title: shareData.title,
desc: shareData.desc,
link: shareData.link,
imgUrl: shareData.img,
success: function (res) { },
cancel: function (res) { }
});
});
}
});
}
return new wxJSTools();
})(window);
3.直接呼叫方法,傳入引數即可;
wxShare.configJMPShare(APIHost, 標題,文案描素,img,分享地址);