微信分享,QQ分享,微博分享

// 分享

var _title, _source, _sourceUrl, _pic, _showcount, _desc, _summary, _site,n,j,

_width = 600,

_height = 600,

_top = (screen.height - _height) / 2,

_left = (screen.width - _width) / 2,

_url =  window.location.href.split('#')[0];

// _url =_url.replace('index', 'register');

n = _url.indexOf('refferedId=');

j = _url.substring(n + 11, n + 22);

if(!!JSON.parse(localStorage.getItem("userObj"))) {

_url = _url.replace(j, JSON.parse(localStorage.getItem("userObj")).nickName);

}

// console.log(_url)

_pic = 'https://image.miazhu.com/ke/20190604/20104015_643.png';

_desc = "友福同享,免费ETC+电影票+话费,给你,都给你!";

_summary =

"七夕马上就到了,给你一个约TA看电影的机会,还不抓紧?";

// 微信

$(function() {

var o = _url.indexOf('keywords=');

p = _url.substring(o + 9, _url.indexOf('&'));

_url = _url.replace(p, 'weixin');

$.ajax({

type: "POST",

//              url: baseUrl + "/getShareConfig",

url: baseUrl + "/getShareConfig",

data: {

"url": _url

},

dataType: "json",

success: function(res) {

// console.log(res);

wx.config({

debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。

appId: res.appId, // 必填,公众号的唯一标识

timestamp: res.timestamp, // 必填,生成签名的时间戳

nonceStr: res.nonceStr, // 必填,生成签名的随机串

signature: res.signature, // 必填,签名

jsApiList: [

"updateAppMessageShareData", "updateTimelineShareData"

] // 必填,需要使用的JS接口列表

})

}

})

var wx_url = _url+'&wx=1';

wx.ready(function() { //需在用户可能点击分享按钮前就先调用

wx.updateAppMessageShareData({

title: _title || document.title, // 分享标题

desc: _desc || '分享的描述', // 分享描述

link: wx_url || document.location, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致

imgUrl: _pic || '', // 分享图标

success: function() {

// 设置成功

// alert("设置成功")

}

});

wx.updateTimelineShareData({

title: _title || document.title, // 分享标题

link: wx_url || document.location, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致

imgUrl: _pic || '', // 分享图标

success: function() {

// 设置成功

// alert("设置成功")

}

})

});

})

function toAPP(scheme) {

var iosA = document.createElement("a");

iosA.setAttribute("href", scheme);

var body = document.body;

body.appendChild(iosA);

iosA.click();

}

function shareWeixin(event) {

var browser = {

versions: function() {

var u = navigator.userAgent,

app = navigator.appVersion;

return { //移动终端浏览器版本信息

trident: u.indexOf('Trident') > -1, //IE内核

presto: u.indexOf('Presto') > -1, //opera内核

webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核

gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核

mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端

ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端

android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器

iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器

iPad: u.indexOf('iPad') > -1, //是否iPad

webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部

};

}()

}

if(browser.versions.mobile) { //判断是否是移动设备打开

var ua = navigator.userAgent.toLowerCase(); //获取判断用的对象

/**

* 是否是 UC 浏览器

*/

var uc = UA.split('UCBrowser/').length > 1 ? 1 : 0;

/**

* 判断 qq 浏览器

* 然而qq浏览器分高低版本

* 2 代表高版本

* 1 代表低版本

*/

var qq = UA.split('MQQBrowser/').length > 1 ? 2 : 0;

if(ua.match(/MicroMessenger/i) == "micromessenger") {

//在微信中打开

$(".boxBottom").click();

$(".fx").show();

setTimeout(function(){

$(".fx").hide();

},3000)

// toastFn(1500, "点击右上角-更多-分享给好友~");

return;

} else {

var mshare = new mShare({

title: _title || document.title, // 分享标题

desc: _desc || '分享的描述', // 分享描述

url: _url || document.location, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致

img: _pic || '', // 分享图标

});

// 1 ==> 朋友圈  2 ==> 朋友  0 ==> 直接弹出原生

mshare.init($(this).data('mshare'));

if(uc || qq) {

return false;

}

}

} else {

// alert("PC");

}

toastFn(2000, "请使用浏览器的分享功能,分享给更多的人吧~")

// toAPP("weixin://")

}

function shareWeixinP(event) {

var uc = UA.split('UCBrowser/').length > 1 ? 1 : 0;

/**

* 判断 qq 浏览器

* 然而qq浏览器分高低版本

* 2 代表高版本

* 1 代表低版本

*/

var qq = UA.split('MQQBrowser/').length > 1 ? 2 : 0;

var browser = {

versions: function() {

var u = navigator.userAgent,

app = navigator.appVersion;

return { //移动终端浏览器版本信息

trident: u.indexOf('Trident') > -1, //IE内核

presto: u.indexOf('Presto') > -1, //opera内核

webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核

gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核

mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端

ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端

android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器

iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器

iPad: u.indexOf('iPad') > -1, //是否iPad

webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部

};

}()

}

if(browser.versions.mobile) { //判断是否是移动设备打开

var ua = navigator.userAgent.toLowerCase(); //获取判断用的对象

if(ua.match(/MicroMessenger/i) == "micromessenger") {

//在微信中打开

$(".boxBottom").click();

$(".fx").show();

setTimeout(function(){

$(".fx").hide();

},3000)

// toastFn(1500, "点击右上角-更多-分享到朋友圈~");

return;

} else {

var mshare = new mShare({

title: _title || document.title, // 分享标题

desc: _desc || '分享的描述', // 分享描述

url: _url || document.location, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致

img: _pic || '', // 分享图标

});

// 1 ==> 朋友圈  2 ==> 朋友  0 ==> 直接弹出原生

mshare.init($(this).data('mshare'));

if(uc || qq) {

return false;

}

}

} else {

// alert("PC");

}

toastFn(2000, "请使用浏览器的分享功能,分享给更多的人吧~")

// toAPP("weixin://")

}

