|
- 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
- 作者:totitan
- 链接:https://www.jianshu.com/p/4adb6a10a00a
- 來源:简书
- 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
复制代码
|
|