Last active
August 29, 2015 14:02
-
-
Save beanyoung/d3ee431822e6bc8c0d0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import requests | |
# api = 'https://api.xmpush.xiaomi.com/v2/message/regid' | |
api = 'https://sandbox.xmpush.xiaomi.com/v2/message/regid' | |
secret = 'demo_secret' | |
headers = {'Authorization': 'key='+secret} | |
def xiaomi_push(registration_ids, payload): | |
session = requests.Session() | |
data = dict() | |
data.update(payload) | |
data['registration_id'] = ','.join(registration_ids) | |
req = requests.Request('post', api, headers=headers, data=data).prepare() | |
print 'body: ', req.body | |
resp = session.send(req) | |
print resp.text.encode('utf8') | |
if __name__ == '__main__': | |
payload = dict() | |
payload['title'] = 'test title' | |
payload['description'] = 'test description' | |
payload['payload'] = 'test payload' | |
payload['restricted_package_name'] = 'cn.buding.martin' | |
payload['extra.notify_effect'] = 3 | |
payload['extra.web_url'] = 'http://www.baidu.com/' | |
registration_ids = ['demo_reg_id'] | |
xiaomi_push(registration_ids, payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment