钉钉页面扫码登录中hmac加密签名

"""
获取签名
param app_secret: 钉钉开发者文档创建的app密钥
param utc_timestamp: 官方文档中要签名的数据,单位是毫秒时间戳
return: 为所需要的签名值,此值为可逆的
"""
def get_ding_talk_signature(app_secret, utc_timestamp):
    digest = hmac.HMAC(
        key=app_secret.encode('utf8'),
        msg=utc_timestamp.encode('utf8'),
        digestmod=hmac._hashlib.sha256
    ).digest()
    signature = standard_b64encode(digest).decode('utf8')
    return signature

  

原文地址:https://www.cnblogs.com/lsz3034/p/14091523.html