《使用第三方推送平臺JPUSH推送消息到android手機》文章里測試消息推送是在頁面上執行的,而現在我需要從路由器上把消息推送出去,打開Jpush API文檔,有curl示例命令
參照示例命令,寫一個針對自己應用的最簡單的測試命令,-u后面的參數是自己應用的AppKey和 Master secret,‘Hi,JPush’是要推送的消息內容
[html] view plain copy在路由器上執行這個命令的時候會出錯如下錯誤,證書驗證失敗,其實是因為curl沒有指定證書,這個證書需要到curl官網下載
下載下來后,通過--cacert參數指定
[html] view plain copypython代碼如下
#!/usr/bin/env python# -*- coding: utf-8 -*- import subPRocessimport json def push_msg(msg): content = {"platform":"all","audience":"all", "notification":{"alert":msg}} print content json_str = json.dumps(content) print json_str cmd = "curl -X POST --cacert /etc/ssl/certs/ca-certificates.crt -v https://api.jpush.cn/v3/push/ -H /"Content-Type: application/json/" -u /"xxx:xxx/"" curl_cmdline = '%s -d /'%s/''%(cmd,json_str) print curl_cmdline rc = subprocess.call(curl_cmdline, shell=True);
新聞熱點
疑難解答