diff --git a/backend-api/backend-api.go b/backend-api/backend-api.go index ccab4d5..1200b80 100644 --- a/backend-api/backend-api.go +++ b/backend-api/backend-api.go @@ -57,11 +57,8 @@ func ProxyRequestGet(path string, r *ghttp.Request) (resStr string, err error) { if Authorization != "" { userToken = r.Header.Get("Authorization")[7:] } - userId, chatgptId, accessToken, err := ChatgptSessionService.GetAccessToken(ctx, userToken) + _, _, accessToken, err := ChatgptSessionService.GetAccessToken(ctx, userToken) - g.Log().Debug(ctx, "userToken", userToken) - g.Log().Debug(ctx, "userId", userId) - g.Log().Debug(ctx, "chatgptId", chatgptId) UpStream := config.CHATPROXY(ctx) if err != nil { // 处理错误 @@ -96,6 +93,7 @@ func ProxyRequestGet(path string, r *ghttp.Request) (resStr string, err error) { req.Header.Add(key, value) } } + req.Header.Set("authkey", config.AUTHKEY(ctx)) req.Header.Set("Authorization", "Bearer "+accessToken) req.Header.Set("Host", "chat.openai.com") req.Header.Set("Origin", "https://chat.openai.com/chat") @@ -104,6 +102,7 @@ func ProxyRequestGet(path string, r *ghttp.Request) (resStr string, err error) { resp, err := client.Do(req) if err != nil { // 处理错误 + g.Log().Error(ctx, err) panic(err) } defer resp.Body.Close() @@ -124,8 +123,6 @@ func ProxyAll(r *ghttp.Request) { if Authorization != "" { userToken = r.Header.Get("Authorization")[7:] } - g.Log().Debug(ctx, "userToken", userToken) - isStream := strings.Contains(r.Header.Get("accept"), "text/event-stream") // 获得当前的请求域名 @@ -191,7 +188,6 @@ func ProxyAll(r *ghttp.Request) { // log content-type g.Log().Debug(ctx, "content-type", response.Header.Get("Content-Type")) } - // 判断response的Cotnent-Type是否是json if strings.Contains(response.Header.Get("Content-Type"), "json") { isStream = false @@ -292,6 +288,7 @@ func AttachGPT4Mobile(ctx g.Ctx, response *http.Response) error { func CreateConversation(r *ghttp.Request, userId int, chatgptId int, userToken string, userAgent string, conversationPath string) { id := strings.Split(conversationPath, "/")[4] r.Request.Header.Set("Authorization", "Bearer "+userToken) + g.Log().Info(r.GetCtx(), "准备开始创建话题CreateConversation", id) resStr, err := ProxyRequestGet("/backend-api/conversation/"+id, r) if err != nil { return diff --git a/public-api/proxypublic.go b/public-api/proxypublic.go index 176e0cf..e1c8e79 100644 --- a/public-api/proxypublic.go +++ b/public-api/proxypublic.go @@ -2,6 +2,7 @@ package publicapi import ( "chatgpt-mirror-server/config" + "chatgpt-mirror-server/utility" "crypto/tls" "net/http" "net/http/httputil" @@ -25,12 +26,21 @@ func ProxyPublic(r *ghttp.Request) { }, ForceAttemptHTTP2: true, } + if config.Ja3Proxy != nil { + proxy.Transport = &http.Transport{ + Proxy: http.ProxyURL(config.Ja3Proxy), + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + ForceAttemptHTTP2: true, + } + } newreq := r.Request.Clone(ctx) newreq.URL.Host = u.Host newreq.URL.Scheme = u.Scheme newreq.Host = u.Host newreq.Header.Set("authkey", config.AUTHKEY(ctx)) - + utility.HeaderModify(&newreq.Header) // newreq.Header.Set("Cookie", "__Secure-next-auth.session-token="+carinfo.RefreshCookie) // // 去除header 中的 压缩 // newreq.Header.Del("Accept-Encoding")