Micro-letter (Public No.) Custom Share

Micro-channel JS-SDK (1.4) version

1, the introduction of micro channel priority JS-SDK

<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<!-- 支持https -->
<script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>

2, the processing micro-channel sharing parameters needed

var timestamp, nonceStr, signature, data = {};
data.url = location.href.split('#')[0];
$.ajax({
    async: false,
    type: 'post',
    url:'xxxx',
    data: data,
    dataType: 'json',
    success:function(res){
        timestamp = res.data.timestamp;
        nonceStr = res.data.nonceStr;
        signature = res.data.signature;
    }
});

3, check the permissions

wx.config({
  debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  appId: appId, // 必填,公众号的唯一标识
  timestamp:timestamp , // 必填,生成签名的时间戳
  nonceStr: nonceStr, // 必填,生成签名的随机串
  signature: signature,// 必填,签名
  jsApiList: ['checkJsApi', 'updateAppMessageShareData', 'updateTimelineShareData'] // 必填,需要使用的JS接口列表
});

/**
 * checkJsApi:校验当前客户端是否支持指定版本JS接口
 * updateAppMessageShareData:自定义“分享给朋友”及“分享到QQ”按钮的分享内容(1.4.0)
 * updateTimelineShareData:自定义“分享到朋友圈”及“分享到QQ空间”按钮的分享内容(1.4.0)
 * */

wx.ready(function(){
    wx.checkJsApi({
      jsApiList: ['chooseImage'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
      success: function(res) {
      // 以键值对的形式返回,可用的api值true,不可用为false
      // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
      }
    });
    
    /**
     * 分享图标imgUrl推荐使用链接地址,不推荐使用相对路径
     * */
    wx.updateAppMessageShareData({ 
        title: '', // 分享标题
        desc: '', // 分享描述
        link: '', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: '', // 分享图标
        success: function () {
          // 设置成功
        }
    });
    
    wx.updateTimelineShareData({ 
        title: '', // 分享标题
        link: '', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: '', // 分享图标
        success: function () {
          // 设置成功
        }
    });
});
Precautions:
  • The following interfaces share custom micro-channel is about to waste, it is recommended using the shared interfaces
    • wx.onMenuShareTimeline: Share circle of friends
    • wx.onMenuShareAppMessage: Send to a friend
    • wx.onMenuShareQQ: Share QQ
    • wx.onMenuShareQZone: QQ space to share
  • Getting permission to verify the information, with the back of the check current client supports the specified version of JS interfaces to synchronous , asynchronous execution will lead to sharing fail

Guess you like

Origin www.cnblogs.com/zxk5211/p/web_22.html
Recommended