微信分享的官方文檔:http://mp.weixin.qq.com/wiki/7/1c97470084b73f8e224fe6d9bab1625b.htmlphp
微信公衆平臺:https://mp.weixin.qq.com/html
1.必須是認證過的公衆號纔能有分享的權限(認證300元/次)安全
2.在公衆平臺獲取AppID(應用ID)
和AppSecret(應用密鑰)
開發 > 基本配置服務器
3.在公衆平臺綁定域名 流程:公衆號設置 > 功能設置 > JS接口安全域名 > 設置(每個月只能設置3次)微信
4.在開發文檔最下方下載demo http://demo.open.weixin.qq.com/jssdk/sample.zipapp
5.修改sample.php
中的AppID
和AppSecret
上傳到第3步綁定域名對應的服務器微信公衆平臺
6.demo給的代碼js部分比較臃腫,稍微整理了一下url
// js部分整理了一下 wx.config({ debug: <?php if(isset($_GET['is_weixin'])){echo 'true';}else{echo 'false';}?>, appId: '<?php echo $signPackage["appId"];?>', timestamp: <?php echo $signPackage["timestamp"];?>, nonceStr: '<?php echo $signPackage["nonceStr"];?>', signature: '<?php echo $signPackage["signature"];?>', jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ'] }); wx.checkJsApi({ jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ'], success: function(res) {},error:function(res){} }); wx.ready(function () { var title = '個人標題'; var desc = '<?=config_item('share_p2p')?>'; var link = '<?=$share_url?>'; var imgUrl = 'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png'; // 發送給朋友 wx.onMenuShareAppMessage({title:title, desc:desc, link:link, imgUrl:imgUrl}); // 分享到朋友圈 wx.onMenuShareTimeline({title:title, desc:desc, link:link, imgUrl:imgUrl}); // 分享到QQ wx.onMenuShareQQ({title:title, desc:desc, link:link, imgUrl:imgUrl}); })