123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package xiangyu
- import (
- "eta/eta_bridge/models/eta"
- "eta/eta_bridge/models/response"
- "eta/eta_bridge/services"
- "eta/eta_bridge/services/xiangyu"
- "fmt"
- "time"
- )
- // LoginEta
- // @Description: 获取eta的session
- // @author: Roc
- // @datetime 2024-01-23 17:44:15
- // @param code string
- // @return resp response.LoginResp
- // @return err error
- // @return errMsg string
- func LoginEta(code string) (resp response.LoginResp, err error, errMsg string) {
- // 获取xiangyu token
- tokenResp, err := xiangyu.GetToken(code)
- if err != nil {
- return
- }
- //// 获取eta用户信息
- //adminInfo, err := eta.GetSysUserByOutId(tokenResp.Uid)
- //if err != nil {
- // return
- //}
- // 获取用户信息
- userInfoResp, err := xiangyu.GetUserInfo(tokenResp.AccessToken)
- if err != nil {
- return
- }
- // 获取eta用户信息
- adminInfo, err := eta.GetSysUserByAdminName(userInfoResp.LoginName)
- if err != nil {
- return
- }
- // 生成登录session
- resp, session, err, errMsg := services.CreateEtaSession(adminInfo)
- if err != nil {
- return
- }
- // 记录两方session的绑定信息
- thirdSession := &eta.SysThirdSession{
- ID: 0,
- SysUserID: uint64(session.SysUserId),
- UserName: session.UserName,
- AccessToken: session.AccessToken,
- ThirdAccessToken: tokenResp.AccessToken,
- //ThirdRefreshToken: tokenResp.RefreshToken,
- ThirdExpiredTime: time.Now().Add(time.Duration(tokenResp.ExpiresIn-100) * time.Second),
- CreatedTime: time.Now(),
- LastUpdatedTime: time.Now(),
- }
- eta.AddSysThirdSession(thirdSession)
- return
- }
- func GetToken(code string) (err error) {
- fmt.Println(xiangyu.GetToken(code))
- return
- }
- func GetUserInfo(token string) (err error) {
- fmt.Println(xiangyu.GetUserInfo(token))
- return
- }
- func CheckToken(token string) (err error) {
- fmt.Println(xiangyu.CheckToken(token))
- return
- }
- func GetTokenInfo(token string) (err error) {
- fmt.Println(xiangyu.GetTokenInfo(token))
- return
- }
- func RefreshToken(token string) (err error) {
- fmt.Println(xiangyu.RefreshToken(token))
- return
- }
- func RevokeToken(token string) (err error) {
- fmt.Println(xiangyu.RevokeToken(token))
- return
- }
|