bind_mobile_handler.go 903 B

123456789101112131415161718192021222324252627282930313233343536
  1. package user
  2. import (
  3. "net/http"
  4. "git.i2edu.net/i2/i2-bill-api/internal/logic/user"
  5. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  6. "git.i2edu.net/i2/i2-bill-api/internal/types"
  7. "git.i2edu.net/i2/i2-bill-api/internal/utils"
  8. "git.i2edu.net/i2/go-zero/rest/httpx"
  9. )
  10. func BindMobileHandler(ctx *svc.ServiceContext) http.HandlerFunc {
  11. return func(w http.ResponseWriter, r *http.Request) {
  12. var req types.BindMobileRequest
  13. if err := httpx.Parse(r, &req); err != nil {
  14. httpx.OkJson(w, utils.ReturnHTTPFail(err))
  15. return
  16. }
  17. uid, skey, err := ctx.GetClaims(r)
  18. if err != nil {
  19. httpx.OkJson(w, utils.ReturnHTTPFail(err))
  20. return
  21. }
  22. l := user.NewBindMobileLogic(r.Context(), ctx)
  23. l.UserId = uid
  24. l.SessionKey = skey
  25. resp, err := l.BindMobile(req)
  26. if err != nil {
  27. httpx.OkJson(w, utils.ReturnHTTPFail(err))
  28. } else {
  29. httpx.OkJson(w, utils.ReturnHTTPSuccess(resp))
  30. }
  31. }
  32. }