pip3 install dingtalkchatbot //首先下载dingtalkchatbot包
# coding:utf-8
# Author:mochacha
# 确保与dingtalkchatbot包在同一路径下
"""
通过DingtalkChatbot推送消息
执行:python xxx.py
"""
from dingtalkchatbot.chatbot import DingtalkChatbot
# webhook
webhook = "https://oapi.dingtalk.com/robot/send?access_token=xxx"
secret = "xxx"
# 初始化
test = DingtalkChatbot(webhook, secret=secret)
# 测试消息@所有人
#xiaoding.send_text(msg="测试所有人收到推送消息", is_at_all=True/at_mobiles=at_mobiles)
at_mobiles = ['xxx', 'xxx'] //手机号
test.send_text(msg="消息发送成功", is_at_all=True) //可以@全体成员,也可以@手机号
# 更多功能可以查看源码和官方文档
# 钉钉开发接口地址:https://dingtalk-sdk.readthedocs.io/zh_CN/stable/client/index.html