function shareQQ(event) {

var uc = UA.split('UCBrowser/').length > 1 ? 1 : 0;

/**

* 判断 qq 浏览器

* 然而qq浏览器分高低版本

* 2 代表高版本

* 1 代表低版本

*/

var qq = UA.split('MQQBrowser/').length > 1 ? 2 : 0;

var mshare = new mShare({

title: _title || document.title, // 分享标题

desc: _desc || '分享的描述', // 分享描述

url: _url || document.location, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致

img: _pic || '', // 分享图标

});

// 1 ==> 朋友圈  2 ==> 朋友  0 ==> 直接弹出原生

mshare.init($(this).data('mshare'));

if(uc || qq) {

return false;

}

var oo = _url.indexOf('keywords=');

pp = _url.substring(oo + 9, _url.indexOf('&'));

_url = _url.replace(pp, 'qq');

event.preventDefault();

var _shareUrl = 'http://connect.qq.com/widget/shareqq/iframe_index.html?'; // QQ好友

// var _shareUrl = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?'; // QQ空间

_shareUrl += 'url=' + encodeURIComponent(_url || document

.location); //参数url设置分享的内容链接|默认当前页location

_shareUrl += '&showcount=' + _showcount || 0; //参数showcount是否显示分享总数,显示:'1',不显示:'0',默认不显示

_shareUrl += '&desc=' + encodeURIComponent(_desc || '分享的描述'); //参数desc设置分享的描述,可选参数

_shareUrl += '&summary=' + encodeURIComponent(_summary || '分享摘要'); //参数summary设置分享摘要,可选参数

_shareUrl += '&title=' + encodeURIComponent(_title || document.title); //参数title设置分享标题,可选参数

_shareUrl += '&site=' + encodeURIComponent(_site || ''); //参数site设置分享来源,可选参数

_shareUrl += '&pics=' + encodeURIComponent(_pic || ''); //参数pics设置分享图片的路径,多张图片以"|"隔开,可选参数

window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',top=' + _top +

',left=' + _left +

',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');

};

// 新浪

function shareXinLang(event) {

_url =_url.replace('index', 'register');

var ooo = _url.indexOf('keywords=');

ppp = _url.substring(ooo + 9, _url.indexOf('&'));

_url = _url.replace(ppp, 'weibo');

//      var param = {

//              url: _url || window.location.href,

//              type: '3',

//              count: '1', /** 是否显示分享数,1显示(可选)*/

//              appkey: '', /** 您申请的应用appkey,显示分享来源(可选)*/

//              title: _desc, /** 分享的文字内容(可选,默认为所在页面的title)*/

//              pic: _pic || '', /**分享图片的路径(可选)*/

//              ralateUid:'', /**关联用户的UID,分享微博会@该用户(可选)*/

//              rnd: new Date().valueOf()

//          }

//          var temp = [];

//          for( var p in param ) {

//              temp.push(p + '=' +encodeURIComponent( param[p ] || '' ) )

//          }

//          var targetUrl = 'http://service.weibo.com/share/share.php?' + temp.join('&');

//          window.open(targetUrl, 'sinaweibo', 'height='+_height+', width=400'+_width);

//         

console.log(_url)

event.preventDefault();

var _shareUrl = 'http://service.weibo.com/share/share.php?'; // QQ好友

// var _shareUrl = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?'; // QQ空间

_shareUrl += 'url=' + encodeURIComponent(_url || document

.location); //参数url设置分享的内容链接|默认当前页location

_shareUrl += '&showcount=' + _showcount || 0; //参数showcount是否显示分享总数,显示:'1',不显示:'0',默认不显示

_shareUrl += '&desc=' + encodeURIComponent(_desc || '分享的描述'); //参数desc设置分享的描述,可选参数

_shareUrl += '&summary=' + encodeURIComponent(_summary || '分享摘要'); //参数summary设置分享摘要,可选参数

_shareUrl += '&title=' + encodeURIComponent(_title || document.title); //参数title设置分享标题,可选参数

_shareUrl += '&site=' + encodeURIComponent(_site || ''); //参数site设置分享来源,可选参数

_shareUrl += '&pics=' + encodeURIComponent(_pic || ''); //参数pics设置分享图片的路径,多张图片以"|"隔开,可选参数

window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',top=' + _top +

',left=' + _left +

',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');

}

你可能感兴趣的:(微信分享,QQ分享,微博分享)