http.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package block
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strings"
  7. "go-common/library/ecode"
  8. "github.com/pkg/errors"
  9. )
  10. // SendSysMsg send sys msg.
  11. func (d *Dao) SendSysMsg(c context.Context, code string, mids []int64, title string, content string, remoteIP string) (err error) {
  12. params := url.Values{}
  13. params.Set("mc", code)
  14. params.Set("title", title)
  15. params.Set("data_type", "4")
  16. params.Set("context", content)
  17. params.Set("mid_list", midsToParam(mids))
  18. var res struct {
  19. Code int `json:"code"`
  20. Data *struct {
  21. Status int8 `json:"status"`
  22. Remark string `json:"remark"`
  23. } `json:"data"`
  24. }
  25. if err = d.client.Post(c, d.c.BlockProperty.MSGURL, remoteIP, params, &res); err != nil {
  26. err = errors.WithStack(err)
  27. return
  28. }
  29. if res.Code != 0 {
  30. err = errors.WithStack(ecode.Int(res.Code))
  31. return
  32. }
  33. return
  34. }
  35. func midsToParam(mids []int64) (str string) {
  36. strs := make([]string, 0, len(mids))
  37. for _, mid := range mids {
  38. strs = append(strs, fmt.Sprintf("%d", mid))
  39. }
  40. return strings.Join(strs, ",")
  41. }