美文网首页
GCM测试Python脚本

GCM测试Python脚本

作者: totitan | 来源:发表于2017-09-19 18:26 被阅读0次

Android开发中经常需要测试GCM发送推送的情况,下面提供Python脚本来模拟推送过程。

#!/usr/bin/env python
# coding=utf8

import urllib2
import json

# 你的应用serverKey
serverKey = '*******************'

# 要推送手机的GCM token
device_token = "********************"
url = 'https://gcm-http.googleapis.com/gcm/send'
headers = {"Content-type": "application/json",
           "Authorization": "key=" + serverKey
           }
# 推送协议接口
data = {
    "to": device_token,
    "priority": "normal",
    # "delay_while_idle": True,
    # "time_to_live": 3600,
    "data": {
        # TODO 你的应用定义的推送协议接口
     }
}
req = urllib2.Request(url, json.dumps(data), headers)
response = urllib2.urlopen(req)
print  response
compressedData = response.read()
print compressedData

相关文章

网友评论

      本文标题:GCM测试Python脚本

      本文链接:https://www.haomeiwen.com/subject/wdrgsxtx.html