zoukankan      html  css  js  c++  java
  • 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("
    请求:")
        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)
    

      

  • 相关阅读:
    线性Softmax分类器实战
    线性SVM分类器实战
    今日心得:读书
    今日心得:正能量
    Excel导出POI
    mysql数据库操作命令
    git常用命令
    list对象 利用Map去除对象中字段的重复
    SpringMVC 利用POI的Excel导出
    利用ajax进行页面加载进行信息展示时,一直不提加载,转圈,不反回问题。
  • 原文地址:https://www.cnblogs.com/doudouyoutang/p/10246676.html
Copyright © 2011-2022 走看看