http.go 1.0 KB

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