文档中心 API文档 修改时间戳防盗链

修改时间戳防盗链

更新时间:2022-12-02 10:47:22

适用产品

网页加速、下载分发、动态加速、全站加速、点播分发、直播分发、上传加速、移动加速、上网加速、S-P2P、PCDN、应用性能管理、WEB应用防火墙、BotGuard爬虫管理、WSS、DMS、DDoS云清洗、IPv6一体化解决方案、电商安全加速解决方案、金融安全加速解决方案、政企安全加速解决方案、应用安全解决方案、区块链安全加速解决方案、IPv6安全加速解决方案

接口描述

修改时间戳防盗链

调用频率

单用户调用频率:300/5min

推荐使用 Open API在线调试

Open API在线调试功能提供可视化界面在线调试API、支持生成代码示例、快速检索查看API文档等能力。前往调试

请求参数

Path 参数

参数名称类型必填描述
domain
String需要查询配置的域名或域名id

Body 参数

参数名称类型必填描述
timestamp-visit-control-rule
Object时间戳防盗链设置 注意: 1、时间戳防盗链分为两部分,一部分是防盗链校验,一部分是时间有效性校验。二者都有效,则防盗链通过,否则不通过。 2、防盗链校验:加密算法为md5sum,按照参与MD5计算的参数及组合顺序进行防盗链加密串的计算,对匹配目录下所有文件的url进行防盗链校验,未匹配到的url,则拒绝访问。 3、时间有效性检验:按照年月日时分秒换算的当前时间,与请求url中所带的名文时间相减,判断是否超过设置的上下限(即前后60s内),时间差小于设置上下限的,系统才会给予正常的响应,否则拒绝请求,返回403 4、日志记录没有带加密串的url 6、需要清空时间戳防盗链规则时,可以只传入节点
path-pattern
Stringurl匹配模式,支持正则,如果是全部匹配,入参可以配置为:.* 对匹配到的URL进行时间戳防盗链验证;未匹配到的URL,则拒绝。
except-path-pattern
String例外的url匹配模式,某些URL除外:如abc.jpg,不做防盗链
protocol-of-path-pattern
String可选值为: http、https、http;https、noprefix、空。为空默认为"http;https";为noprefix表示不指定url的协议前缀,仅按path-pattern的正则匹配。本配置项只与path-pattern(url匹配模式)结合匹配。 例子: 1、指定protocol-of-path-pattern=https,path-pattern=.*,则匹配所有https的请求,不匹配http的请求。 2、指定protocol-of-path-pattern=http;https,path-pattern=.*,则匹配所有http和https的请求。 3、指定protocol-of-path-pattern=noprefix,path-pattern=^http://[^/]+/.*,则匹配所有http的请求,不匹配https的请求。
directory
String目录,多个以英文分号隔开。对于匹配到的目录进行时间戳防盗链验证;未匹配到的则拒绝。和path-pattern互斥。
allowed-ips
String例外的IP,支持输入IP或IP段,IP段之间用分号(;)隔开,如1.1.1.0/24;2.2.2.2,某些IP例外,不做防盗链
ignore-uri-slash
String防盗链中的$uri是否去掉/,可选值为true、false,默认为false,即包含/。 例如: http://www.test.com/1.flv,则$uri默认为/1.flv,若ignore-uri-slash为true,则$uri为1.flv
ignore-key-and-time-position
Stringkey与time是否允许互换,可选值为true和false,true则允许,false则不允许。默认情况下,密钥参数和时间参数的顺序,必须严格参照鉴权模式要求的顺序,即,默认key和time不能互换位置。如选择true,key和time位置可以互换并鉴权成功。
encrypt-method
String加密算法 当前支持入参:md5sum
cipher-combination
String防盗链生成方式,参与MD5计算的参数及组合顺序,仅支持传入以下参数: $uri:介于domain和问号之间的字符串 例如http://cdn.example.com/v0/test.dat?k=v,则URI为/v0/test.dat $ourkey:秘钥,实际秘钥在入参中配置 $time:时间串 $spec_name:文件名 例如:http://cdn.example.com/v0/test.dat?k=v,文件名为 test.dat $args:QUERY_STRING中的某个具体key的值 示例:$uri$ourkey$time$args{k} 注意: 1、$args{k}中的K只允许A-Z大小写字母、数字、下划线、横杠 2、除了$args外,其它参数只允许出现1次 3、可以按照任意组合顺序,拼接各个参数
secret-key
String防盗链加密串的秘钥,只允许传入一个秘钥 示例:abcdef 注意: 1、与客户约定好的秘钥,入参中的某个值可以等于对应的值 2、$ourkey值主要是来自的配置 a)如果不是multiple-secret-keys>中的某个值,则$ourkey值取 b)是multiple-secret-keys>中的某个值,则$ourkey值取 c)如果没有传或者空值,则$ourkey值取
cipher-param
String防盗链串的参数名称 示例:keyname 注意: 1、如果防盗链加密串是在url问号后的参数中,则防盗链加密串的参数名由的配置决定; 2、如果为空,则默认请求的url中使用key作为参数名
time-param
String时间串的参数名称 示例:tname 注意: 1、如果防盗链时间串是放在url问号后面的参数中,则防盗链时间串的参数名由的配置决定; 2、如果为空,则默认请求的url中使用time作为参数名
lower-limit-expiry-time
Integer防盗链串的过期时间下限 示例: 200 对应各种场景的配置方式如下: 注意: 1、请求URL中携带的时间戳如果是URL的生成时间,需要加上有效时长才是过期时间,即配置为有效时长。 2、如果URL携带的时间戳是过期时间,则可以配成零。
upper-limit-expiry-time
Integer防盗链串的过期时间上限 示例: 5000 对应各种场景的配置方式如下: 注意: 1、请求URL中携带的时间戳如果是URL的生成时间,需要加上有效时长才是过期时间,即配置为有效时长。 2、如果URL携带的时间戳是过期时间,则可以配成零。
multiple-secret-keys
String防盗链加密串,支持多个加密串,多个加密串以分号(;)隔开 示例:abcdef;uvwxyz 注意: 1、支持对url 防盗链设置多个密钥。支持客户任意修改密钥,并做到无缝切换。防盗链等级更高。 2、请求url的key只要跟其中任意一个加密串算出来的key一致就验证通过
time-format
String防盗链加密串时间格式,可多选,以分号(;)分隔 年|月|日|时|分|秒|UNIX时间戳|16进制时间戳:1Y;2m;3d;4H;5M;6S;7s;8x 示例:1Y;2m;3d;4H;5M;6S;7s;8x1Y;2m;3d;4H;5M;7s 注意: 1、必须是英文字母和数字 2、每个值只能出现1次 3、如果配置的是16进制时间戳,则需要同时入参:UNIX时间戳|16进制时间戳
request-url-style
String防盗链请求url格式,支持两种防盗链方式,即加密串和时间戳放到“?”后面或者是加密串和时间戳放到“host”后面,url格式支持的参数如下: $domain:域名 $uri:不包含域名的url部分 $key:防盗链加密串的MD5值 $time:防盗链时间串 $args:问号后的QUERY_STRING参数 示例:支持以下请求url格式,可替换为https://,url请求协议根据实际使用,如不知道如何正确配置,请找客户技术支持协助;携带加密串和时间串两个值的参数名“keyname”和“tname”,可替换为实际使用的参数名 http://$domain/$key/$time/$uri?$args http://$domain/$time/$key/$uri?$args http://$domain/$uri?auth_key=$key http://$domain/$uri?keyname=$key&tname=$time http://$domain/$uri?$args&keyname=$key&tname=$time http://$domain/$uri?keyname=$key&tname=$time&$args http://$domain/$uri?$args&keyname=$key&tname=$time&$args http://$domain/$uri?tname=$time&keyname=$key http://$domain/$uri?$args&tname=$time&keyname=$key http://$domain/$uri?tname=$time&keyname=$key&$args http://$domain/$uri?$args&tname=$time&keyname=$key&$args 注意: 1、输入的url必须以“http/https”开头 2、如果加密串和时间戳是放到“?”后面时,keyname和tname必须跟配置的值一致 3、如果没有配置值,则$key对应的参数名默认为key,$time对应的参数名默认为time 4、如果防盗链加密串和时间串在url问号后面的参数中,url中的“keyname”和“tname”,对应的是cipher-param和 time-param配置的防盗链串和时间串参数名称。
dst-style
Integer防盗链回源方式,可选值:1(使用未加密url回源)、2(使用客户请求带加密串url回源) 示例:1 注意: 1、如果URL格式是:http://www.xxx.com/md5/time/uri?参数,则需要下工单给对应客服,让客服在父配置去掉时间戳格式再缓存。
log-format
String 日志记录原始url,可选值:true(日志记录原始url)、false(不开启日志记录原始url)
url-key
String用于配置获取url中的key的名称 示例: auth_key

