WNS 后台Push服务调试脚本
一、API说明
https://cloud.tencent.com/document/product/276/3212二、推送脚本
#!/usr/local/bin/python3 # -*- coding: utf-8 -*- __author__ = 'qqvipfunction' import hmac from hashlib import sha1 import urllib.parse import urllib.request import json import base64 import time appid = "wns appid 腾讯云后台注册" secretid = "wns secretid 腾讯云后台注册" secretkey = "wns secretkey 腾讯云后台注册" #https://cloud.tencent.com/document/product/276/3212 ip = "wns.api.qcloud.com" def hash_hmac2(code, key, sha1): hmac_code = hmac.new(key.encode(), code.encode(), sha1).digest() return base64.b64encode(hmac_code).decode() def test_push(tm, uid, plat, tag, content): print("\n请求:") plaintext = str(appid) + "&" + str(tm) sign = hash_hmac2(plaintext, secretkey, sha1) body = {"appid":appid, "secretid":secretid, "sign":sign, "tm":tm, "uid":uid, "plat":plat, "tag":tag, "content":content} myurl = "http://" + ip + "/api/send_msg_new" encodeBody = urllib.parse.urlencode(body) print("%s?%s" % (myurl, encodeBody)) response = urllib.request.urlopen(myurl, encodeBody.encode()) # response = urllib.request.urlopen("%s?%s" % (myurl, encodeBody)) # page = response.read() page = page.decode('utf-8') print("返回:") print(page)