2021-03-11 13:21:18 +08:00
|
|
|
import hmac
|
|
|
|
import base64
|
2021-03-20 14:49:58 +08:00
|
|
|
import hashlib
|
|
|
|
|
|
|
|
from nonebot.utils import logger_wrapper
|
|
|
|
|
2020-12-03 00:59:32 +08:00
|
|
|
log = logger_wrapper("DING")
|
2021-03-11 13:21:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
def calc_hmac_base64(timestamp: str, secret: str):
|
2021-11-22 23:21:26 +08:00
|
|
|
secret_enc = secret.encode("utf-8")
|
|
|
|
string_to_sign = "{}\n{}".format(timestamp, secret)
|
|
|
|
string_to_sign_enc = string_to_sign.encode("utf-8")
|
|
|
|
hmac_code = hmac.new(
|
|
|
|
secret_enc, string_to_sign_enc, digestmod=hashlib.sha256
|
|
|
|
).digest()
|
2021-03-11 13:21:18 +08:00
|
|
|
return base64.b64encode(hmac_code)
|