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

复制代码
// 需要企微回调的地址
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;
        }
相关推荐
天空属于哈夫克33 天前
企业微信二次开发:精准实现关键词自动回复
架构·企业微信
wechatbot8883 天前
极客互动企业微信 SCRM 自动运营平台效果实测
java·微信·企业微信·rpa
志尊宝3 天前
Vue3 零基础每日笔记(055):组件里正确使用 store——storeToRefs 解构与 $patch 批量修改
笔记·vue·html·前端开发·软件开发
yzy853 天前
Vue中下载或打开文件的JavaScript方法
前端·javascript·vue
极客互动API3 天前
极客互动-企业微信基于外部API接口实现AI客服自动接管外部联系人消息收发
java·微信·企业微信·ai编程·rpa
金融Tech趋势派3 天前
2026企业微信客户运营效率提升方案:AI Agent+SCRM让效率提升300%
企业微信
天空属于哈夫克33 天前
企业微信二次开发:用 sendText 做外部群工单播报
架构·企业微信
星云API技术支持4 天前
企业微信二次开发项目实战:从实例接入到消息收发与 Webhook 回调的完整链路
机器人·yapi·企业微信
星云API技术支持4 天前
企业微信二次开发如何实现外部群自动化?从消息监听到接口调用完整流程
机器人·yapi·企业微信
星云API技术支持4 天前
企业微信二次开发消息收发实战:单聊、群聊与事件消息如何统一处理
机器人·yapi·企业微信