微信页面的分享,设置分享信息以及监听分享
Posted 听风且雨
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微信页面的分享,设置分享信息以及监听分享相关的知识,希望对你有一定的参考价值。
js端
<script src=http://res.wx.qq.com/open/js/jweixin-1.0.0.js></script> //配置微信分享 wx.config({ debug: false, appId: ‘<?php echo $signPackage["appId"];?>‘, timestamp: ‘<?php echo $signPackage["timestamp"];?>‘, nonceStr: ‘<?php echo $signPackage["nonceStr"];?>‘, signature: ‘<?php echo $signPackage["signature"];?>‘, jsApiList: [ ‘checkJsApi‘, ‘onMenuShareTimeline‘, ‘onMenuShareAppMessage‘, ‘onMenuShareQQ‘, ‘onMenuShareWeibo‘ ] }); wx.ready(function () { //分享给好友 wx.onMenuShareAppMessage({ title: "{$content[‘title‘]}", desc: "{$content[‘desc‘]}", link: "{$content[‘link‘]}", imgUrl: "{$content[‘imgUrl‘]}", success: function (res) { $.ajax({ type: "POST", url: "{:U(‘Enroll/addGlod‘)}", data: {"act_id":act_id}, dataType: "json", success: function(data){ if(data.state==0){ layer.msg(‘出错了!‘) }else if(data.state==1){ layer.msg(‘分享成功<br>获得‘+data.glod+‘金币!‘); }else if(data.state==2){ layer.msg(‘分享成功<br>重复分享不增加金币!‘); } } }); }, cancel: function (res) { layer.msg(‘您取消了分享‘); }, fail: function (res) { layer.msg(‘产生了一个分享错误‘); } }); //分享到朋友圈 wx.onMenuShareTimeline({ title: "{$content[‘title‘]}", desc: "{$content[‘desc‘]}", link: "{$content[‘link‘]}", imgUrl: "{$content[‘imgUrl‘]}", success: function (res) { $.ajax({ type: "POST", url: "{:U(‘Enroll/addGlod‘)}", data: {"act_id":act_id}, dataType: "json", success: function(data){ if(data.state==0){ layer.msg(‘出错了!‘) }else if(data.state==1){ layer.msg(‘分享成功<br>获得‘+data.glod+‘金币!‘); }else if(data.state==2){ layer.msg(‘分享成功<br>重复分享不增加金币!‘); } } }); }, cancel: function (res) { layer.msg(‘您取消了分享‘); }, fail: function (res) { layer.msg(‘产生了一个分享错误‘); } }); });
其中像<?php echo $signPackage["appId"];?>这种是由php传递过来的参数
php端
/* 加载微信SDK */ import ( "ORG.Util.ThinkWechat" ); $weixin = new ThinkWechat (); $signPackage = $weixin->GetSignPackage(); $this->assign(‘signPackage‘,$signPackage);
以上是关于微信页面的分享,设置分享信息以及监听分享的主要内容,如果未能解决你的问题,请参考以下文章