GCM测试Python脚本

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脚本)