client_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package jpush
  2. import (
  3. "testing"
  4. "time"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestPush(t *testing.T) {
  8. Convey("test jpush", t, func() {
  9. var (
  10. ad Audience
  11. notice Notice
  12. plat = NewPlatform(PlatformAndroid)
  13. payload = NewPayload()
  14. cbr = NewCallbackReq()
  15. an = &AndroidNotice{
  16. Title: "test title",
  17. Alert: "test alert",
  18. AlertType: AndroidAlertTypeLight | AndroidAlertTypeSound, // 通知提醒类型
  19. Extras: map[string]interface{}{
  20. "task_id": "tid",
  21. "scheme": "bili:///?type=bilivideo&avid=123",
  22. },
  23. }
  24. )
  25. // ad.SetID([]string{"190e35f7e068f4a19d1"})
  26. ad.SetID([]string{""})
  27. notice.SetAndroidNotice(an)
  28. payload.SetPlatform(plat)
  29. payload.SetAudience(&ad)
  30. payload.SetNotice(&notice)
  31. payload.Options.SetTimelive(1000)
  32. payload.Options.SetReturnInvalidToken(true)
  33. cbr.SetParam(map[string]string{"task": "tid"})
  34. payload.SetCallbackReq(cbr)
  35. // bs, err := payload.ToBytes()
  36. // fmt.Printf("payload(%s) error(%v)", bs, err)
  37. cli := NewClient("62396b3e57f0b2b4b2c7bf48", "588f56e1bedd3c6b46db4863", time.Second)
  38. res, err := cli.Push(payload)
  39. So(err, ShouldBeNil)
  40. t.Logf("push result(%+v)", res)
  41. })
  42. }