(function ($) { $.weixinShare = function (options) { var apiBaseUrl = "https://lee.cddfcb.com/"; var localUrl = encodeURIComponent(window.location.href); // 统计访问/分享次数 var defaults = { debug: false, title: "委屈", desc: "饿我去!", link: localUrl, imgUrl: "https://www.baidu.com/img/baidu_jgylogo3.gif", nocount: false, success: function () { syncUpdateCount(this.title,this.desc, "Share"); }, share_success:false, cancel: function () { // alert("用户取消分享!"); } }; // 参数合并 var opts = $.extend(defaults, options); if(opts.nocount==true){ }else{ //访问 } // 分享 $.getJSON(apiBaseUrl + "wechat_tokenheyi.php?&callback=?", {"url": encodeURIComponent(window.location.href)}, function (json) { if (json) { wx.config({ debug: opts.debug, appId: json.appId, timestamp: json.timestamp, nonceStr: json.nonceStr, signature: json.signature, jsApiList: new Array('onMenuShareTimeline', 'onMenuShareAppMessage','showMenuItems','hideMenuItems','hideAllNonBaseMenuItem','hideOptionMenu','startRecord','stopRecord','onVoiceRecordEnd','playVoice','pauseVoice','stopVoice','onVoicePlayEnd','uploadVoice','downloadVoice','chooseImage','previewImage','uploadImage','downloadImage','translateVoice','openLocation','getLocation') }); wx.ready(function () { // 分享给朋友 wx.onMenuShareAppMessage(opts); // 分享到QQ wx.onMenuShareQQ(opts); // 分享到腾讯微博 wx.onMenuShareWeibo(opts); // 分享到朋友圈 //var title = opts.title; //opts.title = opts.desc; var optsx = $.extend({},opts); optsx.success = optsx.share_success||optsx.success; wx.onMenuShareTimeline(optsx); }); } }); } })(jQuery);