php 微信分享

1.引入jssdk wechat-php-jssdk.zip (其中兩個json文件須要讀寫權限)php

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

2.js分享代碼html

<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.htmljson

微信JS SDK Demo

相關文章
相關標籤/搜索