Create RefreshCDN.py
This commit is contained in:
1 file changed
+50
@@ -0,0 +1,50 @@
|
||||
from hashlib import sha1
|
||||
import hmac
|
||||
import requests
|
||||
import json
|
||||
import urllib
|
||||
import os
|
||||
|
||||
def dogecloud_api(api_path, data={}, json_mode=False):
|
||||
"""
|
||||
调用多吉云API。
|
||||
|
||||
:param api_path: 调用的 API 接口地址,包含 URL 请求参数 QueryString。
|
||||
:param data: POST 的数据,字典格式。
|
||||
:param json_mode: 数据 data 是否以 JSON 格式请求,默认为 false 则使用表单形式。
|
||||
|
||||
:return dict: 返回的数据。
|
||||
"""
|
||||
access_key = '4fa23701981899fb' # 替换为自己的 AccessKey
|
||||
secret_key = 'feea91f5781378c4e7f16da1632fc7fd' # 替换为自己的 SecretKey
|
||||
|
||||
body = ''
|
||||
mime = ''
|
||||
if json_mode:
|
||||
body = json.dumps(data)
|
||||
mime = 'application/json'
|
||||
else:
|
||||
body = urllib.parse.urlencode(data)
|
||||
mime = 'application/x-www-form-urlencoded'
|
||||
|
||||
sign_str = api_path + "\n" + body
|
||||
signed_data = hmac.new(secret_key.encode('utf-8'), sign_str.encode('utf-8'), sha1)
|
||||
sign = signed_data.digest().hex()
|
||||
authorization = 'TOKEN ' + access_key + ':' + sign
|
||||
|
||||
response = requests.post('https://api.dogecloud.com' + api_path, data=body, headers={
|
||||
'Authorization': authorization,
|
||||
'Content-Type': mime
|
||||
})
|
||||
return response.json()
|
||||
|
||||
url_list = ['https://xxxxx/'] # 替换为你的博客域名
|
||||
|
||||
api = dogecloud_api('/cdn/refresh/add.json', {
|
||||
'rtype': 'path',
|
||||
'urls': json.dumps(url_list)
|
||||
})
|
||||
if api['code'] == 200:
|
||||
print(api['data']['task_id'])
|
||||
else:
|
||||
print("API failed: " + api['msg'])
|
||||
Reference in new issue
Block a user