report.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta/eta_mini_api/models"
  5. "eta/eta_mini_api/utils"
  6. "fmt"
  7. "io"
  8. "net/http"
  9. "strconv"
  10. "time"
  11. "github.com/rdlucklib/rdluck_tools/paging"
  12. )
  13. type ReportList struct {
  14. List []*models.ReportList
  15. Paging *paging.PagingItem
  16. }
  17. type ReportResp[T any] struct {
  18. Ret int
  19. Data T
  20. Msg string
  21. ErrMsg string
  22. }
  23. func GetReportList(chartPermissionId, level, rangeType, currentIndex, pageSize int) (resp *ReportResp[ReportList], err error) {
  24. url := utils.ETA_MINI_BRIDGE_URL + "/report/list?"
  25. url += fmt.Sprintf("RangeType=%d&ChartPermissionId=%d&Level=%d&PageSize=%d&CurrentIndex=%d", rangeType, chartPermissionId, level, pageSize, currentIndex)
  26. fmt.Println(url)
  27. client := &http.Client{}
  28. // 提交请求
  29. req, err := http.NewRequest("GET", url, nil)
  30. if err != nil {
  31. return
  32. }
  33. nonce := utils.GetRandStringNoSpecialChar(16)
  34. timestamp := time.Now().Format(utils.FormatDateTimeUnSpace)
  35. signature := utils.GetSign(nonce, timestamp, utils.ETA_MINI_APPID, utils.ETA_MINI_APP_SECRET)
  36. //增加header选项
  37. req.Header.Add("Nonce", nonce)
  38. req.Header.Add("Timestamp", timestamp)
  39. req.Header.Add("Appid", utils.ETA_MINI_APPID)
  40. req.Header.Add("Signature", signature)
  41. req.Header.Set("Content-Type", "application/json")
  42. response, err := client.Do(req)
  43. if err != nil {
  44. return
  45. }
  46. defer response.Body.Close()
  47. body, err := io.ReadAll(response.Body)
  48. if err != nil {
  49. return
  50. }
  51. utils.FileLog.Info("result:" + string(body))
  52. err = json.Unmarshal(body, &resp)
  53. if err != nil {
  54. return resp, err
  55. }
  56. return resp, nil
  57. }
  58. func GetReportDetail(reportId, userId int) (resp *ReportResp[models.ReportDetail], err error) {
  59. url := utils.ETA_MINI_BRIDGE_URL + "/report/detail?"
  60. url += fmt.Sprintf("ReportId=%d&UserId=%d", reportId, userId)
  61. fmt.Println(url)
  62. client := &http.Client{}
  63. // 提交请求
  64. req, err := http.NewRequest("GET", url, nil)
  65. if err != nil {
  66. return
  67. }
  68. nonce := utils.GetRandStringNoSpecialChar(16)
  69. timestamp := time.Now().Format(utils.FormatDateTimeUnSpace)
  70. signature := utils.GetSign(nonce, timestamp, utils.ETA_MINI_APPID, utils.ETA_MINI_APP_SECRET)
  71. //增加header选项
  72. req.Header.Add("Nonce", nonce)
  73. req.Header.Add("Timestamp", timestamp)
  74. req.Header.Add("Appid", utils.ETA_MINI_APPID)
  75. req.Header.Add("Signature", signature)
  76. req.Header.Set("Content-Type", "application/json")
  77. response, err := client.Do(req)
  78. if err != nil {
  79. return
  80. }
  81. defer response.Body.Close()
  82. body, err := io.ReadAll(response.Body)
  83. if err != nil {
  84. return
  85. }
  86. utils.FileLog.Info("result:" + string(body))
  87. err = json.Unmarshal(body, &resp)
  88. if err != nil {
  89. return resp, err
  90. }
  91. return resp, nil
  92. }
  93. func GetReportDailyList(currentIndex, pageSize int) (resp *ReportResp[ReportList], err error) {
  94. url := utils.ETA_MINI_BRIDGE_URL + "/report/daily/list"
  95. if currentIndex >= 0 && pageSize > 0 {
  96. url += "?PageSize=" + strconv.Itoa(pageSize)
  97. url += "&CurrentIndex=" + strconv.Itoa(currentIndex)
  98. }
  99. fmt.Println(url)
  100. client := &http.Client{}
  101. // 提交请求
  102. req, err := http.NewRequest("GET", url, nil)
  103. if err != nil {
  104. return &ReportResp[ReportList]{}, err
  105. }
  106. nonce := utils.GetRandStringNoSpecialChar(16)
  107. timestamp := time.Now().Format(utils.FormatDateTimeUnSpace)
  108. signature := utils.GetSign(nonce, timestamp, utils.ETA_MINI_APPID, utils.ETA_MINI_APP_SECRET)
  109. //增加header选项
  110. req.Header.Add("Nonce", nonce)
  111. req.Header.Add("Timestamp", timestamp)
  112. req.Header.Add("Appid", utils.ETA_MINI_APPID)
  113. req.Header.Add("Signature", signature)
  114. req.Header.Set("Content-Type", "application/json")
  115. response, err := client.Do(req)
  116. if err != nil {
  117. return &ReportResp[ReportList]{}, err
  118. }
  119. defer response.Body.Close()
  120. body, err := io.ReadAll(response.Body)
  121. if err != nil {
  122. return &ReportResp[ReportList]{}, err
  123. }
  124. utils.FileLog.Info("result:" + string(body))
  125. err = json.Unmarshal(body, &resp)
  126. if err != nil {
  127. return resp, err
  128. }
  129. return resp, nil
  130. }