zoukankan      html  css  js  c++  java
  • Vue公众号配置微信授权(路由采用history模式)

    created() {
    let vm = this;
    /**如果扫码进入,后端会在地址传openid;
    * */
    if (this.$route.query.openid !== "" || Cookies.get('SESSION')) {
    return
    }
    let code=this.getUrlKey("code");
    if (!code) {
    this.getCodeApi("123");
    } else {
      /*调取接口查看是否登录*/
    userLogin({code:code}).then((res) => {
    window.localStorage.setItem("loginState", '1');
    }).catch((err)=> {
    /*说明没登录*/
    window.localStorage.setItem("loginState", '0');
    vm.$_toast(err.message)
    })
    }

    }
    getUrlKey(name){// 获取url 参数
    return decodeURIComponent((new RegExp('[?|&]'+name+'='+'([^&;]+?)(&|#|;|$)').exec(location.href)||[,""])[1].replace(/+/g,'%20'))||null;
    }
    getCodeApi(state){// 获取code
    let urlNow=window.location.href;
    let scope='snsapi_base'; // snsapi_userinfo //静默授权 用户无感知
    let appid=appId;
    let url=`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`;
    window.location.replace(url);
    }
  • 相关阅读:
    row_number() over
    hubbledotnet 使用笔记
    Sql 递归
    aspnet_isapi.dll 和 iis
    正则题目
    Html to jsstring
    js 回车提交表单
    with as
    MSSQL 时间的操作
    php 执行mssql 里的语句,报错 The EXECUTE permission was denied on the object
  • 原文地址:https://www.cnblogs.com/wangxinyubokeyuan/p/10511991.html
Copyright © 2011-2022 走看看