pc端使用微信登陆

  PC端使用微信登陆,成功后先跳转到稍后页面然后跳到个人中心

  1、首先要后台去申请微信appid以及前期的一些准备工作,当然前端做也可以,但是我没负责这块,我就不知道怎么申请,申请成功后会给一个appid

  2、二维码页面代码 

  <div id="wxCode"></div>

  <script src="https://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
  <script>
    $(document).ready(function(){
      var obj = new WxLogin({
        id:"wxCode",  //div的id
        appid: "wx6axxxxxxxxxxxxxd6",  //后台申请的appid
        scope: "snsapi_login",  //写死
        redirect_uri:encodeURI("https://xxxxxxxxxxxxxxxx.html") ,  //扫描二维码后跳转的页面
        state: "",
        style: "black",//二维码黑白风格
        href: ""
      });
    });
  </script>

  3、跳转页面

  扫描二维码后会返回一个code,该code会自动添加在你跳转页面的url地址后面,后台需要通过code判断是否登陆成功,最好是新增一个页面专门用来判断是否登陆成功,不要直接跳转到原本的页面。

  获取code

  getRequest() {
    var url = window.location.search; //获取url中"?"符后的字串
    url = url.substr(1);
    url = url.split('&')[0].split('=')[1];
    var theRequest = {code:url};
    return theRequest;
  }

  将获取的code传给后台,后台判断后返回结果给你,再通过结果判断是否跳转到个人中心页

  

原文地址:https://www.cnblogs.com/qiruoranbeginner/p/9935761.html