message.go 962 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. // consts
  10. const (
  11. notifyURL = "http://message.bilibili.co/api/notify/send.user.notify.do"
  12. dataType = "4"
  13. source = "2"
  14. )
  15. // SendMessage is
  16. func (d *Dao) SendMessage(c context.Context, mid int64, title, msg, mc string) (err error) {
  17. var (
  18. params = url.Values{}
  19. )
  20. params.Set("mid_list", fmt.Sprintf("%d", mid))
  21. params.Set("mc", mc)
  22. params.Set("data_type", dataType)
  23. params.Set("source", source)
  24. params.Set("context", msg)
  25. params.Set("title", title)
  26. var resp struct {
  27. Code int `json:"code"`
  28. }
  29. log.Info("SendMessage() params(%v)", params)
  30. if err = d.client.Post(c, notifyURL, "", params, &resp); err != nil {
  31. log.Error("d.client.Post(%s,%+v) error(%v)", notifyURL, params, err)
  32. return
  33. }
  34. if resp.Code != 0 {
  35. err = ecode.Int(resp.Code)
  36. log.Error("d.client.Post(%s,%+v) resp.Code(%d)", notifyURL, params, resp.Code)
  37. }
  38. return
  39. }