zoukankan      html  css  js  c++  java
  • 微信公众号授权获取codequ

    getCode() {
    this.code = ''
    let origin = 'httpxxxxxxxxxxxxx/'
    let urlNow = encodeURIComponent(origin); ///netbar/api/wechat/v1/get_open_id
    let scope = "snsapi_base"; //snsapi_userinfo //静默授权 用户无感知
    let appid = "wx4198xxxxxxxxxxxxx";
    this.code = this.getUrlCode().code;
    console.log(this.code);
    console.log(this.getUrlCode())
    sessionStorage.setItem( "code", this.getUrlCode().code);
    // 截取code
    if (this.code == null || this.code === '') { //未授权qu授权
    let url =
    `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=123#wechat_redirect`;
    sessionStorage.setItem("routers", "routers");
    window.location.href = url;
    console.log(url)
    console.log(window.location.href)
    } else {
    this.$router.push({
    name: "Shopcar"
    })
    }

    getUrlCode() { // 截取url中的code方法
    var url = location.search
    this.winUrl = url
    var theRequest = new Object()
    if (url.indexOf("?") != -1) {
    var str = url.substr(1)
    var strs = str.split("&")
    for (var i = 0; i < strs.length; i++) {
    theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1])
    }
    }
    return theRequest
    },

  • 相关阅读:
    函数封装总结
    03.深入javascript
    02.JavaScript基础下
    html5权威指南:客户端分区响应图
    html5权威指南:定制input元素
    html5权威指南:表单元素
    html5权威指南:表格元素
    html5权威指南:组织内容、文档分节
    css布局理解
    html5权威指南:标记文字
  • 原文地址:https://www.cnblogs.com/xzhce/p/13277611.html
Copyright © 2011-2022 走看看