From 78b1650bdb071c858b3f90d53a700d11ee6de328 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Tue, 2 Dec 2025 16:37:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=A5=BF=E9=83=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=BF=94=E5=9B=9E=E4=BF=A1=E6=81=AF=E4=B9=B1?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugins/plugin-west/access.ts | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/ui/certd-server/src/plugins/plugin-west/access.ts b/packages/ui/certd-server/src/plugins/plugin-west/access.ts index fbaffa6aa..cbfb59300 100644 --- a/packages/ui/certd-server/src/plugins/plugin-west/access.ts +++ b/packages/ui/certd-server/src/plugins/plugin-west/access.ts @@ -1,6 +1,7 @@ import { HttpRequestConfig } from '@certd/basic'; import { IsAccess, AccessInput, BaseAccess } from '@certd/pipeline'; import qs from 'qs'; +import iconv from 'iconv-lite'; /** * 这个注解将注册一个授权配置 * 在certd的后台管理系统中,用户可以选择添加此类型的授权 @@ -213,7 +214,7 @@ token=md5(zhangsan + 5dh232kfg!* + 1554691950854)=cfcd208495d565ef66e7dff9f98764 const headers = {} const body: any = {} if (method.toUpperCase() === 'POST') { - headers['Content-Type'] = 'application/x-www-form-urlencoded'; + headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; body.data = data } else if (method.toUpperCase() === 'GET') { let queryString = ''; @@ -230,6 +231,25 @@ token=md5(zhangsan + 5dh232kfg!* + 1554691950854)=cfcd208495d565ef66e7dff9f98764 method, ...body, headers, + responseType: 'arraybuffer', // 关键:获取原始二进制数据 + transformResponse: [ + function(data, headers) { // headers 参数包含响应头 + try { + const contentType = headers['content-type'] || ''; + // 判断是否是 GB2312/GBK 编码 + if (contentType.includes('gb2312') || contentType.includes('gbk')) { + // 使用 iconv-lite 解码 + data = iconv.decode(data, 'gb2312'); + }else{ + // 默认按 UTF-8 处理 + data = data.toString('utf-8'); + } + } catch (error) { + console.error('解码失败:', error); + } + return JSON.parse(data); + } + ] }); this.ctx.logger.info(`request ${url} ${method} res:${JSON.stringify(res)}`); if (res.msg !== 'success' && res.result!= 200) {