腾讯云cdn自动刷新api调用功能实现-python

本文介绍如何使用腾讯云CDN的自动刷新API来更新文件并自动提交刷新请求。通过具体步骤演示了如何下载官方提供的Python脚本,配置个人API密钥,并在更新脚本中集成调用API的功能,实现HTTP目录的快速刷新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[腾讯云](https://l.gushuji.site/tencent)cdn更新文件自动刷新api添加,更新文件并自动提交刷新功能。
官方脚本获取地址:https://cloud.tencent.com/document/product/228/1734
官方个人api密钥生成下载地址:https://console.cloud.tencent.com/capi  

1.从上述脚本获取地址下载,我这里下载的python版,官方地址:https://mc.qcloudimg.com/static/archive/e1b2f9d047705f235d3591e4e7bc7012/python.zip
将解压出的脚本文件QcloudCdnTools_V2.py放在服务器某个目录中用于调用,我这里放在/root/tools/scripts/下。

2.在更新脚本中添加调用api段    

vi tools/scripts/change_txjn.py 

!/use/bin/env python

# -- coding:utf-8 --

import sys,os,re

if len(sys.argv) != 2:
print ‘argv Error! Usage:%s (file|statusZ) (type|txjj|txpp)’%(sysy.argv[0])
sys.exit()

GAME_DIR = ‘/data/test/xclient_unpack/launchercfg/’
START_DIR = ‘/root/tools/scripts/new_serverlist/’
STOP_DIR = ‘/root/tools/scripts/old_serverlist/’
STATUS = sys.argv[1].strip()

def jjstop():
cmd1 = “cp -p -f %s/appleaddr.dat %s”%(GAME_DIR,START_DIR)
cmd2 = “cp -p -f %s/appleaddr.dat %s”%(STOP_DIR,GAME_DIR)
os.popen(cmd1)
os.popen(cmd2)
print “::::::::::::::::::::: \n change stop ipconfig success! \n::::::::::::::::::::”

def jjstart():
cmd = “cp -rp %s/appleaddr.dat %s”%(START_DIR,GAME_DIR)
os.popen(cmd)
print “::::::::::::::::::::: \n change start ipconfig success! \n::::::::::::::::::::”

def flushtxcdn(): #api调用,这里需要个人api密钥SecretId和SecretKey
flushcmd = “/usr/bin/python /root/tools/scripts/QcloudCdnTools_V2.py RefreshCdnDir -u SecretId -p SecretKey –dirs http://aaa.com/ > /dev/null 2>&1”
os.popen(flushcmd)
print “::::::::::::::::::::: \n flush cdndir=http://aaa.com/ success! \n::::::::::::::::::::”

if re.search(‘start’,STATUS):
jjstart()
flushtxcdn()
elif re.search(‘stop’,STATUS):
jjstop()
flushtxcdn()
else:
print ‘Status Type Error!’

3.使用方法

[root@JJ-TXGZ01-FTPServer ~]# cd tools/scripts/
[root@JJ-TXGZ01-FTPServer scripts]# python change_txjn.py stop
s:::::::::::::::::::::
change stop ipconfig success!
::::::::::::::::::::
:::::::::::::::::::::
flush cdndir=http://aaa.com/ success!
::::::::::::::::::::
[root@JJ-TXGZ01-FTPServer scripts]# python change_txjn.py start
:::::::::::::::::::::
change start ipconfig success!
::::::::::::::::::::
:::::::::::::::::::::
flush cdndir=http://aaa.com/ success!
::::::::::::::::::::

这里http://aaa.com/为所需刷新的cdn目录,自行定义,如需有其他需求,官方参考文档:https://cloud.tencent.com/document/api/228/1723

                                                        --binghan li
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值