WNS 后台Push服务调试脚本

一、API说明

  https://cloud.tencent.com/document/product/276/3212
 
  

二、推送脚本

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/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)

  

posted @   兜兜有糖的博客  阅读(422)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示