|
@@ -0,0 +1,100 @@
|
|
|
+function initShare(signature,openid){
|
|
|
+ var myloc = window.location.host;
|
|
|
+ var ors = "";
|
|
|
+ if("https:"==document.location.protocol){
|
|
|
+ ors = "s"
|
|
|
+ }
|
|
|
+ myloc="http"+ors+"://"+myloc;
|
|
|
+ if(typeof(signature) != "undefined" && signature != null && signature.length == 4){
|
|
|
+ wx.config({
|
|
|
+ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
|
+ appId: signature[0], // 必填,公众号的唯一标识
|
|
|
+ timestamp:signature[1], // 必填,生成签名的时间戳
|
|
|
+ nonceStr: signature[2], // 必填,生成签名的随机串
|
|
|
+ signature: signature[3],// 必填,签名,见附录1
|
|
|
+ jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage','onMenuShareQQ','onMenuShareQZone','closeWindow'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
|
|
|
+ });
|
|
|
+ var randShareTitle = "邀好友,免费获得超级订阅";
|
|
|
+
|
|
|
+ var link = myloc+"/front/followGift/"+openid;
|
|
|
+ var otherLink = link;
|
|
|
+ var desc = "分享有礼";
|
|
|
+ var otherDesc = desc;
|
|
|
+ var url = "/wxswordfish/images/small_log_new.jpg";
|
|
|
+ var encryptid = "";
|
|
|
+ var subhref = window.location.href;
|
|
|
+
|
|
|
+ wx.ready(function () {
|
|
|
+ var triggerFlag = false;
|
|
|
+ wx.onMenuShareTimeline({
|
|
|
+ title: randShareTitle, // 分享标题
|
|
|
+ link: otherLink, // 分享链接
|
|
|
+ imgUrl: myloc+'/wxswordfish/images/small_log_new.jpg', // 分享图标
|
|
|
+ trigger: function (res) {
|
|
|
+ try{
|
|
|
+ triggerFlag = true;
|
|
|
+ afterShareTimeline("trigger");
|
|
|
+ }catch(e){}
|
|
|
+ },
|
|
|
+ success: function () {
|
|
|
+ if(!triggerFlag){
|
|
|
+ try{
|
|
|
+ afterShareTimeline("success");
|
|
|
+ }catch(e){}
|
|
|
+ }
|
|
|
+ //alert('分享成功');
|
|
|
+ },
|
|
|
+ cancel: function () {
|
|
|
+ if(!triggerFlag){
|
|
|
+ try{
|
|
|
+ afterShareTimeline("cancel");
|
|
|
+ }catch(e){}
|
|
|
+ }
|
|
|
+ //alert('分享失败,或用户取消了');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ wx.onMenuShareAppMessage({
|
|
|
+ title: randShareTitle, // 分享标题
|
|
|
+ desc: desc, // 分享描述
|
|
|
+ link: link, // 分享链接
|
|
|
+ imgUrl: myloc+url, // 分享图标
|
|
|
+ type: 'link', // 分享类型,music、video或link,不填默认为link'
|
|
|
+ dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
|
|
|
+ success: function () {
|
|
|
+ //alert('分享成功');
|
|
|
+ },
|
|
|
+ cancel: function () {
|
|
|
+ //alert('分享失败,或用户取消了');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ wx.onMenuShareQQ({
|
|
|
+ title: randShareTitle, // 分享标题
|
|
|
+ desc: otherDesc, // 分享描述
|
|
|
+ link: otherLink, // 分享链接
|
|
|
+ imgUrl: myloc+url, // 分享图标
|
|
|
+ success: function () {
|
|
|
+ // 用户确认分享后执行的回调函数
|
|
|
+ },
|
|
|
+ cancel: function () {
|
|
|
+ // 用户取消分享后执行的回调函数
|
|
|
+ }
|
|
|
+ });
|
|
|
+ wx.onMenuShareQZone({
|
|
|
+ title: randShareTitle, // 分享标题
|
|
|
+ desc: otherDesc, // 分享描述
|
|
|
+ link: otherLink, // 分享链接
|
|
|
+ imgUrl: myloc+url, // 分享图标
|
|
|
+ success: function () {
|
|
|
+ // 用户确认分享后执行的回调函数
|
|
|
+ },
|
|
|
+ cancel: function () {
|
|
|
+ // 用户取消分享后执行的回调函数
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ wx.error(function(res){
|
|
|
+ // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
|
|
|
+ //alert("error auth");
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|