收藏
回答

网站应用微信登录有时无法跳转到我提供的重定向地址

https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html

我使用了官方的微信登录脚本

<script src="https://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>


然后使用微信扫码,点击授权后,可以看到 api 返回了 wx_code,但是页面没有发生跳转,一直卡着不动了

我的应用技术栈是 tauri+angular,我的重定向地址是一个网页,如下

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>微信登录重定向</title>
  <script>
    // 获取URL参数
    // client: web, desktop_sunwoo, dev
    function getUrlParams() {
      const params = new URLSearchParams(window.location.search);
      return {
        code: params.get('code'),
        client: params.get('client'),
        state: params.get('state')
      };
    }
    // 根据客户端类型获取重定向URL
    function getRedirectUrl(client, code, state) {
      const baseUrls = {
        web: 'https://mydomain.com',
            web_dev: 'http://localhost:3000',
        desktop: 'http://tauri.localhost/sign-in',
        desktop_dev: 'http://localhost:3000/sign-in',
      };
      const baseUrl = baseUrls[client] || baseUrls.web;
      const separator = baseUrl.includes('?') ? '&' : '?';
      return `${baseUrl}${separator}code=${code}&state=${state}`;
    }

    // 立即执行重定向
    const { code, client, state } = getUrlParams();
    if (code && client) {
      const redirectUrl = getRedirectUrl(client, code, state);
      window.location.replace(redirectUrl);
    }
  </script>
</head>
<body>
</body>
</html>


部分 windows 用户会出现这个问题,大部分 windows 用户是可以正常登录的;我在 mac 上测试经常复现,但是偶尔能登进去,windows 上测试一直没问题,不知道什么原因,有人遇到过这种情况吗?

回答关注问题邀请回答
收藏

1 个回答

  • 阿白
    阿白
    2025-11-05

    +11111

    最后解决了吗

    2025-11-05
    有用
    回复
登录 后发表内容