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);