client_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package mi
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "testing"
  7. "time"
  8. "go-common/app/service/main/push/model"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. func Test_Push(t *testing.T) {
  12. Convey("push mi", t, func() {
  13. xmm := &XMMessage{
  14. Payload: "bili:///?type=bililive&roomid=33886",
  15. RestrictedPackageName: "tv.danmaku.bili",
  16. PassThrough: 0, // 0 表示通知栏消息1 表示透传消息
  17. Title: model.DefaultMessageTitle,
  18. Description: "直播推荐",
  19. NotifyType: NotifyTypeDefaultAll,
  20. TaskID: "vdsfdfs", // 每次不能相同,相同的只会推一次
  21. }
  22. // 设置是否被覆盖,不同的数字,可显示多行
  23. xmm.SetNotifyID(xmm.TaskID)
  24. xmm.SetCallbackParam("1")
  25. xmm.SetRegID("device token")
  26. // xmm.SetRegID("qlRyXrBPQ8ZkTg3x46hvTz3g8Oe/Fyz93XnE5U2NxRk=")
  27. // xmm.SetUserAccount("15678567,25668444")
  28. client := NewClient("tv.danmaku.bili", "QlcVxtNh6j7BXBPXjcbGoQ==", time.Hour)
  29. // client.SetProductionURL(AccountURL)
  30. client.SetVipURL(RegURL)
  31. resp, err := client.Push(xmm)
  32. So(err, ShouldBeNil)
  33. So(resp.Code, ShouldEqual, ResultCodeNoValidTargets)
  34. if resp.Result == ResultOk {
  35. tt := strings.Split(resp.Info, " ")
  36. if len(tt) == 6 {
  37. m, _ := strconv.Atoi(tt[4])
  38. fmt.Println(m + 1)
  39. }
  40. }
  41. t.Logf("push xiaomi res(%+v)", resp)
  42. // success: &{Result:ok Reason: Code:0 Data:{ID:scm01b20510561935064bK List:[]} Description:成功 Info:Received push messages for 1 REGID}
  43. // failed: &{Result:error Reason:No valid targets! Code:20301 Data:{ID: List:[]} Description:发送消息失败 Info:}
  44. })
  45. }
  46. // 需要测的时候再打开,因为失效token获取完了就没了
  47. // func Test_InvalidTokens(t *testing.T) {
  48. // client := NewClient("tv.danmaku.bili", "QlcVxtNh6j7BXBPXjcbGoQ==", time.Hour)
  49. // client.SetFeedbackURL()
  50. // resp, err := client.InvalidTokens()
  51. // if err != nil {
  52. // t.Log(err)
  53. // t.FailNow()
  54. // }
  55. // t.Log(resp)
  56. // }
  57. // 需要测的时候再打开,因为卸载token获取完了就没了
  58. // func Test_UninstalledTokens(t *testing.T) {
  59. // client := NewClient("tv.danmaku.bili", "QlcVxtNh6j7BXBPXjcbGoQ==", time.Hour)
  60. // resp, err := client.UninstalledTokens()
  61. // if err != nil {
  62. // t.Log(err)
  63. // t.FailNow()
  64. // }
  65. // t.Log(resp)
  66. // }