push.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package bnj
  2. import (
  3. "context"
  4. "net/url"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. "go-common/library/xstr"
  8. )
  9. const (
  10. _opt = "1004"
  11. _platform = "web"
  12. _broadURL = "/x/internal/broadcast/push/all"
  13. _messageURL = "/api/notify/send.user.notify.do"
  14. _notify = "4"
  15. )
  16. // PushAll broadcast push all
  17. func (d *Dao) PushAll(c context.Context, msg string) (err error) {
  18. params := url.Values{}
  19. params.Set("operation", _opt)
  20. params.Set("platform", _platform)
  21. params.Set("message", msg)
  22. var res struct {
  23. Code int `json:"code"`
  24. }
  25. if err = d.client.Post(c, d.broadcastURL, "", params, &res); err != nil {
  26. log.Error("PushAll url(%s) error(%v)", d.broadcastURL+"?"+params.Encode(), err)
  27. return
  28. }
  29. if res.Code != ecode.OK.Code() {
  30. err = ecode.Int(res.Code)
  31. }
  32. return
  33. }
  34. // SendMessage send system notify.
  35. func (d *Dao) SendMessage(c context.Context, mids []int64, mc, title, msg string) (err error) {
  36. params := url.Values{}
  37. params.Set("mid_list", xstr.JoinInts(mids))
  38. params.Set("title", title)
  39. params.Set("mc", mc)
  40. params.Set("data_type", _notify)
  41. params.Set("context", msg)
  42. var res struct {
  43. Code int `json:"code"`
  44. }
  45. err = d.client.Post(c, d.messageURL, "", params, &res)
  46. if err != nil {
  47. log.Error("SendMessage d.client.Post(%s) error(%+v)", d.messageURL+"?"+params.Encode(), err)
  48. return
  49. }
  50. if res.Code != 0 {
  51. log.Error("SendMessage url(%s) res code(%d)", d.messageURL+"?"+params.Encode(), res.Code)
  52. err = ecode.Int(res.Code)
  53. }
  54. return
  55. }