From bc253e9a81b98bee628005ec43a35905f865d71c Mon Sep 17 00:00:00 2001 From: liuhuapiaoyuan <278780765@qq.com> Date: Tue, 14 May 2024 13:01:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/session.go | 2 +- api/share.go | 2 +- backend-api/accounts/check.go | 2 +- backend-api/backend-api.go | 6 ++++-- backend-api/me.go | 4 ++-- backend-api/next_data_gpts_fixed.go | 2 +- config.yaml | 4 ++-- config/config.go | 6 +++--- modules/chatgpt/service/chatgpt_session.go | 4 ++-- modules/chatgpt/tasks/refresh_session.go | 3 --- public-api/proxypublic.go | 1 + 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/api/session.go b/api/session.go index 8154b10..1213bfd 100644 --- a/api/session.go +++ b/api/session.go @@ -62,7 +62,7 @@ func Session(r *ghttp.Request) { refreshFlag = expires.Before(time.Now()) } - getSessionUrl := config.CHATPROXY(ctx) + "/getsession" + getSessionUrl := config.CHATPROXY + "/getsession" // 判断是否过期 if refreshFlag { g.Log().Info(ctx, "session 过期,重新获取") diff --git a/api/share.go b/api/share.go index 7533ceb..f916700 100644 --- a/api/share.go +++ b/api/share.go @@ -14,7 +14,7 @@ import ( func Share(r *ghttp.Request) { ctx := r.GetCtx() - UpStream := config.CHATPROXY(ctx) + UpStream := config.CHATPROXY // 分享按钮 buttonContent := "Get started with ChatGPT" diff --git a/backend-api/accounts/check.go b/backend-api/accounts/check.go index 6d6e9b0..52fbda7 100644 --- a/backend-api/accounts/check.go +++ b/backend-api/accounts/check.go @@ -39,7 +39,7 @@ func Check(r *ghttp.Request) { // client.SetHeader("Authorization", authHeader) // client.SetHeader("authkey", config.AUTHKEY(ctx)) - // res := client.GetVar(ctx, config.CHATPROXY(ctx)+"/backend-api/accounts/check/v4-2023-04-27") + // res := client.GetVar(ctx, config.CHATPROXY+"/backend-api/accounts/check/v4-2023-04-27") // resJson := gjson.New(res) jsonStr := `{ "accounts": { diff --git a/backend-api/backend-api.go b/backend-api/backend-api.go index e9e69bf..9c6b5ef 100644 --- a/backend-api/backend-api.go +++ b/backend-api/backend-api.go @@ -21,10 +21,12 @@ import ( "github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gcache" ) var ( ChatgptSessionService = service.NewChatgptSessionService() + AccessTokenCache = gcache.New() ) func init() { @@ -62,7 +64,7 @@ func ProxyRequestGet(path string, r *ghttp.Request) (resStr string, err error) { } _, _, accessToken, err := ChatgptSessionService.GetAccessToken(ctx, userToken) - UpStream := config.CHATPROXY(ctx) + UpStream := config.CHATPROXY if err != nil { // 处理错误 panic(err) @@ -142,7 +144,7 @@ func ProxyAll(r *ghttp.Request) { WsUpStream := config.WS_SERVICE(ctx) // g.Log().Info(ctx, "ProxyBackendApi:", path) proxy := &httputil.ReverseProxy{} - UpStream := config.CHATPROXY(ctx) + UpStream := config.CHATPROXY proxy.Transport = &http.Transport{ TLSClientConfig: &tls.Config{ diff --git a/backend-api/me.go b/backend-api/me.go index 2f700a8..d94868d 100644 --- a/backend-api/me.go +++ b/backend-api/me.go @@ -18,10 +18,10 @@ func Me(r *ghttp.Request) { g.Log().Error(ctx, err) r.Response.WriteStatus(http.StatusUnauthorized) return - } + } resStr, err := ProxyRequestGet("/backend-api/me", r) - // UpStream := config.CHATPROXY(ctx) + // UpStream := config.CHATPROXY // // 请求后端接口 // res, err := g.Client().SetHeaderMap(map[string]string{ // "Authorization": "Bearer " + AccessToken, diff --git a/backend-api/next_data_gpts_fixed.go b/backend-api/next_data_gpts_fixed.go index 1a11f27..e6c732c 100644 --- a/backend-api/next_data_gpts_fixed.go +++ b/backend-api/next_data_gpts_fixed.go @@ -17,7 +17,7 @@ func NextDataGptsFixed(r *ghttp.Request) { // 如果请求包含gizmoId gizmoId := r.Request.URL.Query().Get("gizmoId") if gizmoId != "" { - UpStream := config.CHATPROXY(ctx) + UpStream := config.CHATPROXY u, _ := url.Parse(UpStream) proxy := httputil.NewSingleHostReverseProxy(u) proxy.Transport = &http.Transport{ diff --git a/config.yaml b/config.yaml index 90274d2..59496c9 100644 --- a/config.yaml +++ b/config.yaml @@ -55,8 +55,8 @@ modules: enable: 1 # 接入网关地址 -CHATPROXY: "https://chat.openai.com" -#JA3_PROXY: "http://a:b@host.docker.internal:9988" +# CHATPROXY: "https://chat.openai.com" +JA3_PROXY: "http://a:b@host.docker.internal:9988" #CHATPROXY: "http://host.docker.internal:7999" #CHATPROXY: "https://chatgpt.ggss.club/gateway" #ARKOSE_URL: "https://chatgpt.ggss.club/arkose/v2/" diff --git a/config/config.go b/config/config.go index 8592077..764f8df 100644 --- a/config/config.go +++ b/config/config.go @@ -16,9 +16,9 @@ import ( "github.com/gogf/gf/v2/util/gconv" ) -func CHATPROXY(ctx g.Ctx) string { - return g.Cfg().MustGetWithEnv(ctx, "CHATPROXY").String() -} +// func CHATPROXY(ctx g.Ctx) string { +// return g.Cfg().MustGetWithEnv(ctx, "CHATPROXY").String() +// } func WS_SERVICE(ctx g.Ctx) string { return g.Cfg().MustGetWithEnv(ctx, "WS_SERVICE").String() } diff --git a/modules/chatgpt/service/chatgpt_session.go b/modules/chatgpt/service/chatgpt_session.go index ab44145..4ccda68 100644 --- a/modules/chatgpt/service/chatgpt_session.go +++ b/modules/chatgpt/service/chatgpt_session.go @@ -57,7 +57,7 @@ func (s *ChatgptSessionService) ModifyAfter(ctx g.Ctx, method string, param map[ officialSession := param["officialSession"] if officialSession == "" { g.Log().Debug(ctx, "ChatgptSessionService.ModifyAfter", "officialSession is empty") - getSessionUrl := config.CHATPROXY(ctx) + "/getsession" + getSessionUrl := config.CHATPROXY + "/getsession" sessionVar := g.Client().SetHeader("authkey", config.AUTHKEY(ctx)).SetCookie("arkoseToken", gconv.String(param["arkoseToken"])).PostVar(ctx, getSessionUrl, g.Map{ "username": param["email"], "password": param["password"], @@ -91,7 +91,7 @@ func (s *ChatgptSessionService) ModifyAfter(ctx g.Ctx, method string, param map[ // 写一个函数 刷新数据 func (s *ChatgptSessionService) RefreshSession(ctx g.Ctx, chatgpt_session gdb.Record) (err error) { - getSessionUrl := config.CHATPROXY(ctx) + "/getsession" + getSessionUrl := config.CHATPROXY + "/getsession" sessionVar := g.Client().SetHeader("authkey", config.AUTHKEY(ctx)).PostVar(ctx, getSessionUrl, g.Map{ "username": chatgpt_session["email"], "password": chatgpt_session["password"], diff --git a/modules/chatgpt/tasks/refresh_session.go b/modules/chatgpt/tasks/refresh_session.go index 13267c7..4fb4c30 100644 --- a/modules/chatgpt/tasks/refresh_session.go +++ b/modules/chatgpt/tasks/refresh_session.go @@ -42,9 +42,6 @@ func RefreshSession(ctx g.Ctx) { continue } - getSessionUrl := config.CHATPROXY(ctx) + "/getsession" - refreshCookie := gjson.New(v["officialSession"]).Get("refreshCookie").String() - sessionVar := g.Client().SetHeader("authkey", config.AUTHKEY(ctx)).PostVar(ctx, getSessionUrl, g.Map{ "username": v["email"], "password": v["password"], diff --git a/public-api/proxypublic.go b/public-api/proxypublic.go index fbec32c..a2198eb 100644 --- a/public-api/proxypublic.go +++ b/public-api/proxypublic.go @@ -4,6 +4,7 @@ import ( backendapi "chatgpt-mirror-server/backend-api" "chatgpt-mirror-server/config" "chatgpt-mirror-server/utility" + "crypto/tls" "net/http" "net/http/httputil" "net/url"