微擎 公众号分享朋友圈不显示缩略图

微擎 公众号分享朋友圈不显示缩略图

首先在公众号控制器层面获取用户数据
$account_api = WeAccount::create();
$jssdk = $account_api->getJssdkConfig();获取数据

在需要分享的页面写入js代码(如果每个页面都需要分享就写在公共的页面中)

// html页面代码
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>           
<script type="text/javascript">
  wx.config({
      debug: false,
      appId: '{$jssdk['appId']}',
      timestamp: '{$jssdk['timestamp']}',
      nonceStr: '{$jssdk['nonceStr']}',
      signature: '{$jssdk['signature']}',
      jsApiList: [
        'checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideMenuItems',
        'showMenuItems',
        'hideAllNonBaseMenuItem',
        'showAllNonBaseMenuItem',
        'translateVoice',
        'startRecord',
        'stopRecord',
        'onRecordEnd',
        'playVoice',
        'pauseVoice',
        'stopVoice',
        'uploadVoice',
        'downloadVoice',
        'chooseImage',
        'previewImage',
        'uploadImage',
        'downloadImage',
        'getNetworkType',
        'openLocation',
        'getLocation',
        'hideOptionMenu',
        'showOptionMenu',
        'closeWindow',
        'scanQRCode',
        'chooseWXPay',
        'openProductSpecificView',
        'addCard',
        'chooseCard',
        'openCard'
      ]
  });
  wx.ready(function () {
  
    var shareData = {
    title: '这里是标题,如果需要动态标题自己获取',
    desc: '这里是描述',
    link: "",
    imgUrl: '请使用图片的绝对路径',
  };
  var adurl="绝对路径回调地址";//回调
  //分享朋友
  wx.onMenuShareAppMessage({
       title: shareData.title,
      desc: shareData.desc,
      link: shareData.link,
      imgUrl:shareData.imgUrl,
      trigger: function (res) {
      },
      success: function (res) {
        window.location.href =adurl;
      },
      cancel: function (res) {
      },
      fail: function (res) {
        alert(JSON.stringify(res));
      }
    });
 //朋友圈
  wx.onMenuShareTimeline({
      title: shareData.title+"---"+shareData.desc,
      link: shareData.link,
      imgUrl:shareData.imgUrl,
      trigger: function (res) {
      },
      success: function (res) {
          window.location.href =adurl;
      },
      cancel: function (res) {
      },
      fail: function (res) {
        alert(JSON.stringify(res));
      }
    });   
    
  });
</script>

你可能感兴趣的:(微擎 公众号分享朋友圈不显示缩略图)