美文网首页
vue H5获取微信登陆code

vue H5获取微信登陆code

作者: 安徒生1997 | 来源:发表于2021-03-10 13:50 被阅读0次

CodeBtn(){

    let _this=this;

    let appid = "xxxxxxxxx"; //公众平台appid

    const code = _this.getUrlParam('code'); //是否存在code

    let local = encodeURIComponent(window.location.href);//获取当前url

    if (code == null || code === "") {

        //不存在就打开上面的地址进行授权

        window.location.href =

          `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${local}&response_type=code&scope=snsapi_userinfo&state=wecedirect`;

      }else{

        _this.code = code;

        _this.getOpenId(code);

      }

    },

},

// 获取url地址栏参数

getUrlParam(name) {

      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");

      var rrr = decodeURIComponent(window.location.search);

      var r = rrr.substr(1).match(reg);

      if(r != null) return unescape(r[2]);

      return null;

},

getOpenId(){

    // 修改url参数以及设置参数

    window.history.replaceState({}, '','http://www.wkjiankang.com');

}

相关文章

  • vue H5获取微信登陆code

    CodeBtn(){ let _this=this; let appid = "xxxxxxxxx"; //公...

  • 微信公众号开发

    采用 TP5 + vue 实现如下功能 微信登录微信分享微信支付 微信登录 前端输入参数跳转 前端获取code码 ...

  • H5页面调用微信授权获取code

    H5调用微信授权获取code(微信公众号微信页面开发网页授权) 一、首先你要有一个公众号(公众号、订阅号),微信公...

  • 微信公众号开发—获取微信openid

    前言 微信在获取openid时,首先需要获取code。根据微信开发文档,获取code https://open.w...

  • 各三方网页OAuth登录获取openid和unionid

    微信 大致流程 获取code 》 获取access_token 获取code(前端) 网页跳转地址https://...

  • 获取微信OpenId

    获取微信OpenId 先获取code 再通过code获取authtoken,从authtoken中取出openid...

  • 微信登录

    1.登录 及获取 用户基础信息 前端调起微信登录获取code ----传给后端 后端通过code 调用微信api...

  • 微信授权登陆与自定义分享

    微信授权登陆 第一步:用户同意授权,获取code 在确保微信公众账号拥有授权作用域(scope参数)的权限的前提下...

  • 网络流程梳理2

    在微信登陆成功之后把微信返回的code通过Autorize类的sendWXLoginAuther方法将这个code...

  • 网络流程梳理

    在微信登陆成功之后把微信返回的code通过Autorize类的sendWXLoginAuther方法将这个code...

网友评论

      本文标题:vue H5获取微信登陆code

      本文链接:https://www.haomeiwen.com/subject/rxlwqltx.html