页面分享功能,分享好友、朋友圈判断,用share_type做标记 这里用的是jweixin-1.3.2.js

这里用的是jweixin-1.3.2.js
trigger: function (res) {
//判断分享的状态,好友、朋友圈
localStorage.setItem("share_type",1);
}, //单独页面微信分享功能
var methods={
wxShare: function (shareImg, shareTitle, shareDesc, shareUrl,callBack,tipsCon) {
var url = window.location.href;
var wcConfig;
methods.ajax("/index.php/Wechat/GetJssdk/getJssdkConfig", {
url: url
}, function (res) {
wcConfig = res;
setConfig();
}); function setConfig() {
wx.config({
debug: false,
appId: wcConfig.data.appId,
timestamp: wcConfig.data.timestamp,
nonceStr: wcConfig.data.nonceStr,
signature: wcConfig.data.signature,
jsApiList: [
'onMenuShareQQ',
'uploadImage',
'chooseImage',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'startRecord',
'stopRecord',
'translateVoice',
'chooseCard',
'openCard',
'addCard'
]
});
var wxData = {
url: shareUrl ? location.protocol + "//" + location.host + shareUrl : url,
imgurl: location.protocol + "//" + location.host + (shareImg ? shareImg : "/shop-m/public/images/share_icon.jpg"),
title: shareTitle ? shareTitle : "默认标题",
desc: shareDesc ? shareDesc : "默认描述"
}
       //分享好友
var weixinShare = {
title: wxData.title,
desc: wxData.desc,
link: wxData.url,
imgUrl: wxData.imgurl,
type: '',
trigger: function (res) {
// console.log('用户点击发送给朋友');
localStorage.setItem("share_type",2); },
success: function(res) {
if(callBack){
if(tipsCon){
methods.confirm(tipsCon);
}else{
methods.prompt("分享成功"); }
callBack();
};
},
};
var qqShare = {
title: wxData.title,
desc: wxData.desc,
link: url,
imgUrl: wxData.imgurl, success: function() {
if(callBack){
if(tipsCon){
methods.confirm(tipsCon);
}else{
methods.prompt("分享成功");
}
callBack();
};
},
};
//分享朋友圈
var friendShare = {
title: wxData.title,
link: wxData.url,
imgUrl: wxData.imgurl,
trigger: function (res) {
console.log('用户点击分享到朋友圈');
localStorage.setItem("share_type",1);
},
success: function(res) {
if(callBack){
if(tipsCon){
methods.confirm(tipsCon);
}else{
methods.prompt("分享成功");
}
callBack();
};
},
};
wx.ready(function () {
wx.onMenuShareTimeline(friendShare);
wx.onMenuShareAppMessage(weixinShare);
wx.onMenuShareQQ(qqShare);
});
}
}
}    //调用方法
//微信分享,先判断是不是微信,设置分享内容shareImg, shareTitle, shareDesc, shareUrl,callBack分享成功后回调函数,tipsCon提示语
var userAgentInfo = navigator.userAgent.toLowerCase();
if (userAgentInfo.match(/MicroMessenger/i) == 'micromessenger') {
methods.wxShare("/shop-m/page/activity/2019-0520/images/share_icon.jpg",
"帮他助力",
"有你的助力会更有信心哦!",
"/shop-m/page/activity/2019-0720/buy-new-car/helpAssistance.html?fromOpenid="+fromOpenid+"&"+"fromUserid="+fromUserid,
function(){
console.log('分享成功')
})
}

  

上一篇:ASP调用SDK微信分享好友、朋友圈


下一篇:MongoDB之三(高级操作 聚合、游标)