蛋蛋星球-制度模式
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client_push.go 1.3 KiB

4 週之前
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package jpush
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "strconv"
  6. )
  7. func (c *Client) Push(push *PushRequest) (map[string]interface{}, error) {
  8. link := c.pushUrl + "/v3/push"
  9. buf, err := json.Marshal(push)
  10. if err != nil {
  11. return nil, err
  12. }
  13. resp, err := c.request("POST", link, bytes.NewReader(buf), false)
  14. if err != nil {
  15. return nil, err
  16. }
  17. return resp.Map()
  18. }
  19. func (c *Client) GetCidPool(count int, cidType string) (map[string]interface{}, error) {
  20. link := c.pushUrl + "/v3/push/cid?"
  21. if count > 0 {
  22. link += "count=" + strconv.Itoa(count)
  23. }
  24. if cidType != "" {
  25. link += "type=" + cidType
  26. }
  27. resp, err := c.request("GET", link, nil, false)
  28. if err != nil {
  29. return nil, err
  30. }
  31. return resp.Map()
  32. }
  33. func (c *Client) GroupPush(push *PushRequest) (map[string]interface{}, error) {
  34. link := c.pushUrl + "/v3/grouppush"
  35. buf, err := json.Marshal(push)
  36. if err != nil {
  37. return nil, err
  38. }
  39. resp, err := c.request("POST", link, bytes.NewReader(buf), true)
  40. if err != nil {
  41. return nil, err
  42. }
  43. return resp.Map()
  44. }
  45. func (c *Client) Validate(req *PushRequest) (map[string]interface{}, error) {
  46. link := c.pushUrl + "/v3/push/validate"
  47. buf, err := json.Marshal(req)
  48. if err != nil {
  49. return nil, err
  50. }
  51. resp, err := c.request("POST", link, bytes.NewReader(buf), false)
  52. if err != nil {
  53. return nil, err
  54. }
  55. return resp.Map()
  56. }