钉钉开放平台机器人提供的加签代码片段为python2版本,
加密方式为:HmacSHA256算法
以下为python3版本:
import time
import hashlib
import base64
import urllib.parse
def encrypt():
timestamp = round(time.time()*1000)
secret = 'this is secret'
secret_string = str(timestamp) + "\n" + secret
signature = hmac.new(key=bytes(secret, 'utf-8'), msg=bytes(secret_string, 'utf-8'), digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote(base64.b64encode(signature)) //加签结果
return (timestamp, sign)
网友评论