Skip to content

Commit

Permalink
fix: 修复账号保存后,无法自动更新token
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhuapiaoyuan committed Jan 21, 2024
1 parent 8c424fd commit fbbccc1
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions modules/chatgpt/service/chatgpt_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
Expand Down

0 comments on commit fbbccc1

Please sign in to comment.