An example of generating the token code based on python is as follows:
import base64
import hmac
import time
from urllib.parse import quote
def token(id,access_key):
version = '2018-10-31'
res = 'products/%s' % id # 通过产品ID访问产品API
# user-defined token expiration time
et = str(int(time.time()) + 3600)
# signature method, supports md5, sha1 and sha256
method = 'sha1'
# decode access_key
key = base64.b64decode(access_key)
# calculate sign
org = et + '\n' + method + '\n' + res + '\n' + version
sign_b = hmac.new(key=key, msg=org.encode(), digestmod=method)
sign = base64.b64encode(sign_b.digest()).decode()
# the value part is URL encoded, and the method/res/version value is relatively simple, with no coding required
sign = quote(sign, safe='')
res = quote(res, safe='')
# token parameters are concatenated
token = 'version=%s&res=%s&et=%s&method=%s&sign=%s' % (version, res, et, method, sign)
return token
if __name__ == '__main__':
id = '123123'
access_key = 'KuF3NT/jUBJ62LNBB/A8XZA9CqS3Cu79B/ABmfA1UCw='
print(token(id,access_key))