day_new.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/utils"
  6. "fmt"
  7. "github.com/rdlucklib/rdluck_tools/http"
  8. "time"
  9. )
  10. var (
  11. DayNewWeworkMsgRefreshUrl = utils.HongzeOpenApiHost + "/api/day_new/refresh"
  12. DayNewTranslateContentUrl = utils.HongzeOpenApiHost + "/api/day_new/translate"
  13. )
  14. type DayNewResponse struct {
  15. Code int `json:"code"`
  16. Msg string `json:"msg"`
  17. ErrMsg string `json:"err_msg"`
  18. }
  19. func DayNewWeworkMsgRefresh() (err error) {
  20. cacheKey := utils.CACHE_KEY_DAYNEW_REFRESH
  21. //设置redis 防止频繁操作
  22. if !utils.Rc.SetNX(cacheKey, 1, 1*time.Minute) {
  23. err = errors.New(fmt.Sprintf("系统处理中,请1分钟之后再试"))
  24. return
  25. }
  26. ret, err := http.Get(DayNewWeworkMsgRefreshUrl)
  27. if err != nil {
  28. return
  29. }
  30. var resp DayNewResponse
  31. err = json.Unmarshal(ret, &resp)
  32. if err != nil {
  33. return
  34. }
  35. if resp.Code != 200 {
  36. err = errors.New(resp.Msg)
  37. return
  38. }
  39. return
  40. }
  41. func DayNewTranslateContent() (err error) {
  42. cacheKey := utils.CACHE_KEY_DAYNEW_TRANSLATE
  43. //设置redis 防止频繁操作,控制每分钟执行1次
  44. if !utils.Rc.SetNX(cacheKey, 1, 1*time.Minute) {
  45. err = errors.New(fmt.Sprintf("系统处理中,请1分钟之后再试"))
  46. return
  47. }
  48. ret, err := http.Get(DayNewTranslateContentUrl)
  49. if err != nil {
  50. return
  51. }
  52. var resp DayNewResponse
  53. err = json.Unmarshal(ret, &resp)
  54. if err != nil {
  55. return
  56. }
  57. if resp.Code != 200 {
  58. err = errors.New(resp.Msg)
  59. return
  60. }
  61. return
  62. }