



cloud.tencent.com is configured for global acceleration and the authentication configuration is as follows:

http://cloud.tencent.com/1.jpg by directly initiating a request.http://cloud.tencent.com/1.jpg by initiating a request with a URL in the format of http://cloud.tencent.com/509301d10da7b862052927ed7a947f43/5e561139/1.jpg.import requestsimport jsonimport sysimport timeimport hashlibdef generate_url(category, ts=None):url = 'http://www.test.com' # Test domain namepath = '/1.txt' # Access pathsuffix = '?a=1&b=2' # URL parameterkey = 'abc123456789' # Authentication keynow = int(time.mktime(time.strptime(ts, "%Y%m%d%H%M%S")) if ts else time.time()) # If a `ts` is entered, it will be used; otherwise, the current `ts` will be usedsign_key = 'key' # URL signature fieldtime_key = 't' # URL time fieldttl_format = 10 # Time format. Valid values: 10, 16. This is supported only for type Dif category == 'A': # Type Ats = nowrand_str = '123abc'sign = hashlib.md5('%s-%s-%s-%s-%s' % (path, ts, rand_str, 0, key)).hexdigest()request_url = '%s%s?%s=%s' % (url, path, sign_key, '%s-%s-%s-%s' % (ts, rand_str, 0, sign))print(request_url)elif category == 'B': # Type Bts = time.strftime('%Y%m%d%H%M', time.localtime(now))sign = hashlib.md5('%s%s%s' % (key, ts, path)).hexdigest()request_url = '%s/%s/%s%s%s' % (url, ts, sign, path, suffix)print(request_url)elif category == 'C': # Type Cts = hex(now)[2:]sign = hashlib.md5('%s%s%s' % (key, path, ts)).hexdigest()request_url = '%s/%s/%s%s%s' % (url, sign, ts, path, suffix)print(request_url)elif category == 'D': # Type Dts = now if ttl_format == 10 else hex(now)[2:]sign = hashlib.md5('%s%s%s' % (key, path, ts)).hexdigest()request_url = '%s%s?%s=%s&%s=%s' % (url, path, sign_key, sign, time_key, ts)print(request_url)if __name__ == '__main__':if len(sys.argv) == 1:print('usage: python generate_url.py A 20200501000000')args = sys.argv[1:]generate_url(*args)
Feedback