dw_mini.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package dwmini
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_chart_lib/models"
  6. "eta/eta_chart_lib/utils"
  7. )
  8. type MyChartIsCollect struct {
  9. IsCollect bool
  10. }
  11. type BaseResponse struct {
  12. Ret int
  13. Msg string
  14. ErrMsg string
  15. ErrCode string
  16. Data MyChartIsCollect
  17. }
  18. type MyChartIsCollectReq struct {
  19. UniqueCode string
  20. }
  21. type MyChartCollectReq struct {
  22. UniqueCode string
  23. ChartName string
  24. ChartImage string
  25. ChartInfoId int
  26. }
  27. type MyChartCollectCancelReq struct {
  28. UniqueCode string
  29. }
  30. func GetMyChartIsCollect(token string, uniqueCode string) (isCollect bool, err error) {
  31. url := utils.ETA_MINI_URL + "mychart/isCollect"
  32. req := MyChartIsCollectReq{UniqueCode: uniqueCode}
  33. reqBody, _ := json.Marshal(req)
  34. result, err := HttpPost(url, string(reqBody), token)
  35. if err != nil {
  36. return
  37. }
  38. var resp BaseResponse
  39. if err = json.Unmarshal(result, &resp); err != nil {
  40. return
  41. }
  42. if resp.Ret != 200 {
  43. err = errors.New(resp.ErrMsg)
  44. return
  45. }
  46. isCollect = resp.Data.IsCollect
  47. return
  48. }
  49. func MyChartCollect(token, uniqueCode, chartName, chartImage string, chartInfoId int) (resp *models.BaseResponse, err error) {
  50. url := utils.ETA_MINI_URL + "mychart/collect"
  51. req := MyChartCollectReq{
  52. UniqueCode: uniqueCode,
  53. ChartName: chartName,
  54. ChartImage: chartImage,
  55. ChartInfoId: chartInfoId,
  56. }
  57. reqBody, _ := json.Marshal(req)
  58. result, err := HttpPost(url, string(reqBody), token)
  59. if err != nil {
  60. return
  61. }
  62. if err = json.Unmarshal(result, &resp); err != nil {
  63. return
  64. }
  65. if resp.Ret != 200 {
  66. return
  67. }
  68. return
  69. }
  70. func MyChartCollectCancel(token string, uniqueCode string) (resp *models.BaseResponse, err error) {
  71. url := utils.ETA_MINI_URL + "mychart/collectCancel"
  72. req := MyChartCollectCancelReq{UniqueCode: uniqueCode}
  73. reqBody, _ := json.Marshal(req)
  74. result, err := HttpPost(url, string(reqBody), token)
  75. if err != nil {
  76. return
  77. }
  78. if err = json.Unmarshal(result, &resp); err != nil {
  79. return
  80. }
  81. if resp.Ret != 200 {
  82. return
  83. }
  84. return
  85. }