auth.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package xiangyu
  2. import (
  3. "eta_gn/eta_bridge/models/eta"
  4. "eta_gn/eta_bridge/models/response"
  5. "eta_gn/eta_bridge/services"
  6. "eta_gn/eta_bridge/services/xiangyu"
  7. "fmt"
  8. "time"
  9. )
  10. // LoginEta
  11. // @Description: 获取eta的session
  12. // @author: Roc
  13. // @datetime 2024-01-23 17:44:15
  14. // @param code string
  15. // @return resp response.LoginResp
  16. // @return err error
  17. // @return errMsg string
  18. func LoginEta(code string) (resp response.LoginResp, err error, errMsg string) {
  19. // 获取xiangyu token
  20. tokenResp, err := xiangyu.GetToken(code)
  21. if err != nil {
  22. return
  23. }
  24. //// 获取eta用户信息
  25. //adminInfo, err := eta.GetSysUserByOutId(tokenResp.Uid)
  26. //if err != nil {
  27. // return
  28. //}
  29. // 获取用户信息
  30. userInfoResp, err := xiangyu.GetUserInfo(tokenResp.AccessToken)
  31. if err != nil {
  32. return
  33. }
  34. // 获取eta用户信息
  35. adminInfo, err := eta.GetSysUserByAdminName(userInfoResp.LoginName)
  36. if err != nil {
  37. return
  38. }
  39. // 生成登录session
  40. resp, session, err, errMsg := services.CreateEtaSession(adminInfo)
  41. if err != nil {
  42. return
  43. }
  44. // 记录两方session的绑定信息
  45. thirdSession := &eta.SysThirdSession{
  46. ID: 0,
  47. SysUserID: uint64(session.SysUserId),
  48. UserName: session.UserName,
  49. AccessToken: session.AccessToken,
  50. ThirdAccessToken: tokenResp.AccessToken,
  51. //ThirdRefreshToken: tokenResp.RefreshToken,
  52. ThirdExpiredTime: time.Now().Add(time.Duration(tokenResp.ExpiresIn-100) * time.Second),
  53. CreatedTime: time.Now(),
  54. LastUpdatedTime: time.Now(),
  55. }
  56. eta.AddSysThirdSession(thirdSession)
  57. return
  58. }
  59. func GetToken(code string) (err error) {
  60. fmt.Println(xiangyu.GetToken(code))
  61. return
  62. }
  63. func GetUserInfo(token string) (err error) {
  64. fmt.Println(xiangyu.GetUserInfo(token))
  65. return
  66. }
  67. func CheckToken(token string) (err error) {
  68. fmt.Println(xiangyu.CheckToken(token))
  69. return
  70. }
  71. func GetTokenInfo(token string) (err error) {
  72. fmt.Println(xiangyu.GetTokenInfo(token))
  73. return
  74. }
  75. func RefreshToken(token string) (err error) {
  76. fmt.Println(xiangyu.RefreshToken(token))
  77. return
  78. }
  79. func RevokeToken(token string) (err error) {
  80. fmt.Println(xiangyu.RevokeToken(token))
  81. return
  82. }