mop_device_security.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package client
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "git.finogeeks.club/base/apm"
  6. "mop-account-system/common"
  7. "github.com/gin-gonic/gin"
  8. )
  9. type GetTokenInfoRsp struct {
  10. Errcode string `json:"errcode"`
  11. Error string `json:"error"`
  12. Data struct {
  13. JwtToken string `json:"jwtToken"`
  14. UserId string `json:"userId"`
  15. ExpireTime int `json:"expireTime"`
  16. RefreshToken string `json:"refreshToken"`
  17. } `json:"data"`
  18. }
  19. func GetTokenInfo(c *gin.Context, userId string) (*GetTokenInfoRsp, error) {
  20. traceCtx := apm.ApmClient().TraceContextFromGin(c)
  21. var headers = map[string]string{
  22. "Accept": "application/json, text/plain, */*",
  23. "Content-Type": "application/json",
  24. }
  25. type GetTokenReq struct {
  26. UserId string `json:"userId"`
  27. }
  28. var req GetTokenReq
  29. req.UserId = userId
  30. body, _ := json.Marshal(req)
  31. url := cfg.DeviceSecurityUrlPrefix + "/api/v1/mop/applets-ecol-device-security/login"
  32. rsp, err := Request(traceCtx).SetHeaders(headers).SetBody(body).Post(url)
  33. if err != nil {
  34. common.GinLog.Errorln("DeviceActive status err:" + err.Error())
  35. return nil, err
  36. }
  37. if rsp.StatusCode() != 200 {
  38. common.GinLog.Errorln("DeviceActive status err:" + rsp.String())
  39. return nil, errors.New("status err")
  40. }
  41. var tokensRsp GetTokenInfoRsp
  42. err = json.Unmarshal(rsp.Body(), &tokensRsp)
  43. if err != nil {
  44. common.GinLog.Errorln("json.Unmarshal err:" + err.Error())
  45. return nil, err
  46. }
  47. return &tokensRsp, nil
  48. }