function wxShare(e) { $.ajax({ url : '../wx/getSignature', type : 'get', data : { shareUrl : location.href }, success : function(data) { wxinit(data, e); } }); } function wxinit(data, e) { /* * 注意: 1. * 所有的JS接口只能在公众号绑定的域名下调用,公众号开发者需要先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”。 2. * 如果发现在 Android 不能分享自定义内容,请到官网下载最新的包覆盖安装,Android 自定义分享接口需升级至 6.0.2.58 * 版本及以上。 3. 完整 JS-SDK * 文档地址:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html * * 如有问题请通过以下渠道反馈: 邮箱地址:weixin-open@qq.com 邮件主题:【微信JS-SDK反馈】具体问题 * 邮件内容说明:用简明的语言描述问题所在,并交代清楚遇到该问题的场景,可附上截屏图片,微信团队会尽快处理你的反馈。 */ wx.config({ debug : false, appId : data.appId, timestamp : data.timestamp, nonceStr : data.nonceStr, signature : data.signature, jsApiList : [ 'checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo' ] }); wx.error(function(res) { // alert(JSON.stringify(res)); }); wx.ready(function() { // 1 判断当前版本是否支持指定 JS 接口,支持批量判断 wx.checkJsApi({ jsApiList : [ 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo' ], success : function(res) { // alert(JSON.stringify(res)); // 2. 分享接口 // 2.1 监听“分享给朋友”,按钮点击、自定义分享内容及分享结果接口 wx.onMenuShareAppMessage({ appId : data.appId, title : e.title, desc : e.desc, link : e.link, imgUrl : e.imgUrl, trigger : function(res) { // alert('用户点击发送给朋友'); }, success : function(res) { // alert('已分享'); $.ajax({ url : '../coupon/saveUserCoupon', type : 'post', data : { userId : e.userId, couponId : 21 }, success : function(data) { alert("优惠卷已领取"); } }); }, cancel : function(res) { // alert('已取消'); }, fail : function(res) { // alert(JSON.stringify(res)); } }); // 2.2 监听“分享到朋友圈”按钮点击、自定义分享内容及分享结果接口 wx.onMenuShareTimeline({ title : e.desc, desc : e.desc, link : e.link, imgUrl : e.imgUrl, trigger : function(res) { // alert('用户点击分享到朋友圈'); }, success : function(res) { // alert('已分享'); $.ajax({ url : '../coupon/saveUserCoupon', type : 'post', data : { userId : e.userId, couponId : 21 }, success : function(data) { alert("优惠卷已领取"); } }); }, cancel : function(res) { // alert('已取消'); }, fail : function(res) { // alert(JSON.stringify(res)); } }); // 2.3 监听“分享到QQ”按钮点击、自定义分享内容及分享结果接口 wx.onMenuShareQQ({ title : e.title, desc : e.desc, link : e.link, imgUrl : e.imgUrl, trigger : function(res) { // alert('用户点击分享到QQ'); }, complete : function(res) { // alert(JSON.stringify(res)); }, success : function(res) { // alert('已分享'); }, cancel : function(res) { // alert('已取消'); }, fail : function(res) { // alert(JSON.stringify(res)); } }); // 2.4 监听“分享到微博”按钮点击、自定义分享内容及分享结果接口 wx.onMenuShareWeibo({ title : e.title, desc : e.desc, link : e.link, imgUrl : e.imgUrl, trigger : function(res) { // alert('用户点击分享到微博'); }, complete : function(res) { // alert(JSON.stringify(res)); }, success : function(res) { // alert('已分享'); }, cancel : function(res) { // alert('已取消'); }, fail : function(res) { // alert(JSON.stringify(res)); } }); } }); }); }