Dingtalk-robot-python

钉钉自定义机器人的python版本

MIT License

Stars
4

Dingtalk-robot-python Python

python

Webhook ``

Python secert here WEBHOOK HERE

https://open.dingtalk.com/document/group/custom-robot-access

#python 3.8
import time
import hmac
import hashlib
import base64
import urllib.parse

timestamp = str(round(time.time() * 1000))
secret = 'secret here'  #
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))

timestamp+"\n"+``HmacSHA256``Base64 encode``urlEncode``UTF-8

secret here

def dingmessage():
# URLWebHook
    webhook = "WEBHOOK HERE"
#
    header = {
        "Content-Type": "application/json",
        "Charset": "UTF-8"
}

WEBHOOK HEREWebhook

    message ={
         "msgtype": "text",
         "text": 
        {
            "content": ""
        },
         "at": {
          "atMobiles":  #At
          [
              
          ],
          "atUserIds":   #Atid
          [
              
          ],
          "isAtAll": False  #At
      }
 }
#json
    message_json = json.dumps(message)
#
    info = requests.post(url=webhook+"&timestamp="+timestamp+"&sign="+sign,data=message_json,headers=header)
#
    print(info.text)

if __name__=="__main__":
    dingmessage()

`text```

https://open.dingtalk.com/document/group/custom-robot-access

url``webhook``timestamp``sign