from urllib import parse
import base64
import hashlib
import hmac
def hmacSha256(key, message):
key = bytes(key, 'utf-8')
message = bytes(message, 'utf-8')
hmacObject = hmac.new(key, message, hashlib.sha256)
return hmacObject.hexdigest()
def sha256hex(message):
sha256Object = hashlib.sha256()
message = bytes(message, 'utf-8')
sha256Object.update(message)
return sha256Object.hexdigest()
appID = 'eVzjIKe1NZe9Tfpb'
appSecret = 'nzWChGoCWnAwSxEsMRXFDKwDeKIfZhVbjeyzZooBnnJa5KBQC4Zd1lmYVy8AEanM'
method = 'GET'
requestPath = '/api/zhaozhao/涂卡'
timeStamp = '1746689979576'
requestStr = "Findluo" + "\n" + method + "\n" + parse.quote(requestPath).lower()
signHexStr = sha256hex(requestStr)
signStr = base64.b64encode(bytes(signHexStr + timeStamp, 'utf-8')).decode()
signKey = hmacSha256(appSecret, signStr)
authContent = "Findluo" + "\n" + appID + "\n" + signKey + "\n" + timeStamp
authHeaderValue = "Findluo " + base64.b64encode(bytes(authContent, 'utf-8')).decode()
print('url: ' + requestPath)
print('SHA256 请求信息签名字符串: ' + signHexStr)
print('签名字符串: ' + signStr)
print('最终签名: ' + signKey)
print('Authorization: ' + authHeaderValue)