notify.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package dao
  2. import (
  3. "context"
  4. "errors"
  5. "net/url"
  6. "go-common/library/log"
  7. "go-common/library/xstr"
  8. )
  9. const (
  10. _notifyDataType = "4" // 消息类型:1、回复我的2、@我3、收到的爱4、业务通知
  11. _notifyURL = "/api/notify/send.user.notify.do"
  12. _notifyMC = "1_8_2"
  13. )
  14. func (d *Dao) notifyURI() string {
  15. return d.conf.Host.Message + _notifyURL
  16. }
  17. // SendNotify 发送站内信
  18. func (d *Dao) SendNotify(c context.Context, title, content string, mids []int64) (err error) {
  19. res := struct {
  20. Code int `json:"code"`
  21. Data struct {
  22. TotalCount int
  23. ErrorCount int
  24. } `json:"data"`
  25. }{}
  26. params := url.Values{}
  27. params.Set("mc", _notifyMC)
  28. params.Set("title", title)
  29. params.Set("data_type", _notifyDataType)
  30. params.Set("context", content)
  31. params.Set("mid_list", xstr.JoinInts(mids))
  32. if err = d.httpClient.Post(c, d.notifyURI(), "", params, &res); err != nil {
  33. log.Error("d.httpClient.Post(%s,%v,%d)", d.notifyURI(), params, err)
  34. return
  35. }
  36. if res.Code != 0 {
  37. err = errors.New("code != 0")
  38. log.Error("d.httpClient.Post(%s,%v,%v,%d)", d.notifyURI(), params, err, res.Code)
  39. }
  40. return
  41. }