微信 分享

时间:2020-04-02 01:42:22   收藏:0   阅读:94

 

var link = location.href
$.ajax({
  url: ‘your_url‘, //后台给你提供的接口
  type: ‘GET‘,
  data: { url: link },
  async: true,
  dataType: ‘json‘,
  success: function(data) {
    wx.config({
      debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来
      appId: data.configMap.appId, // 必填,公众号的唯一标识
      timestamp: data.configMap.timestamp, // 必填,生成签名的时间戳
      nonceStr: data.configMap.nonceStr, // 必填,生成签名的随机串
      signature: data.configMap.signature, // 必填,签名,见附录1
      jsApiList: [‘onMenuShareTimeline‘, ‘onMenuShareAppMessage‘] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
    })
    wx.ready(function(res) {
      wx.onMenuShareAppMessage({
        title: document.title,
        desc: document.title,
        link: link,
        imgUrl: Imgurl,
        trigger: function(res) {},
        success: function(res) {},
        cancel: function(res) {},
        fail: function(res) {}
      })
      wx.onMenuShareTimeline({
        title: document.title,
        link: link,
        imgUrl: Imgurl,
        trigger: function(res) {},
        success: function(res) {},
        cancel: function(res) {},
        fail: function(res) {}
      })
    })
    wx.error(function(res) {
      alert(res)
    })
  },
  error: function(error) {
    alert(error)
  }
})

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!