diff --git a/frontend/web/package-lock.json b/frontend/web/package-lock.json index 44f66a3..282244f 100644 --- a/frontend/web/package-lock.json +++ b/frontend/web/package-lock.json @@ -8,12 +8,14 @@ "name": "cyrene-web", "version": "0.2.0", "dependencies": { + "qrcode": "^1.5.4", "react": "^19.0.0", "react-dom": "^19.0.0", "zustand": "^5.0.2" }, "devDependencies": { "@tailwindcss/postcss": "^4.0.6", + "@types/qrcode": "^1.5.6", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", "@vitejs/plugin-react": "^4.3.4", @@ -1506,6 +1508,26 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/node": { + "version": "26.4.1", + "resolved": "https://registry.npmmirror.com/@types/node/-/node-26.4.1.tgz", + "integrity": "sha512-k97ENvZWtvA6yqz5/FS6a7duDgOPEeOQOc2iKS/nY6mX6qJUKtLnWzQS+Xj6tXweyj6ZcTAK2Qecetnvi9nCLA==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~8.3.0" + } + }, + "node_modules/@types/qrcode": { + "version": "1.5.6", + "resolved": "https://registry.npmmirror.com/@types/qrcode/-/qrcode-1.5.6.tgz", + "integrity": "sha512-te7NQcV2BOvdj2b1hCAHzAoMNuj65kNBMz0KBaxM6c3VGBOhU0dURQKOtH8CFNI/dsKkwlv32p26qYQTWoB5bw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/react": { "version": "19.2.18", "resolved": "https://registry.npmmirror.com/@types/react/-/react-19.2.18.tgz", @@ -1547,6 +1569,30 @@ "vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0" } }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmmirror.com/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/baseline-browser-mapping": { "version": "2.11.21", "resolved": "https://registry.npmmirror.com/baseline-browser-mapping/-/baseline-browser-mapping-2.11.21.tgz", @@ -1594,6 +1640,15 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmmirror.com/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/caniuse-lite": { "version": "1.0.30001810", "resolved": "https://registry.npmmirror.com/caniuse-lite/-/caniuse-lite-1.0.30001810.tgz", @@ -1615,6 +1670,35 @@ ], "license": "CC-BY-4.0" }, + "node_modules/cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmmirror.com/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "license": "ISC", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "license": "MIT", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmmirror.com/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "license": "MIT" + }, "node_modules/convert-source-map": { "version": "2.0.0", "resolved": "https://registry.npmmirror.com/convert-source-map/-/convert-source-map-2.0.0.tgz", @@ -1647,6 +1731,15 @@ } } }, + "node_modules/decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmmirror.com/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/detect-libc": { "version": "2.1.2", "resolved": "https://registry.npmmirror.com/detect-libc/-/detect-libc-2.1.2.tgz", @@ -1657,6 +1750,12 @@ "node": ">=8" } }, + "node_modules/dijkstrajs": { + "version": "1.0.3", + "resolved": "https://registry.npmmirror.com/dijkstrajs/-/dijkstrajs-1.0.3.tgz", + "integrity": "sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA==", + "license": "MIT" + }, "node_modules/electron-to-chromium": { "version": "1.5.422", "resolved": "https://registry.npmmirror.com/electron-to-chromium/-/electron-to-chromium-1.5.422.tgz", @@ -1664,6 +1763,12 @@ "dev": true, "license": "ISC" }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmmirror.com/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "license": "MIT" + }, "node_modules/enhanced-resolve": { "version": "5.24.5", "resolved": "https://registry.npmmirror.com/enhanced-resolve/-/enhanced-resolve-5.24.5.tgz", @@ -1748,6 +1853,19 @@ } } }, + "node_modules/find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmmirror.com/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "license": "MIT", + "dependencies": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz", @@ -1773,6 +1891,15 @@ "node": ">=6.9.0" } }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmmirror.com/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "license": "ISC", + "engines": { + "node": "6.* || 8.* || >= 10.*" + } + }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmmirror.com/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -1780,6 +1907,15 @@ "dev": true, "license": "ISC" }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmmirror.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/jiti": { "version": "2.7.0", "resolved": "https://registry.npmmirror.com/jiti/-/jiti-2.7.0.tgz", @@ -2084,6 +2220,18 @@ "url": "https://opencollective.com/parcel" } }, + "node_modules/locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmmirror.com/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "license": "MIT", + "dependencies": { + "p-locate": "^4.1.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmmirror.com/lru-cache/-/lru-cache-5.1.1.tgz", @@ -2140,6 +2288,51 @@ "node": ">=18" } }, + "node_modules/p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmmirror.com/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "license": "MIT", + "dependencies": { + "p-try": "^2.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmmirror.com/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "license": "MIT", + "dependencies": { + "p-limit": "^2.2.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmmirror.com/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmmirror.com/picocolors/-/picocolors-1.1.1.tgz", @@ -2160,6 +2353,15 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/pngjs": { + "version": "5.0.0", + "resolved": "https://registry.npmmirror.com/pngjs/-/pngjs-5.0.0.tgz", + "integrity": "sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==", + "license": "MIT", + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/postcss": { "version": "8.5.28", "resolved": "https://registry.npmmirror.com/postcss/-/postcss-8.5.28.tgz", @@ -2189,6 +2391,23 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/qrcode": { + "version": "1.5.4", + "resolved": "https://registry.npmmirror.com/qrcode/-/qrcode-1.5.4.tgz", + "integrity": "sha512-1ca71Zgiu6ORjHqFBDpnSMTR2ReToX4l1Au1VFLyVeBTFavzQnv5JxMFr3ukHVKpSrSA2MCk0lNJSykjUfz7Zg==", + "license": "MIT", + "dependencies": { + "dijkstrajs": "^1.0.1", + "pngjs": "^5.0.0", + "yargs": "^15.3.1" + }, + "bin": { + "qrcode": "bin/qrcode" + }, + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/react": { "version": "19.2.8", "resolved": "https://registry.npmmirror.com/react/-/react-19.2.8.tgz", @@ -2220,6 +2439,21 @@ "node": ">=0.10.0" } }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmmirror.com/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", + "license": "ISC" + }, "node_modules/rollup": { "version": "4.63.1", "resolved": "https://registry.npmmirror.com/rollup/-/rollup-4.63.1.tgz", @@ -2282,6 +2516,12 @@ "semver": "bin/semver.js" } }, + "node_modules/set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", + "license": "ISC" + }, "node_modules/source-map-js": { "version": "1.2.1", "resolved": "https://registry.npmmirror.com/source-map-js/-/source-map-js-1.2.1.tgz", @@ -2292,6 +2532,32 @@ "node": ">=0.10.0" } }, + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/tailwindcss": { "version": "4.3.3", "resolved": "https://registry.npmmirror.com/tailwindcss/-/tailwindcss-4.3.3.tgz", @@ -2344,6 +2610,13 @@ "node": ">=14.17" } }, + "node_modules/undici-types": { + "version": "8.3.0", + "resolved": "https://registry.npmmirror.com/undici-types/-/undici-types-8.3.0.tgz", + "integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==", + "dev": true, + "license": "MIT" + }, "node_modules/update-browserslist-db": { "version": "1.3.2", "resolved": "https://registry.npmmirror.com/update-browserslist-db/-/update-browserslist-db-1.3.2.tgz", @@ -2450,6 +2723,32 @@ } } }, + "node_modules/which-module": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/which-module/-/which-module-2.0.1.tgz", + "integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==", + "license": "ISC" + }, + "node_modules/wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmmirror.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/y18n": { + "version": "4.0.3", + "resolved": "https://registry.npmmirror.com/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", + "license": "ISC" + }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmmirror.com/yallist/-/yallist-3.1.1.tgz", @@ -2457,6 +2756,41 @@ "dev": true, "license": "ISC" }, + "node_modules/yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmmirror.com/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "license": "MIT", + "dependencies": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmmirror.com/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "license": "ISC", + "dependencies": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/zustand": { "version": "5.0.15", "resolved": "https://registry.npmmirror.com/zustand/-/zustand-5.0.15.tgz", diff --git a/frontend/web/package.json b/frontend/web/package.json index 115ed68..1e03f28 100644 --- a/frontend/web/package.json +++ b/frontend/web/package.json @@ -11,12 +11,14 @@ "typecheck": "tsc --noEmit" }, "dependencies": { + "qrcode": "^1.5.4", "react": "^19.0.0", "react-dom": "^19.0.0", "zustand": "^5.0.2" }, "devDependencies": { "@tailwindcss/postcss": "^4.0.6", + "@types/qrcode": "^1.5.6", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", "@vitejs/plugin-react": "^4.3.4", diff --git a/frontend/web/src/admin/modules/channels/WeixinLogin.tsx b/frontend/web/src/admin/modules/channels/WeixinLogin.tsx index 0ab2202..a270bbb 100644 --- a/frontend/web/src/admin/modules/channels/WeixinLogin.tsx +++ b/frontend/web/src/admin/modules/channels/WeixinLogin.tsx @@ -1,14 +1,37 @@ import { useEffect, useRef, useState } from "react"; +import QRCode from "qrcode"; import { adminWeixinLoginQR, adminWeixinLoginStatus } from "../../../lib/api"; import { useAuditStore } from "../../audit"; import { Button, Surface, Tag } from "../../../components/primitives"; import { Notice } from "../../components"; /** weixin-iLink scan-login panel (design/08 §4). On an account without a bot_token - * it shows a 扫码登录 button; clicking it mints a QR via GET /login-qr, renders the - * QR image, and polls GET /login-status until confirmation. On confirmation the - * backend persists the token and hot-connects the adapter, so the panel just - * flags "已登录". An account that already has a token never shows the button. */ + * it shows a 扫码登录 button; clicking it mints a QR via GET /login-qr, renders a + * scannable QR from the WeChat QR URL (qrcode_img_content), and polls GET /login-status + * until confirmation. The liteapp URL is an HTML page that cannot be fetched as an + * image, so the frontend draws the QR itself from qrUrl. On confirmation the backend + * persists the token and hot-connects the adapter; the panel flags "已登录". */ +function QrImage({ value }: { value: string }): React.ReactNode { + const [src, setSrc] = useState(""); + useEffect(() => { + let alive = true; + QRCode.toDataURL(value, { width: 200, margin: 1 }) + .then((url) => alive && setSrc(url)) + .catch(() => alive && setSrc("")); + return () => { + alive = false; + }; + }, [value]); + if (!value) return 未获得二维码,请点「刷新二维码」重试。; + if (!src) return 生成二维码中…; + return ( + 微信 iLink 登录二维码 + ); +} export function WeixinLogin({ platform, accountId, @@ -18,7 +41,6 @@ export function WeixinLogin({ }): React.ReactNode { const log = useAuditStore((s) => s.log); const [status, setStatus] = useState("idle"); - const [qrImage, setQrImage] = useState(""); const [qrUrl, setQrUrl] = useState(""); const [botId, setBotId] = useState(""); const [busy, setBusy] = useState(null); @@ -64,12 +86,10 @@ export function WeixinLogin({ const start = () => { setBusy("__qr__"); setNotice(null); - setQrImage(""); setQrUrl(""); adminWeixinLoginQR(platform, accountId) .then((r) => { log("channel.weixin.login.qr", "ok"); - setQrImage(r.qrImage ?? ""); setQrUrl(r.qrUrl ?? ""); if (r.status === "confirmed") { setStatus("confirmed"); @@ -97,7 +117,7 @@ export function WeixinLogin({ .finally(() => setBusy(null)); }; - const showQR = status === "waiting" || (qrImage !== "" || qrUrl !== ""); + const showQR = status === "waiting" || qrUrl !== ""; return ( @@ -124,14 +144,10 @@ export function WeixinLogin({ {showQR ? (
- {qrImage || qrUrl ? ( - 微信 iLink 登录二维码 + {qrUrl ? ( + ) : ( - 二维码图片暂不可用,请点击「刷新二维码」重试。 + 二维码暂不可用,请点击「刷新二维码」重试。 )}

请用微信扫描上方二维码,确认后自动连接(最多等待约 8 分钟)。

diff --git a/frontend/web/src/lib/types.ts b/frontend/web/src/lib/types.ts index 3f2f8ff..4b416b8 100644 --- a/frontend/web/src/lib/types.ts +++ b/frontend/web/src/lib/types.ts @@ -294,8 +294,10 @@ export interface AdminChannelAccount { * directly. status is one of idle|waiting|confirmed|failed. The qrcode scan * identifier is never exposed. */ export interface WeixinLoginQRResponse { + /** The WeChat QR image URL (qrcode_img_content); the panel renders a QR from it. */ qrUrl?: string; - qrImage?: string; + /** The raw scan identifier (qrcode), used for status polling. */ + qrCode?: string; status: string; } diff --git a/internal/channel/adapter/adapter.go b/internal/channel/adapter/adapter.go index a00272b..617bb9e 100644 --- a/internal/channel/adapter/adapter.go +++ b/internal/channel/adapter/adapter.go @@ -83,8 +83,11 @@ var ( // configuration as strongly typed structs. Unknown keys are ignored; missing // keys leave the corresponding zero value. func DecodeConfig(raw map[string]any, v any) error { + // A nil config map is treated as empty (decodes to the zero value), so a + // pending account with no keys yet (e.g. a weixin-ilink scan-login account the + // panel created before binding) builds with defaults rather than erroring. if raw == nil { - return errors.New("adapter: nil config map") + raw = map[string]any{} } b, err := json.Marshal(raw) if err != nil { diff --git a/internal/channel/adapter/adapter_test.go b/internal/channel/adapter/adapter_test.go index c380d73..e4968ed 100644 --- a/internal/channel/adapter/adapter_test.go +++ b/internal/channel/adapter/adapter_test.go @@ -100,8 +100,13 @@ func TestDecodeConfig(t *testing.T) { func TestDecodeConfigNil(t *testing.T) { t.Parallel() + // A nil config map is treated as empty (decodes to zero value), so a pending + // account with no keys yet builds with defaults rather than erroring. var c struct{ Token string } - if err := DecodeConfig(nil, &c); err == nil { - t.Error("DecodeConfig(nil, ...) error = nil, want non-nil") + if err := DecodeConfig(nil, &c); err != nil { + t.Fatalf("DecodeConfig(nil, ...) error = %v, want nil (empty config)", err) + } + if c.Token != "" { + t.Fatalf("Token = %q, want empty zero value", c.Token) } } diff --git a/internal/services/gateway/admin_channels_weixin.go b/internal/services/gateway/admin_channels_weixin.go index 11a36d4..a811365 100644 --- a/internal/services/gateway/admin_channels_weixin.go +++ b/internal/services/gateway/admin_channels_weixin.go @@ -38,9 +38,12 @@ type weixinLoginAdmin interface { } // weixinLoginQRResponse is the wire shape of GET /admin/channels/{platform}/login-qr. +// qrUrl is the WeChat QR image URL (qrcode_img_content) and qrCode is the raw scan +// identifier (qrcode); the frontend renders a scannable QR from qrUrl, since the +// liteapp URL is an HTML page that cannot be fetched as an image. type weixinLoginQRResponse struct { QrUrl string `json:"qrUrl,omitempty"` - QrImage string `json:"qrImage,omitempty"` + QrCode string `json:"qrCode,omitempty"` Status string `json:"status"` } @@ -77,9 +80,9 @@ func (s *Server) adminWeixinLoginQR(w http.ResponseWriter, r *http.Request) { status, _ := wx.LoginStatus(r.Context()) s.auditClaims(r, "channel.weixin.login.qr", "ok") writeJSON(w, http.StatusOK, weixinLoginQRResponse{ - QrUrl: qr.Image, - QrImage: qrImageDataURL(r.Context(), qr.Image), - Status: status, + QrUrl: qr.Image, + QrCode: qr.Qrcode, + Status: status, }) } diff --git a/internal/services/gateway/admin_channels_weixin_test.go b/internal/services/gateway/admin_channels_weixin_test.go index 727d4c5..c857386 100644 --- a/internal/services/gateway/admin_channels_weixin_test.go +++ b/internal/services/gateway/admin_channels_weixin_test.go @@ -196,19 +196,19 @@ func TestAdminWeixinLoginQR_ReturnsQRAndStatus(t *testing.T) { } var out struct { Data struct { - QrUrl string `json:"qrUrl"` - QrImage string `json:"qrImage"` - Status string `json:"status"` + QrUrl string `json:"qrUrl"` + QrCode string `json:"qrCode"` + Status string `json:"status"` } `json:"data"` } if err := json.Unmarshal(body, &out); err != nil { t.Fatalf("decode login-qr: %v", err) } if out.Data.QrUrl == "" { - t.Errorf("qrUrl empty, want the QR image content") + t.Errorf("qrUrl empty, want the QR image URL (qrcode_img_content)") } - if !strings.HasPrefix(out.Data.QrImage, "data:image/png;base64,") { - t.Errorf("qrImage = %q, want a base64 data URL", out.Data.QrImage) + if out.Data.QrCode == "" { + t.Errorf("qrCode empty, want the raw scan identifier") } if out.Data.Status != weixin_ilink.LoginStatusWaiting && out.Data.Status != weixin_ilink.LoginStatusConfirmed { t.Errorf("status = %q, want waiting|confirmed", out.Data.Status)