From 9282f1d8932c2ecf0b4334ef0b12ddda01ebe1d1 Mon Sep 17 00:00:00 2001 From: duyazhe Date: Sun, 6 Jul 2025 23:09:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E7=99=BE?= =?UTF-8?q?=E5=BA=A6=E8=AF=B7=E6=B1=82=E6=97=B6=E5=80=99=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E4=BC=A0appid=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- relay/channel/baidu_v2/adaptor.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/relay/channel/baidu_v2/adaptor.go b/relay/channel/baidu_v2/adaptor.go index 2b8a52a2..c97bc5e9 100644 --- a/relay/channel/baidu_v2/adaptor.go +++ b/relay/channel/baidu_v2/adaptor.go @@ -42,7 +42,12 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) { func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) error { channel.SetupApiRequestHeader(info, c, req) - req.Set("Authorization", "Bearer "+info.ApiKey) + infos := strings.Split(info.ApiKey, "|") + if len(infos) > 1 { + req.Set("appid", infos[1]) + } + + req.Set("Authorization", "Bearer "+infos[0]) return nil } From ce57ad35706b41c8b51f96ae36c98fbbac121e91 Mon Sep 17 00:00:00 2001 From: duyazhe Date: Mon, 7 Jul 2025 09:57:20 +0800 Subject: [PATCH 2/2] Update adaptor.go --- relay/channel/baidu_v2/adaptor.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/relay/channel/baidu_v2/adaptor.go b/relay/channel/baidu_v2/adaptor.go index c97bc5e9..470f2a0c 100644 --- a/relay/channel/baidu_v2/adaptor.go +++ b/relay/channel/baidu_v2/adaptor.go @@ -42,12 +42,16 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) { func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) error { channel.SetupApiRequestHeader(info, c, req) - infos := strings.Split(info.ApiKey, "|") - if len(infos) > 1 { - req.Set("appid", infos[1]) - } - - req.Set("Authorization", "Bearer "+infos[0]) + keyParts := strings.Split(info.ApiKey, "|") + if len(keyParts) == 0 || keyParts[0] == "" { + return errors.New("invalid API key: authorization token is required") + } + if len(keyParts) > 1 { + if keyParts[1] != "" { + req.Set("appid", keyParts[1]) + } + } + req.Set("Authorization", "Bearer "+keyParts[0]) return nil }