message.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. "go-common/library/xstr"
  8. "github.com/pkg/errors"
  9. )
  10. const (
  11. _msgURL = "/api/notify/send.user.notify.do"
  12. )
  13. // Message send message.
  14. func (d *Dao) Message(c context.Context, title, msg string, mids []int64) (err error) {
  15. return d.RawMessage(c, "2_2_2", title, msg, mids)
  16. }
  17. // RawMessage send message with mc.
  18. func (d *Dao) RawMessage(c context.Context, mc string, title, msg string, mids []int64) (err error) {
  19. params := url.Values{}
  20. params.Set("type", "json")
  21. params.Set("source", "2")
  22. params.Set("mc", mc)
  23. params.Set("title", title)
  24. params.Set("data_type", "4")
  25. params.Set("context", msg)
  26. params.Set("mid_list", xstr.JoinInts(mids))
  27. var res struct {
  28. Code int `json:"code"`
  29. }
  30. if err = d.httpClient.Post(c, d.msgURL, "", params, &res); err != nil {
  31. err = errors.Wrap(err, "dao send message")
  32. return
  33. }
  34. if res.Code != ecode.OK.Code() {
  35. err = errors.Wrapf(err, "message send failed,mid(%v)", mids)
  36. return
  37. }
  38. log.Info("sendmessage mc:%s, mids:%v, title:%s, msg:%s", mc, mids, title, msg)
  39. return
  40. }