From fbbccc1e22b7d6004c87267221815a7b46bd159a Mon Sep 17 00:00:00 2001 From: liuhuapiaoyuan <278780765@qq.com> Date: Sun, 21 Jan 2024 19:50:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=90=8E=EF=BC=8C=E6=97=A0=E6=B3=95=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=9B=B4=E6=96=B0token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/chatgpt/service/chatgpt_session.go | 59 +++++++++++----------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/modules/chatgpt/service/chatgpt_session.go b/modules/chatgpt/service/chatgpt_session.go index 6583022..61f9653 100644 --- a/modules/chatgpt/service/chatgpt_session.go +++ b/modules/chatgpt/service/chatgpt_session.go @@ -54,38 +54,37 @@ func (s *ChatgptSessionService) ModifyAfter(ctx g.Ctx, method string, param map[ g.Log().Debug(ctx, "手工模式不需要刷新") return } - officialSession := gjson.New(param["officialSession"]) - refreshCookie := officialSession.Get("refreshCookie").String() - // 如果没有officialSession,就去获取 - g.Log().Debug(ctx, "ChatgptSessionService.ModifyAfter", "officialSession is empty") - getSessionUrl := config.CHATPROXY(ctx) + "/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"], - "authkey": config.AUTHKEY(ctx), - "refreshCookie": refreshCookie, - }) - sessionJson := gjson.New(sessionVar) - if sessionJson.Get("accessToken").String() == "" { - g.Log().Error(ctx, "ChatgptSessionService.ModifyAfter", "get session error", sessionJson) - detail := sessionJson.Get("detail").String() - if detail != "" { - err = gerror.New(detail) - cool.DBM(s.Model).Where("email=?", param["email"]).Update(g.Map{ - "officialSession": sessionJson.String(), - "status": 0, - }) - } else { - err = gerror.New("get session error") + officialSession := param["officialSession"] + if officialSession == "" { + g.Log().Debug(ctx, "ChatgptSessionService.ModifyAfter", "officialSession is empty") + getSessionUrl := config.CHATPROXY(ctx) + "/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"], + "authkey": config.AUTHKEY(ctx), + }) + sessionJson := gjson.New(sessionVar) + if sessionJson.Get("accessToken").String() == "" { + g.Log().Error(ctx, "ChatgptSessionService.ModifyAfter", "get session error", sessionJson) + detail := sessionJson.Get("detail").String() + if detail != "" { + err = gerror.New(detail) + cool.DBM(s.Model).Where("email=?", param["email"]).Update(g.Map{ + "officialSession": sessionJson.String(), + "status": 0, + }) + } else { + err = gerror.New("get session error") + } + return } - return + models := sessionJson.Get("models").Array() + _, err = cool.DBM(s.Model).Where("email=?", param["email"]).Update(g.Map{ + "officialSession": sessionJson.String(), + "isPlus": len(models) > 1, + "status": 1, + }) } - models := sessionJson.Get("models").Array() - _, err = cool.DBM(s.Model).Where("email=?", param["email"]).Update(g.Map{ - "officialSession": sessionJson.String(), - "isPlus": len(models) > 1, - "status": 1, - }) return }