#!/usr/bin/python3 import time import hmac import hashlib import base64 import urllib.parse import os timestamp = str(round(time.time() * 1000)) secret = 'SEC×××××××××××××××××××××××××××××××××××××××××××' 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() sign = urllib.parse.quote_plus(base64.b64encode(hmac_code)) #print(timestamp) #print(sign) webhookurl = 'https://oapi.dingtalk.com/robot/send?access_token=××××××××××××××××××××××××××××××××××' + '×tamp=' + timestamp + '&sign=' + sign os.environ['url'] = webhookurl #os.environ['xiantime'] = time.strftime('%H:%M:%S') os.environ['xiantime'] = time.ctime() os.system(''' curl ${url} -H 'Content-Type: application/json' -d '{"msgtype": "text","text":{"content":"现在时间是 '"$xiantime"' !"}}' ''') #print(webhookurl)