标签:ash type ges hash new end 钉钉 base string
import time
import hmac
import hashlib
import base64
import urllib.parse
def get_sign():
timestamp = str(round(time.time() * 1000))
secret = ‘SEC6b56772f9126e3b55711413f40114c9954a120965979650356e89e380bd50d05‘
secret_enc = secret.encode(‘utf-8‘)
# string_to_sign = ‘{}\n{}‘.format(timestamp, secret)
string_to_sign = timestamp+ ‘\n‘ + 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()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
return timestamp,sign
import time
url = "https://oapi.dingtalk.com/robot/send?access_token=1dc3bfa867e169261bb21793fff3da9f83f756085efadaa0bdd107c453e3e91c" #数据测试
for i in range(3):
data ={
"msgtype": "text",
"text": {
"content": "现在的时间可以休息%s" % i
}
}
timestamp,sign = get_sign()
params1 ={"timestamp":timestamp,"sign":sign}
r = requests.post(url,json=data,params=params1)
print(r.json())
标签:ash type ges hash new end 钉钉 base string
原文地址:https://www.cnblogs.com/wsc001/p/14363843.html