欢迎光临一流素材网,免积分免费素材下载!
当前位置:首页 > 教程 > CMS教程>DiYunCms

DiYunCMS微信分享代码

所属栏目:DiYunCms更新时间:2020-07-01 来源:DiYunCMS 原作者:不详 发布:deepdfhy浏览:0

在内容模板中添加微信分享代码

可自定义分享参数


{php \Phpcmf\Service::C()->init_file('weixin');$signPackage = \Phpcmf\Service::L('jssdk', 'weixin')->GetSignPackage();}
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>           
<script type="text/javascript">
  wx.config({
      appId: '<?php echo $signPackage["appId"];?>',
    timestamp: <?php echo $signPackage["timestamp"];?>,
    nonceStr: '<?php echo $signPackage["nonceStr"];?>',
    signature: '<?php echo $signPackage["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: '{$title}',
    desc: '{$description}',
    link: "{dr_now_url()}",
    imgUrl: '{dr_get_file($thumb)}',
  };
  //分享朋友
  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>
收藏 0 有帮助 0 没帮助 0 打赏 0
给个评价吧