Created
August 27, 2021 05:22
-
-
Save kang8/df7758b6fb0923470381d4732403322e to your computer and use it in GitHub Desktop.
使用 python3 生成签名并发送友盟消息推送
This file contains hidden or 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
import calendar | |
import time | |
import json | |
import hashlib | |
import requests | |
def md5(s): | |
m = hashlib.md5(s.encode(encoding="utf-8")) | |
return m.hexdigest() | |
appkey = "your appkey" | |
app_master_secret ="your app_master_secret" | |
# generate timstamp with 10 digits | |
timestamp = calendar.timegm(time.gmtime()) | |
method ="POST" | |
url ="https://msgapi.umeng.com/api/send" | |
broadcast = { | |
"payload": { | |
"display_type": "notification", | |
"body": { | |
"after_open": "go_app", | |
"text": "text message", | |
"title": "title message" | |
} | |
}, | |
"appkey": appkey, | |
"type": "broadcast", | |
"timestamp": timestamp | |
} | |
post_body = json.dumps(broadcast) | |
sign = md5("%s%s%s%s"%(method,url,post_body,app_master_secret)) | |
req = requests.post(url, data = post_body, params={"sign": sign}) | |
# response body | |
print(req.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment