#!/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)
data = {
"msgtype": "markdown",
"markdown": {
"title": info1,
"text":"### <font color=%s>%s</font>"%(color,標題) + '\n\n '+ 內容+""%(圖片鏈接)+"@手機號1 @手機號2" },
"at":{
"atMobiles":["手機號1","手機號2"],
"isAtAll": False,
},
color格式##00FF00