1. 类库:下载
2. php 调用
$jssdk = new \Vendor\Jssdk\Jssdk("wx8b8eafc6427b1f84", "73705538fa7b0b0d5fae8452c666fc25"); $signPackage = $jssdk->GetSignPackage(); $this->assign('signPackage',$signPackage);
3. js
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> <script> wx.config({ appId: '{$signPackage.appId}', timestamp: '{$signPackage.timestamp}', nonceStr: '{$signPackage.nonceStr}', signature: '{$signPackage.signature}', jsApiList: [ 'onMenuShareTimeline', 'onMenuShareAppMessage', ] }); wx.ready(function () { wx.checkJsApi({ jsApiList: [ 'onMenuShareTimeline', 'onMenuShareAppMessage' ], }); wx.onMenuShareTimeline({ title: '{$house.pname}', link: '{$signPackage.url}', imgUrl: '{$image[0][imgurl]}', success: function (res) { // 用户确认分享后执行的回调函数 shareSuccess(res); }, cancel: function () { // 用户取消分享后执行的回调函数 layer.msg('取消了分享到朋友圈'); } }); wx.onMenuShareAppMessage({ title: '{$house.pname}', desc: '{$house.description}', link: '{$signPackage.url}', imgUrl: '{$image[0][imgurl]}', type: '', dataUrl: '', success: function (res) { // 用户确认分享后执行的回调函数 shareSuccess(res); }, cancel: function () { // 用户取消分享后执行的回调函数 layer.msg('取消了分享给朋友'); } }); }); </script> <script> function shareSuccess(res){ // r=eval("("+res+")"); $.ajax({ url: '/shareSuccess.php?checksign={$checksign}&id={$house.id}', type: 'get', dataType: 'json', }) .done(function(r) { layer.msg(r.con); }) console.log(res); } </script>
本文为看恩吧原创文章,转载无需和我联系,但请注明来自knsay.com