使用curl发送推送,数据肯定没错,但一直返回1002的错误?!


(aluzi) #1

推送内容直接拷贝官方文档中的示例,当然替换了我自己的AppKey和Master Secret,命令如下:

curl --insecure -X POST 
-v https://api.jpush.cn/v3/push 
-H "Content-Type: application/json" 
-u "2d9071115f7eae8282b163cd:9d8b515b960e4348a4a4d9ea" 
-d "{'platform':'all','audience':'all','notification':{'alert':'Hi,JPush!'}}"

返回1002,求助!

curl调试信息如下:

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 121.46.20.48...
* TCP_NODELAY set
* Connected to api.jpush.cn (121.46.20.48) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject: C=CN; ST=GuangDong; L=Shenzhen; O=Shenzhen HeXunHuaGu Information Technologies Co.Ltd; CN=*.jpu
cn
*  start date: Jul 17 00:00:00 2017 GMT
*  expire date: Jul 16 23:59:59 2020 GMT
*  issuer: C=US; O=GeoTrust Inc.; CN=GeoTrust SSL CA - G3
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Server auth using Basic with user '2d9071115f7eae8282b163cd'
* Using Stream ID: 1 (easy handle 0x812588)
> POST /v3/push HTTP/2
> Host: api.jpush.cn
> Authorization: Basic MmQ5MDcxMTE1ZjdlYWU4MjgyYjE2M2NkOjlkOGI1MTViOTYwZTQzNDhhNGE0ZDllYQ==
> User-Agent: curl/7.53.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 72
>
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
* We are completely uploaded and fine
< HTTP/2 400
< server: nginx
< date: Wed, 06 Dec 2017 10:42:00 GMT
< content-type: application/json
< x-rate-limit-limit: 600
< x-rate-limit-remaining: 599
< x-rate-limit-reset: 60
< x-jpush-msgid:
<
{"error": {"message": "Missing parameter", "code": 1002}}* Connection #0 to host api.jpush.cn left intact

(aluzi) #2

我对比过要发送的那些json数据,长度的确就是72字节,和curl输出的调试信息中的“Content-Length”一致,绝对不存在数据被截断的问题!
命令中的 2d9071115f7eae8282b163cd:9d8b515b960e4348a4a4d9ea 就是我实际的AppKey和Secret!


#3

(aluzi) #4

你说的这些全部验证过了,就是不行!

你可以直接把那个curl的命令在你的电脑上运行一下看看,整条命令就是从从你们的文档中复制来的(当然替换了AppKey和Secret),这都还有错?


#5

curl --insecure -X POST -v https://api.jpush.cn/v3/push -H “Content-Type: application/json”
-u “7d431e42dfa6a6d693ac2d04:5e987ac6d2e04d95a9d8f0d1”
-d ‘{“platform”:“all”,“audience”:“all”,“notification”:{“alert”:“Hi,JPush!”}}’

官网示例是这样的,你自己对比下吧