{"id":17306752,"url":"https://github.com/evannotfound/dingtalk-robot-python","last_synced_at":"2026-01-27T12:36:19.815Z","repository":{"id":151893455,"uuid":"481416103","full_name":"EvanNotFound/Dingtalk-robot-python","owner":"EvanNotFound","description":"钉钉自定义机器人的python版本","archived":false,"fork":false,"pushed_at":"2022-04-14T05:17:14.000Z","size":7,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-30T11:35:38.595Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EvanNotFound.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-14T00:34:57.000Z","updated_at":"2023-07-25T14:56:24.000Z","dependencies_parsed_at":"2023-05-14T11:00:26.369Z","dependency_job_id":null,"html_url":"https://github.com/EvanNotFound/Dingtalk-robot-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/EvanNotFound/Dingtalk-robot-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanNotFound%2FDingtalk-robot-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanNotFound%2FDingtalk-robot-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanNotFound%2FDingtalk-robot-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanNotFound%2FDingtalk-robot-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EvanNotFound","download_url":"https://codeload.github.com/EvanNotFound/Dingtalk-robot-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanNotFound%2FDingtalk-robot-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28813215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T12:25:15.069Z","status":"ssl_error","status_checked_at":"2026-01-27T12:25:05.297Z","response_time":168,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T11:59:19.341Z","updated_at":"2026-01-27T12:36:19.798Z","avatar_url":"https://github.com/EvanNotFound.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dingtalk-robot-python 钉钉机器人 Python 版本\n\n钉钉自定义机器人的python版本，改写自官网开发文档\n\n## 使用方法\n\n首先到钉钉新增自定义机器人\n\n\u003cimg width=\"671\" alt=\"Screen Shot 2022-04-14 at 08 41 58\" src=\"https://user-images.githubusercontent.com/68590232/163291972-1fba7656-307f-4faf-84ab-82442dd21979.png\"\u003e\n\n然后安全验证方式选择“加签”\n\n\u003cimg width=\"634\" alt=\"Screen Shot 2022-04-14 at 08 42 39\" src=\"https://user-images.githubusercontent.com/68590232/163292038-078de2ad-4560-4172-8deb-2bb42b472618.png\"\u003e\n\n最后将 `Webhook` 地址和 `加签` 复制下来\n\n分别替换本 Python 脚本中的 `secert here` 和 `WEBHOOK HERE` 地址\n\n便可以直接自定义消息发送到钉钉群中\n\n消息类型详情请见钉钉开发文档 https://open.dingtalk.com/document/group/custom-robot-access\n\n## 代码解析\n\n### 加签部分\n\n```python\n#python 3.8\nimport time\nimport hmac\nimport hashlib\nimport base64\nimport urllib.parse\n\ntimestamp = str(round(time.time() * 1000))\nsecret = 'secret here'  #在此处填写机器人的签名\nsecret_enc = secret.encode('utf-8')\nstring_to_sign = '{}\\n{}'.format(timestamp, secret)\nstring_to_sign_enc = string_to_sign.encode('utf-8')\nhmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()\nsign = urllib.parse.quote_plus(base64.b64encode(hmac_code))\n```\n把`timestamp+\"\\n\"+`密钥当做签名字符串，使用`HmacSHA256`算法计算签名，然后进行`Base64 encode`，最后再把签名参数再进行`urlEncode`，得到最终的签名（需要使用`UTF-8`字符集）。\n\n在`secret here`处填写机器人获取到的签名，不要去掉引号\n\n### 请求头部数据部分\n\n```python\ndef dingmessage():\n# 请求的URL，填写WebHook地址\n    webhook = \"WEBHOOK HERE\"\n#构建请求头部\n    header = {\n        \"Content-Type\": \"application/json\",\n        \"Charset\": \"UTF-8\"\n}\n```\n在`WEBHOOK HERE`部分填写获取的Webhook地址，不要去掉引号\n\n### 数据输出部分\n\n```python\n    message ={\n         \"msgtype\": \"text\",\n         \"text\": \n        {\n            \"content\": \"太恐怖了吧\"\n        },\n         \"at\": {\n          \"atMobiles\":  #At的人的手机号\n          [\n              \n          ],\n          \"atUserIds\":   #At的人的用户id\n          [\n              \n          ],\n          \"isAtAll\": False  #是否At所有人\n      }\n }\n#对请求的数据进行json封装\n    message_json = json.dumps(message)\n#发送请求\n    info = requests.post(url=webhook+\"\u0026timestamp=\"+timestamp+\"\u0026sign=\"+sign,data=message_json,headers=header)\n#打印返回的结果\n    print(info.text)\n\nif __name__==\"__main__\":\n    dingmessage()\n```\n消息类型为`text`，内容为`太恐怖了吧`\n\n各种消息类型见 https://open.dingtalk.com/document/group/custom-robot-access\n\n本人对发送请求进行了改动，让`url`等于`webhook`并加上`timestamp`和`sign`签名，每次无需重新获取签名便可发送\n\n## 结尾\n\n还是挺有用的，有很多拓展方式比如邮件转发等\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevannotfound%2Fdingtalk-robot-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevannotfound%2Fdingtalk-robot-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevannotfound%2Fdingtalk-robot-python/lists"}