heartrate_server.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package http
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "net/http"
  7. "net/url"
  8. "strings"
  9. "video_course/global"
  10. "video_course/model"
  11. "video_course/utils"
  12. )
  13. type HeartRateServer struct {
  14. }
  15. //查询用户身体数据
  16. func (h HeartRateServer) VipUserQueryByUserMd5(userMd5 string) (rtnCode int, rtn *model.UserBodyInfo) {
  17. api := strings.Join([]string{global.Project.HeartrateUrl, "v1/OutService/GetUserBodyInfoByUserMd5"}, "/")
  18. resp, err := http.PostForm(api, url.Values{
  19. "userMd5": {userMd5},
  20. })
  21. if err != nil {
  22. panic(err)
  23. }
  24. defer resp.Body.Close()
  25. body, err := ioutil.ReadAll(resp.Body)
  26. if err != nil {
  27. err = fmt.Errorf("response:[%s], err:\n%w", string(body), err)
  28. panic(err)
  29. }
  30. var responseBase struct {
  31. Code int
  32. Memo string
  33. Rs map[string]interface{}
  34. }
  35. err = json.Unmarshal(body, &responseBase)
  36. if err != nil {
  37. err = fmt.Errorf("response:[%s], err:\n%w", string(body), err)
  38. panic(err)
  39. }
  40. rtnCode = responseBase.Code
  41. if rtnCode == 0 {
  42. rtn = &model.UserBodyInfo{
  43. UserName: utils.MapToString(responseBase.Rs, "Name"),
  44. Birthday: utils.MapToTime(responseBase.Rs, "Birthday"),
  45. Height: utils.MapToInt32(responseBase.Rs, "Height"),
  46. Weight: utils.MapToInt32(responseBase.Rs, "Weight"),
  47. Sex: utils.MapToInt32(responseBase.Rs, "Sex"),
  48. StaticHr: utils.MapToInt32(responseBase.Rs, "StaticHr"),
  49. UserMd5: utils.MapToString(responseBase.Rs, "UserMd5"),
  50. Head: utils.MapToString(responseBase.Rs, "Head"),
  51. }
  52. }
  53. return
  54. }