微信授权和分享展示设置

415 阅读1分钟

微信授权取数据


if (!sessionStorage.getItem("islogin")) {
      if (code == "" || code == undefined) {
        $.ajax({
          type: 'GET',
          url: ''',
          success: function (res) {
            if (Number(res.errno) === 0) {
            
              var state = Date.parse(new Date());
              var url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(location.href)}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`;
              document.write("<a href='" + url + "'>如您的浏览器没有自动跳转,请点击此处手动跳转</a>");
              window.location.href = url;
            }
          }, 
          error: function () {
            warningTip('服务器链接失败', 5000)
          }
        })
      } else {
        code = getSearchVal('code');
        // reqData.url = window.location.href
    } else {
     
    }

设置分享展示


  function wxConfig() {
    wx.config({
      debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
      appId: appid, // 必填,公众号的唯一标识
      timestamp: timestamp, // 必填,生成签名的时间戳
      nonceStr: nonce_str, // 必填,生成签名的随机串
      signature: signature, // 必填,签名
      jsApiList: [
        'checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage'
      ]
    });
    wx.ready(function () {
      wx.onMenuShareTimeline({
        title:  '', // 分享标题
        link:''',
        imgUrl: '',
        success: function () {
          alert("分享成功")
        },
        cancel: function () {
          // 用户取消分享后执行的回调函数
        }
      });
      wx.onMenuShareAppMessage({
        title:  '', // 分享标题
        link:''',
                //分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: '', // 分享图标
        desc: '', // 分享描述        
        type: '', // 分享类型,music、video或link,不填默认为link
        dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
        success: function () {
          alert("分享成功")
        },
        cancel: function () {
          // 用户取消分享后执行的回调函数
        }
      });
    });
  }