IOS使用新的HTTP2 api测试推送,APNs推送的测试工具

工具项目地址

github

https://github.com/wardenlym/apns2-test

工具安装

参考项目描述编译安装即可工具(很简单,直接make就可以)
如有报错,根据错误提示解决即可。
我编译时遇到autoconf版本低(2.63)导致编译失败的问题,后面升级下autoconf就好了,我是升级到2.68

工具使用介绍

用法

最简用法,只有2个必须参数: 证书,要推送设备的token。

./apns2-test -cert <cert.pem> -token
然后设备就会收到一条 "apns2 test." 的默认测试信息。

可选参数

-dev 开发环境,默认推生产环境
-debug 详细的日志了连接过程和HTTP请求过程
-topic 不填的话,从证书里面取UID,默认就是应用的bundle-id
-message 自定义一个消息内容,比较常用,替换的是alert字段
example: -message "abc test."
-payload 如果你对payload中的字段需要详细的指定,这个选项跟-message冲突,不应该同时设置(废话。。。),如果都设置,以-payload为准。
example: -payload '{"aps":{"alert":"payload test.","sound":"default"}}'

还有些没什么太大用的选项,但也留出来方便些:

-uri 如果你有特别的代理,可以用来替换苹果默认的域名,这个如果设置了,默认覆盖生产开发选项。你指定哪个地址就推哪个。
-port 如果你要设定端口,默认苹果端口是2197
-prefix 这个一般不用改吧。协议里的header前缀 /3/device/
-pkey 如果需要指定一个私钥文件,正常来说,证书与私钥都在一个pem文件里。默认都从pem里面读取

效果

debug效果

[root@local-vm apns2-test]# ./apns2-test -cert /tmp/test_dev.pem -token 167f86c48b3418cbe45ff3bfe51f4d504df456d1110a77de0dfb5576294b758e -debug -dev
6 -dev
notBefore : 190225060336Z
notAfter  : 200225060336Z
UID = com.test [23]

apns2-test version: 0.1.1
nghttp2 version: 1.9.0-DEV
tls/ssl version: TLSv1.2
ns looking up ...
connecting to : 17.188.165.219
socket connect ok: fd=3, host: api.development.push.apple.com:2197
Enter PEM pass phrase:
ssl allocation ok
ssl handshaking ...
Connected with encryption: ECDHE-RSA-AES256-GCM-SHA384
ssl handshake ok
[INFO] Stream ID = 1
[INFO] C ----------------------------> S (HEADERS)
:method: POST
:path: /3/device/167f86c48b3418cbe45ff3bfe51f4d504df456d1110a77de0dfb5576294b758e
apns-topic: com.test
[INFO] C ----------------------------> S (DATA post body)
{"aps":{"alert":"apns2 test.","sound":"default"}}

[INFO] C <---------------------------- S (HEADERS begin)
:status: 200
apns-id: D63E10AF-D391-9958-6C70-92CC5759204B
[INFO] C <---------------------------- S (HEADERS end)
[INFO] C ----------------------------> S (GOAWAY)
over.

debug消息如上,能看到

  • {"aps":{"alert":"apns2 test.","sound":"default"}}
    推送的消息内容,可以用message参数指定
  • :status: 200 (推送结果,对照如下)
Status code Description
200 Success
400 Bad request
403 There was an error with the certificate or with the provider authentication token
405 The request used a bad :method value. Only POST requests are supported.
410 The device token is no longer active for the topic.
413 The notification payload was too large.
429 The server received too many requests for the same device token.
500 Internal server error
503 The server is shutting down and unavailable.

结束

项目中有时排查推送问题,自己单个推送调试排查问题还是很不错的

posted @ 2019-06-27 17:54  JaminX86  阅读(1415)  评论(0编辑  收藏  举报