auth_controller.go 1.0 KB

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