message.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. var _notify = "4"
  10. // SendMessage .
  11. func (d *Dao) SendMessage(c context.Context, tid, mid, aid int64, title, msg string) (err error) {
  12. params := url.Values{}
  13. params.Set("mid_list", strconv.FormatInt(mid, 10))
  14. params.Set("title", title)
  15. params.Set("mc", d.c.Message.MC)
  16. params.Set("data_type", _notify)
  17. params.Set("context", msg)
  18. params.Set("notify_type", strconv.FormatInt(tid, 10))
  19. params.Set("res_id", strconv.FormatInt(aid, 10))
  20. var res struct {
  21. Code int `json:"code"`
  22. }
  23. err = d.messageHTTPClient.Post(c, d.c.Message.URL, "", params, &res)
  24. if err != nil {
  25. PromError("message:send接口")
  26. log.Error("d.client.Post(%s) error(%+v)", d.c.Message.URL+"?"+params.Encode(), err)
  27. return
  28. }
  29. if res.Code != 0 {
  30. PromError("message:send接口")
  31. log.Error("url(%s) res code(%d)", d.c.Message.URL+"?"+params.Encode(), res.Code)
  32. err = ecode.Int(res.Code)
  33. return
  34. }
  35. log.Info("发送点赞消息通知 (%s) error(%+v)", d.c.Message.URL+"?"+params.Encode(), err)
  36. return
  37. }