· 6 years ago · Jan 07, 2020, 02:16 PM
1# 腾讯云api获取域名列表
2
3import hmac
4import hashlib
5import json
6import requests
7import time
8from hashlib import sha1
9import base64
10from urllib.parse import quote
11with open("config.json") as config_file:
12 config = json.load(config_file)
13uri = "cns.api.qcloud.com/v2/index.php?"
14SecretId = config["SecretId"]
15SecretKey = config["SecretKey"]
16
17# 所需要的参数
18param_dict = {
19 "Action": "DomainList",
20 "Nonce": "233333",
21 "SecretId": SecretId,
22 "Timestamp": str(int(time.time()))
23
24}
25
26# 生成请求字符串
27result_str = ("Action=" + param_dict["Action"]
28 + "&Nonce="+param_dict["Nonce"]
29 + "&SecretId="+param_dict["SecretId"]
30 + "&Timestamp="+param_dict["Timestamp"]
31 )
32
33# 拼接签名原文字符串
34requestStr = "GET"+uri+result_str
35
36# 签名
37signStr = requestStr.encode("UTF-8")
38SecretKey = SecretKey.encode("UTF-8")
39hashed = hmac.new(SecretKey, signStr, sha1).hexdigest()
40
41# base64加密,同时进行URL编码
42base64Data = quote(base64.b64encode(hashed.encode("utf-8")))
43
44data = requests.get("https://"+uri+result_str+"&Signature="+base64Data).text
45print(data)