1.引入jssdk wechat-php-jssdk.zip (其中两个json文件需要读写权限)

<?php
require_once "./jssdk.php";
$jssdk = new JSSDK("APPID", "APPSECRET");
$signPackage = $jssdk->GetSignPackage();
?>

2.js分享代码

<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<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: [
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
      // 所有要调用的 API 都要加到这个列表中
    ]
  });
  var title = '';
  var desc = '';
  var link = '';
  var imgUrl = '';
  wx.ready(function () {
      wx.onMenuShareAppMessage({
          title: title,
          desc: desc,
          link: link,
          imgUrl: imgUrl
        });
      wx.onMenuShareTimeline({
          title: title,
          desc: desc,
          link: link,
          imgUrl: imgUrl
        });
      wx.onMenuShareQQ({
          title: title,
          desc: desc,
          link: link,
          imgUrl: imgUrl
        });
      wx.onMenuShareWeibo({
          title: title,
          desc: desc,
          link: link,
          imgUrl: imgUrl
        });
  });
</script>

微信JS-SDK说明文档:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html

微信JS SDK Demo

posted on 2015-04-22 10:39  浊浊然  阅读(330)  评论(0编辑  收藏  举报