zoukankan      html  css  js  c++  java
  • vue:h5实现微信授权

    先在main.js中设置全局的项目地址 方便在其他页面调用

    Vue.prototype.globalVerb={

      openMpOpenPlatformHost:"http://afopen.afarsoft.com"

    }

    1、先调用本地接口获取到后端提供的初始用户信息

    getInfo() {
          This.http.get(“接口地址xxx”,{
    params:{...})
    .then(res => {
            console.log(res.Result);
            if (res.Result.Data) {
              this.appId = res.Result.Data.MpAppId;
              this.img = res.Result.Data.MpHeadImg;
              this.NickName = res.Result.Data.MpNickName;
              this.UserName = res.Result.Data.UserName;
            }
          });
        },

    、授权页面点击按钮调取授权接口,按照如下格式拼接url

    http://test.crm.afarsoft.com/WeChatSynchronization?nickname=1&headimg=https%3A%2F%2Fss1.baidu.com%2F6ONXsjip0QIZ8tyhnq%2Fit%2Fu%3D1750833952,2529388352%26fm%3D58%26bpow%3D380%26bpoh%3D380&appid=3&username=4&qrcode=https%3A%2F%2Fss1.baidu.com%2F6ONXsjip0QIZ8tyhnq%2Fit%2Fu%3D1750833952,2529388352%26fm%3D58%26bpow%3D380%26bpoh%3D380

    btn() {
         var host = request.defaults.baseURL;
                  if(/^//g.test(host)){
                    host=window.location.protocol + "//" + window.location.host+host;
                  }
          var notifyUrl = encodeURIComponent(
            this.baseURL + "/api/mp/mpeventhandler"
        //baseUrl 在http.js里,所以要在该授权页面引入http
          );
          var returnUrl = encodeURIComponent(
            window.location.protocol +
              "//" +
              window.location.host +
              this.$route.fullPath
          );
          window.location =
            this.globalVerb.openMpOpenPlatformHost +
            "/home/index?returnurl=" +
            returnUrl +
            "&notifyurl=" +
            notifyUrl +
            "&type=mp";
        }

    3、更新用户信息

    updateInfo(query) {
          this.appId = query.appid;
          this.img = query.headimg;
          this.NickName = query.nickname;
          this.UserName = query.username;
          this.qrCode = query.qrcode;
          This.http.post(“接口地址xxx”,{
            MpAppId: this.appId,
            MpNickName: this.NickName,
            MpHeadImg: this.img,
            UserName: this.UserName,
            MpQrcode: this.qrCode
          })
    .then(res => {
            console.log(res.Result);
          });
        },

    4、判断状态

     created() {
        var query = this.$router.currentRoute.query;
        if (query.nickname) {
          this.updateInfo(query);
        } else {
          this.getInfo();
        }
      }
  • 相关阅读:
    win7 安装 memcached
    Nginx执行php显示no input file specified的处理方法
    Nginx配置SSI
    Windows Services
    如何安装mysql服务
    windows下nginx+php简单配置
    Thread Safe(线程安全)和None Thread Safe(NTS,非线程安全)之分
    php常用方法总结
    弹出框以及提示插件lghdialog.js的使用
    webservice的简单示例的实现步骤
  • 原文地址:https://www.cnblogs.com/jervy/p/11946230.html
Copyright © 2011-2022 走看看