api.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package newcomer
  2. import (
  3. "context"
  4. "errors"
  5. "net/url"
  6. "go-common/library/log"
  7. "go-common/library/xstr"
  8. )
  9. // SendNotify send msg notify user
  10. func (d *Dao) SendNotify(c context.Context, mids []int64, mc, title, context string) (err error) {
  11. var (
  12. params = url.Values{}
  13. res struct {
  14. Code int `json:"code"`
  15. Msg string `json:"msg"`
  16. Data *struct {
  17. TotalCount int `json:"total_count"`
  18. ErrorCount int `json:"error_count"`
  19. ErrorMidList []int64 `json:"error_mid_list"`
  20. } `json:"data"`
  21. }
  22. )
  23. params.Set("mc", mc) //消息码,用于识别消息类别
  24. params.Set("data_type", "4") //消息类型:1、回复我的 2、@我 3、收到的爱 4、业务通知 5、系统公告
  25. params.Set("title", title) //消息标题
  26. params.Set("context", context) //消息实体内容
  27. params.Set("mid_list", xstr.JoinInts(mids)) //用于接收该消息的用户mid列表,不超过1000个(半角逗号分割)
  28. log.Info("SendNotify params(%+v)|msgURI(%s)", params.Encode(), d.msgURI)
  29. if err = d.httpClient.Post(c, d.msgURI, "", params, &res); err != nil {
  30. log.Error("d.httpClient.Post(%s,%v,%d)", d.msgURI, params, err)
  31. return
  32. }
  33. if res.Code != 0 {
  34. err = errors.New("code != 0")
  35. log.Error("d.httpClient.Post(%s,%v,%v,%d)", d.msgURI, params, err, res.Code)
  36. }
  37. if res.Data != nil {
  38. log.Info("SendNotify log total_count(%d) error_count(%d) error_mid_list(%v)", res.Data.TotalCount, res.Data.ErrorCount, res.Data.ErrorMidList)
  39. }
  40. return
  41. }