auth_controller.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package haitong
  2. import (
  3. "encoding/json"
  4. "eta/eta_bridge/controller/resp"
  5. "eta/eta_bridge/global"
  6. "eta/eta_bridge/logic/htfutures"
  7. "fmt"
  8. "github.com/gin-gonic/gin"
  9. "github.com/go-playground/validator/v10"
  10. )
  11. type GetTokenReq struct {
  12. Code string `json:"code" form:"code" description:"code编码"`
  13. }
  14. type SSOLoginController struct {
  15. }
  16. // SSOLogin
  17. // @Description: 用code换取token
  18. // @author: CH
  19. // @receiver xc
  20. // @datetime 2024-01-23 17:06:34
  21. // @param c *gin.Context
  22. func (xc *SSOLoginController) SSOLogin(c *gin.Context) {
  23. var req GetTokenReq
  24. if e := c.Bind(&req); e != nil {
  25. err, ok := e.(validator.ValidationErrors)
  26. if !ok {
  27. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  28. return
  29. }
  30. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  31. return
  32. }
  33. if req.Code == "" {
  34. resp.FailMsg("请传入code码", "请输入指标code码", c)
  35. return
  36. }
  37. result, err, errMsg := htfutures.LoginEta(req.Code)
  38. global.FILE_LOG.Info("oss 请求结束")
  39. if err != nil {
  40. resp.FailData(errMsg, err.Error(), c)
  41. return
  42. }
  43. str, err := json.Marshal(result)
  44. global.FILE_LOG.Info(fmt.Sprintf("请求成功,返回响应体:%s", str))
  45. resp.OkData("获取成功", result, c)
  46. return
  47. }