返回参数

Body 参数

参数名称类型描述
http status code
Integerhttpstatus=202;   表示成功调用新增域名接口,可使用header中的x-cnc-request-id查看当前新增域名的部署情况
x-cnc-request-id
String唯一标示的id,用于查询每次请求的任务 (适用全部接口)
code
String错误代码,当HTTPStatus不为202时出现,表示当前请求调用的错误类型
message
String响应信息,成功时为success

错误码

错误代码(code)描述(message)HTTP状态码语义
InternalErrorWe encountered an internal error. Please try again.500内部错误
InvalidParameterNo domain was specified.400uri中没有指定域名或者域名ID
NoSuchDomainThe specified domain does not exist.404指定的域名不存在
ConfigErrorThe config {} does not access.400域名没有规划指定配置,无法修改
DomainNotRestoredThe domain you are trying to cancel has not been restored.409请求的域名已经取消结束,无法修改
ForbiddenThe domain is being deleted403请求的域名已经挂起,无法修改
WrongDataIdWrong data-d.400错误的DataId
InternalErrorWe encountered an internal error. Please try again.500内部错误
NoSuchDomainThe specified domain does not exist.404请求的域名不存在
CustomerNoOwnDomaincustomer not own domain name[*]400请求账号无法操作请求的域名
InvalidParameterNo domain was specified.400uri中没有指定域名或者域名ID
InvalidParameterThe specified allowed-ips was invalid.400参数allowed-ips的格式不正确
InvalidParameterThe specified cipher-combination was invalid.400参数cipher-combination的格式不正确
InvalidParameterThe specified lower-limit-expiry-time must be digits.400参数lower-limit-expiry-time的格式不正确
InvalidParameterThe specified upper-limit-expiry-time must be digits.400参数upper-limit-expiry-time的格式不正确
InvalidParameterThe specified time-format was invalid.400参数time-format的格式不正确
InvalidParameterThe time-format's value separated by semicolon can appear only once.400参数time-format中的数据不能出现重复的
InvalidParameterThe specified request-url-style was invalid.400参数request-url-style的格式不正确
InvalidParameterThe specified dst-style is either 1 or 2.400参数dst-style的格式不正确
InvalidParameterThe specified encrypt-method was invalid.400参数encrypt-method的格式不正确
InvalidParameterThe specified log-format was invalid.400参数log-format的格式不正确
InvalidParameterThe specified m3u8 was invalid.400参数lm3u8的格式不正确
InvalidParameterThe path-pattern is required when path-pattern-protocol has value.400参数timestamp-control-rule/path-pattern-protocol存在时,参数timestamp-control-rule/path-pattern也必须存在
InvalidParameterThe specified (timestamp-control-rule/path-pattern-protocol) was invalid.400参数timestamp-control-rule/path-pattern-protocol的格式不正确
InvalidParameterThe except-path-pattern is required when except-path-pattern-protocol has value.400参数timestamp-control-rule/except-path-pattern-protocol存在时参数timestamp-control-rule/except-path-pattern也必须存在
InvalidParameterThe specified (timestamp-control-rule/except-path-pattern-protocol) was invalid.400参数timestamp-control-rule/except-path-pattern-protocol的格式不正确
InvalidParameterThe specified (timestamp-control-rule/cipher-combination) was invalid.400参数timestamp-control-rule/cipher-combination的格式不正确
InvalidParameterThe specified (timestamp-control-rule/lower-limit-expiry-time) must be digits.400参数timestamp-control-rule/lower-limit-expiry-time的格式不正确
InvalidParameterThe specified (timestamp-control-rule/upper-limit-expiry-time) must be digits.400参数timestamp-control-rule/upper-limit-expiry-time的格式不正确
InvalidParameterThe specified (timestamp-control-rule/request-url-style) was invalid.400参数timestamp-control-rule/request-url-style的格式不正确
InvalidParameterThe (timestamp-control-rule/uri-select) was invalid.400参数timestamp-control-rule/uri-select的格式不正确
InvalidParameterConflicting request parameters,The  parameters "cipher-combination|secret-key|cipher-param|time-param|lower-limit-expiry-time|upper-limit-expiry-time" must only exist in "timestamp-visit-control-rule" or "timestamp-control-rules".400参数cipher-combination|secret-key|cipher-param|time-param|lower-limit-expiry-time|upper-limit-expiry-time 同时仅能在父标签timestamp-visit-control-rule或者timestamp-control-rules下的一处配置
InvalidParameterConflicting request parameters, The  parameters "request-url-style" must only exist in "timestamp-visit-control-rule" or "timestamp-control-rules".400参数request-url-style同时仅能在父标签timestamp-visit-control-rule或者timestamp-control-rules下的一处配置
MalformedXML400参数request-url-style的格式不正确,?后的$key或者$time对应的参数需要符合预期
ConfigError[The format of request URL] just one value can be configured.400配置[请求url格式]仅能在一处配置
ConfigError[Access Control generation method] just one value can be configured.400配置[防盗链生成方式]仅能在一处配置
InvalidParameterThe path-pattern and directory cannot have values at the same time. 400path-pattern 和 directory 不能同时有值

