Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
fix: 修复微信授权登录
Nevinc5a50feb1fed
diff --git a/aitoearn_web/server/aitoearn-gateway/src/core/plat/wxGzh/wxPlat.controller.ts b/aitoearn_web/server/aitoearn-gateway/src/core/plat/wxGzh/wxPlat.controller.tsindex 9ff9dc75..db03bd57 100644--- a/aitoearn_web/server/aitoearn-gateway/src/core/plat/wxGzh/wxPlat.controller.ts+++ b/aitoearn_web/server/aitoearn-gateway/src/core/plat/wxGzh/wxPlat.controller.ts@@ -1,4 +1,5 @@-import { Body, Controller, Get, Param, Post, Query, UseGuards } from '@nestjs/common'+import { Body, Controller, Get, Post, Query, UseGuards } from '@nestjs/common'+import { Public } from '@/auth/auth.guard'import { OrgGuard } from '@/common/interceptor/transform.interceptor'import { PlatWxGzhNatsApi } from '@/transports/channel/wxGzh.natsApi'import { CallbackMsgData } from './common'@@ -12,19 +13,19 @@ export class WxPlatController {/*** 接收授权回调- * @param taskId* @param query* @returns*/+ @Public()@UseGuards(OrgGuard)@Post('auth/back')async authBackGet(- @Query() query: AuthBackQueryDto,+ @Body() body: AuthBackQueryDto,) {await this.platWxGzhNatsApi.createAccountAndSetAccessToken({- taskId: query.stat,- auth_code: query.auth_code,- expires_in: query.expires_in,+ taskId: body.stat,+ auth_code: body.auth_code,+ expires_in: body.expires_in,})return 'success'}@@ -34,6 +35,7 @@ export class WxPlatController {* @param body* @returns*/+ @Public()@UseGuards(OrgGuard)@Post('callback/msg')async callbackMsg(diff --git a/aitoearn_web/server/aitoearn-wxplat/src/config.ts b/aitoearn_web/server/aitoearn-wxplat/src/config.tsindex e22fe5de..2146fe9d 100644--- a/aitoearn_web/server/aitoearn-wxplat/src/config.ts+++ b/aitoearn_web/server/aitoearn-wxplat/src/config.ts@@ -38,7 +38,7 @@ export const configSchema = z.object({redis: redisConfigSchema,wxPlat: WxPlatSchema,msgUrlList: z.array(z.string()).default([]),- authUrlMap: z.object().default({}),+ authUrlMap: z.any().default({}),})export class AppConfig extends createZodDto(configSchema) {}diff --git a/aitoearn_web/server/aitoearn-wxplat/src/core/wxPlat/server.service.ts b/aitoearn_web/server/aitoearn-wxplat/src/core/wxPlat/server.service.tsindex 4033d5ee..1767df60 100644--- a/aitoearn_web/server/aitoearn-wxplat/src/core/wxPlat/server.service.ts+++ b/aitoearn_web/server/aitoearn-wxplat/src/core/wxPlat/server.service.ts@@ -39,19 +39,14 @@ export class ServerService {*/async sendAuthBack(url: string, data: AuthBackQueryDto & {stat: string- }) {+ }): Promise<boolean> {try {const result = await axios.post<string>(url, data)-- Logger.debug('sendAuthBack---result', result.data)- return result.data+ return result.data === 'success'}catch (error) {- Logger.error(- '------ Error wxPlat sendAuthBack: ------',- error,- )- return null+ Logger.debug('sendAuthBack---error', error)+ return false}}}diff --git a/aitoearn_web/server/aitoearn-wxplat/src/core/wxPlat/wxPlat.controller.ts b/aitoearn_web/server/aitoearn-wxplat/src/core/wxPlat/wxPlat.controller.tsindex 5c1d6be8..5c0dfe57 100644--- a/aitoearn_web/server/aitoearn-wxplat/src/core/wxPlat/wxPlat.controller.ts+++ b/aitoearn_web/server/aitoearn-wxplat/src/core/wxPlat/wxPlat.controller.ts@@ -7,10 +7,12 @@ import {Param,Post,Query,+ Render,Res,UseGuards,UseInterceptors,} from '@nestjs/common';+import { Response } from 'express';import { OrgGuard } from '@/common';import { XmlParseInterceptor } from '@/common/interceptors/xml.interceptor';import { strUtil } from '@/common/utils/str.util';@@ -26,14 +28,15 @@ import {} from './dto/wxPlat.dto';import { ServerService } from './server.service';import { WxPlatService } from './wxPlat.service';-import { Response } from 'express';+@Controller('wxPlat')export class WxPlatController {logger = new Logger(WxPlatController.name);constructor(private readonly wxPlatService: WxPlatService,private readonly serverService: ServerService,- ) { }+ ) {+ }// -------- 接收回调 STR --------@@ -123,6 +126,7 @@ export class WxPlatController {*/@HttpCode(200)@UseGuards(OrgGuard)+ @Render('back/res')@Get('auth/back/:key/:stat')async authBackGet(@Param('key') key: string,@@ -131,12 +135,29 @@ export class WxPlatController {) {const { authUrlMap } = config;const url = authUrlMap[key];- if (!url)- return 'success'- return await this.serverService.sendAuthBack(authUrlMap[key], {++ if (!url) {+ return {+ success: false,+ message: 'Authorization failed',+ }+ }+ const res = await this.serverService.sendAuthBack(url, {...query,- stat+ stat,});++ if (!res) {+ return {+ success: false,+ message: 'Authorization failed',+ }+ }++ return {+ success: true,+ message: 'Authorization successful',+ }}// -------- 接收回调 END --------@@ -156,11 +177,11 @@ export class WxPlatController {@Get('auth/page')async getAuthPage(@Query() query: GetAuthUrlDto,- @Res() res: Response+ @Res() res: Response,) {const redirectUri = `${config.wxPlat.authBackHost}/wxPlat/auth/back/${query.key}/${query.stat}`;const authUrl = await this.wxPlatService.getAuthPageUrl(redirectUri, query.type);-+return res.render(`auth/${query.type}`,{ url: authUrl },diff --git a/aitoearn_web/server/aitoearn-wxplat/src/views/back/res.hbs b/aitoearn_web/server/aitoearn-wxplat/src/views/back/res.hbsnew file mode 100644index 00000000..2bde46dc--- /dev/null+++ b/aitoearn_web/server/aitoearn-wxplat/src/views/back/res.hbs@@ -0,0 +1,195 @@+<!DOCTYPE html>+<html lang="zh-CN">++<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Authorization result</title>+ <style>+ * {+ margin: 0;+ padding: 0;+ box-sizing: border-box;+ }++ body {+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);+ min-height: 100vh;+ display: flex;+ align-items: center;+ justify-content: center;+ }++ .container {+ background: rgba(255, 255, 255, 0.95);+ border-radius: 20px;+ box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);+ padding: 40px 20px;+ text-align: center;+ max-width: 90%;+ width: 100%;+ backdrop-filter: blur(10px);+ animation: fadeIn 0.5s ease-out;+ }++ @keyframes fadeIn {+ from {+ opacity: 0;+ transform: translateY(-20px);+ }++ to {+ opacity: 1;+ transform: translateY(0);+ }+ }++ .logo {+ width: 80px;+ height: 80px;+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);+ border-radius: 50%;+ margin: 0 auto 20px;+ display: flex;+ align-items: center;+ justify-content: center;+ color: white;+ font-size: 30px;+ font-weight: bold;+ }++ h3 {+ color: #333;+ margin-bottom: 20px;+ font-size: 22px;+ font-weight: 500;+ }++ .result-message {+ font-size: 18px;+ margin: 20px 0;+ padding: 15px;+ border-radius: 10px;+ }++ .success {+ background-color: #e8f5e9;+ color: #4caf50;+ border: 1px solid #c8e6c9;+ }++ .error {+ background-color: #ffebee;+ color: #f44336;+ border: 1px solid #ffcdd2;+ }++ .details {+ background: #f8f9fa;+ border-radius: 10px;+ padding: 15px;+ margin: 20px 0;+ word-break: break-all;+ font-size: 12px;+ color: #666;+ border: 1px solid #eee;+ max-height: 150px;+ overflow-y: auto;+ text-align: left;+ }++ .action-button {+ display: inline-block;+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);+ color: white;+ text-decoration: none;+ padding: 12px 30px;+ border-radius: 25px;+ font-weight: 500;+ transition: all 0.3s ease;+ box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);+ width: 80%;+ max-width: 200px;+ margin: 10px 0;+ border: none;+ cursor: pointer;+ font-size: 16px;+ }++ .action-button:hover {+ transform: translateY(-2px);+ box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);+ }++ .action-button:active {+ transform: translateY(0);+ }++ .action-button.secondary {+ background: transparent;+ color: #667eea;+ border: 2px solid #667eea;+ box-shadow: none;+ }++ .tips {+ color: #999;+ font-size: 12px;+ margin-top: 20px;+ line-height: 1.5;+ }++ @media (max-width: 480px) {+ .container {+ padding: 30px 15px;+ }++ h3 {+ font-size: 18px;+ }++ .action-button {+ padding: 10px 20px;+ font-size: 14px;+ }+ }+ </style>+</head>++<body>+ <div class="container">+ <div class="logo">WX</div>+ <h3>授权结果</h3>++ {{#if success}}+ <div class="result-message success">+ ✅ 授权成功+ </div>+ <p>您已成功完成微信授权</p>+ {{else}}+ <div class="result-message error">+ ❌ 授权失败+ </div>+ {{#if message}}+ <div class="details">+ <strong>错误信息:</strong><br />+ {{message}}+ </div>+ {{/if}}+ {{/if}}+++ <div class="tips">+ <p>如遇到问题,请联系客服</p>+ </div>+ </div>++ <script>+ setTimeout(() => {+ window.close();+ }, 3000);+ </script>+</body>++</html>\ No newline at end of file