微信分享的官方文档:http://mp.weixin.qq.com/wiki/7/1c97470084b73f8e224fe6d9bab1625b.html
微信公众平台:https://mp.weixin.qq.com/
1.必须是认证过的公众号才能有分享的权限(认证300元/次)
2.在公众平台获取AppID(应用ID)
和AppSecret(应用密钥)
开发 > 基本配置
3.在公众平台绑定域名 流程:公众号设置 > 功能设置 > JS接口安全域名 > 设置(每月只能设置3次)
4.在开发文档最下方下载demo http://demo.open.weixin.qq.com/jssdk/sample.zip
5.修改sample.php
中的AppID
和AppSecret
上传到第3步绑定域名对应的服务器
6.demo给的代码js部分比较臃肿,稍微整理了一下
// 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});
})