示例

JSON
XML
JSON
请求示例
复制代码 复制成功
#!/bin/bash
username="example_username"
apiKey="example_apiKey"
date=`env LANG="en_US.UTF-8" date -u "+%a, %d %b %Y %H:%M:%S GMT"`
password=`echo -en "$date" | openssl dgst -sha1 -hmac $apiKey -binary | openssl enc -base64`
curl -i --url "https://open.chinanetcenter.com/api/config/timecontrol/www.aaa.com" \
-X "PUT" \
-u "$username:$password" \
-H "Date: $date" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{
    "timestamp-visit-control-rule":{
        "path-pattern":"/*",
        "except-path-pattern":"/*",
        "allowed-ips":"1.1.1.1",
        "cipher-combination":"$uri$ourkey$time$args{param1}",
        "secret-key":"ad",
        "cipher-param":"keyname",
        "time-param":"tname",
        "lower-limit-expiry-time":"60",
        "upper-limit-expiry-time":"60",
        "multiple-secret-keys":"60",
        "time-format":"1Y;2m;3d;4H;5M;6S;7s;8x",
        "request-url-style":"http://$domain/$uri?$args&keyname=$key&tname=$time",
        "dst-style":"1",
        "encrypt-method":"md5sum"
    }
}'
返回示例
复制代码 复制成功
HTTP/1.1 202 Accepted
Server: openresty/1.11.2.2
Date: Wed, 15 May 2019 07:31:43 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 60
Connection: keep-alive
App-Name: service_confApi
x-cnc-request-id: 5c429816-5fda-4d6d
{
    "message":"success",
    "code":""
}
本篇文档内容对您是否有帮助?
有帮助
我要反馈
提交成功!非常感谢您的反馈,我们会继续努力做到更好!