File size: 1,209 Bytes
5a79bd6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import hashlib
import time
import uuid
'''
添加鉴权相关参数 -
appKey : 应用ID
salt : 随机值
curtime : 当前时间戳(秒)
signType : 签名版本
sign : 请求签名
@param appKey 您的应用ID
@param appSecret 您的应用密钥
@param paramsMap 请求参数表
'''
def addAuthParams(appKey, appSecret, params):
salt = str(uuid.uuid1())
curtime = str(int(time.time()))
sign = calculateSign(appKey, appSecret, salt, curtime)
params['appKey'] = appKey
params['salt'] = salt
params['curtime'] = curtime
params['signType'] = 'v4'
params['sign'] = sign
'''
计算鉴权签名 -
计算方式 : sign = sha256(appKey + input(q) + salt + curtime + appSecret)
@param appKey 您的应用ID
@param appSecret 您的应用密钥
@param salt 随机值
@param curtime 当前时间戳(秒)
@return 鉴权签名sign
'''
def calculateSign(appKey, appSecret, salt, curtime):
strSrc = appKey + salt + curtime + appSecret
return encrypt(strSrc)
def encrypt(strSrc):
hash_algorithm = hashlib.sha256()
hash_algorithm.update(strSrc.encode('utf-8'))
return hash_algorithm.hexdigest()
|