企业微信对接:回调地址带#时返回地址参数位置不对的问题

复制代码
// 需要企微回调的地址
http://localhost:1024/app/#/SsoLogin?loginMethod=qw

// 企微配置的地址
https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxxxxxxx&redirect_uri=http%3A%2F%2Flocalhost%3A1024%2Fapp%2F%23%2FSsoLogin%3FloginMethod%3Dqw&response_type=code&scope=snsapi_base&state=STATE&agentid=AGENTID#wechat_redirect

// 企微返回的地址
http://localhost:1024/app/?code=xxxxxxxxxxxxxxxxxxstate=000000#/SsoLogin?loginMethod=qw

返回结果并没有在#/SsoLogin后拼接参数

方法一:

企微返回的地址虽然参数顺序不对,但还是访问到/SsoLogin这个地址

只需要在这个页面中处理一下字符串取出参数即可

复制代码
const getUrlParamsRegex = url => {
  const params = {};
  // 处理 URL 中的参数
  const urlParts = url.split("?");
  if (urlParts[1]) {
    const searchParams = new URLSearchParams(urlParts[1].split("#")[0]);
    for (const [key, value] of searchParams.entries()) {
      params[key] = value;
    }
  }
  // 处理 hash 中的参数
  const hashParts = url.split("#");
  if (hashParts[1]) {
    const hashParams = new URLSearchParams(hashParts[1].split("?")[1] || "");
    for (const [key, value] of hashParams.entries()) {
      params[key] = value;
    }
  }
  return params;
};

// 返回结果取值  const urlParamsRegex = getUrlParamsRegex(window.location.href);
// urlParamsRegex.code

方法二

1、修改vue路由模式,去掉#

复制代码
// createWebHashHistory改为createWebHistory,并可以在配置额文件指定路由后缀VITE_PUBLIC_PATH

// 原代码
const router = createRouter({
  history: createWebHashHistory(),
...
});

// 修改后
const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_PATH),
...
});

2、修改nginx配置

复制代码
// 原配置
        location /app {
            root  /usr/share/nginx;
            index index.html;
        }

// 修改后
        location /app {
            root  /usr/share/nginx;
            index index.html;
            try_files $uri $uri/ /cloud/index.html;
        }
相关推荐
源雀数智6 天前
源雀AI SCRM开源版重磅升级:AI智能标签库
人工智能·企业微信·流量运营
梦想的旅途26 天前
企业微信API:外部群自动化推送实战指南
大数据·机器人·自动化·企业微信·rpa
vx-bot5556666 天前
企业微信ipad协议的事件驱动架构与实时监听实践
架构·企业微信·ipad
南_山无梅落6 天前
从传统Web到API驱动:使用Django REST Framework重构智能合同审查系统
重构·django·vue·drf
天空属于哈夫克36 天前
基于 Webhook 的企业微信外部群自动化推送集成
运维·自动化·企业微信
JZC_xiaozhong6 天前
企业微信对接泛微OA:实现审批进度实时同步与自动催办
企业微信·etl工程师·泛微oa·数据集成与应用集成·业务流程管理系统·异构系统集成·跨系统流程管理
PD我是你的真爱粉7 天前
API 请求封装(Axios + 拦截器 + 错误处理)
前端框架·vue
天空属于哈夫克37 天前
Java 开发|企微外部群主动发送小程序消息实战
开发语言·python·小程序·自动化·企业微信·rpa
vx-bot5556667 天前
企业微信ipad协议的标签管理机制与自动化打标实践
自动化·企业微信·ipad
梦想的旅途27 天前
Python 实现企业微信外部群主动消息发送
机器人·自动化·企业微信·rpa