push.go 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. package service
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. pushmdl "go-common/app/service/main/push/model"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _testTokenURL = "http://api.bilibili.co/x/internal/push-service/test/token"
  11. )
  12. // TestToken for test via push token.
  13. func (s *Service) TestToken(ctx context.Context, info *pushmdl.PushInfo, token string) (err error) {
  14. params := url.Values{}
  15. params.Add("app_id", strconv.FormatInt(info.APPID, 10))
  16. params.Add("alert_title", info.Title)
  17. params.Add("alert_body", info.Summary)
  18. params.Add("token", token)
  19. params.Add("link_type", strconv.FormatInt(int64(info.LinkType), 10))
  20. params.Add("link_value", info.LinkValue)
  21. params.Add("sound", strconv.Itoa(info.Sound))
  22. params.Add("vibration", strconv.Itoa(info.Vibration))
  23. params.Add("expire_time", strconv.FormatInt(int64(info.ExpireTime), 10))
  24. params.Add("image_url", info.ImageURL)
  25. if err = s.httpClient.Post(ctx, _testTokenURL, "", params, nil); err != nil {
  26. log.Error("s.TestToken(%+v) error(%v)", info, err)
  27. }
  28. return
  29. }