diff --git a/yelaymaths_api/src/main.ts b/yelaymaths_api/src/main.ts index 9012e86..1bcba9c 100644 --- a/yelaymaths_api/src/main.ts +++ b/yelaymaths_api/src/main.ts @@ -1,4 +1,5 @@ import { NestFactory } from '@nestjs/core'; +import express from 'express'; import { Logger } from 'nestjs-pino'; import { AppModule } from './app.module'; import { loadEnvFile, readConfig } from './config/config'; @@ -16,6 +17,11 @@ async function bootstrap(): Promise { app.useLogger(app.get(Logger)); app.getHttpAdapter().getInstance().set('trust proxy', 1); + // 微信虚拟支付的回调是 XML 请求体,而 Nest 的 rawBody 只挂在 json/urlencoded + // 两个解析器上,对 application/xml 不生效。这里显式补一个文本解析器, + // 否则控制器拿到的是空对象,发货推送会一直失败。 + app.use('/v1/payments', express.text({ type: ['application/xml', 'text/xml'], limit: '1mb' })); + // 管理后台跨域;小程序不走 CORS app.enableCors({ origin: [cfg.ADMIN_ORIGIN], @@ -29,4 +35,3 @@ async function bootstrap(): Promise { } void bootstrap(); -