notify.go 1007 B

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