Python 企微机器人发送 MarkDown消息

python发送企微md消息:

class WXRobot:
    def robot_send(self):
        import requests

        headers = {"Content-Type": "text/plain"}

        send_url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxx-xxx-xxxxxxxxaaa123'

        send_data = {
            "msgtype": "markdown",  # 消息类型,此时固定为markdown
            "markdown": {
                "content": "# **【测试】**<font color=\"warning\">**xxx例**</font>\n" +  # 标题 (支持1至6级标题,注意#与文字中间要有空格)
                           "#### **请注意**\n" +  # 加粗:**需要加粗的字**
                           "> 类型:<font color=\"info\">XXX</font> \n" +  # 引用:> 需要引用的文字
                           "> 1XXX:<font color=\"warning\">xxx例</font> \n" +  # 字体颜色(只支持3种内置颜色)
                           "> 2XXX:<font color=\"warning\">xxx例</font>"  # 绿色:info、灰色:comment、橙红:warning
            }
        }

        res = requests.post(url = send_url, headers = headers, json = send_data)

        print(res.text)

if __name__ == '__main__':
    wx_robot = WXRobot()
    wx_robot.robot_send()

参考加入数据库数据校验:

class WXRobot:
    def get_doris_prd_engine(self):
        engine = create_engine(
            "mysql+pymysql://{}:{}@{}:{}/{}?charset={}".format('user_name', 'password', 'ip_addr', 'port', 'database_name', 'utf8'))
        return engine

    def robot_send(self):
        import requests

        headers = {"Content-Type": "text/plain"}

        send_url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxx-xxx-xxxxxxxxaaa123'

        send_data = {
            "msgtype": "markdown",  # 消息类型,此时固定为markdown
            "markdown": {
                "content": "# **【测试】**<font color=\"warning\">**xxx例**</font>\n" +  # 标题 (支持1至6级标题,注意#与文字中间要有空格)
                           "#### **请注意**\n" +  # 加粗:**需要加粗的字**
                           "> 类型:<font color=\"info\">XXX</font> \n" +  # 引用:> 需要引用的文字
                           "> 1XXX:<font color=\"warning\">xxx例</font> \n" +  # 字体颜色(只支持3种内置颜色)
                           "> 2XXX:<font color=\"warning\">xxx例</font>"  # 绿色:info、灰色:comment、橙红:warning
            }
        }

        res = requests.post(url = send_url, headers = headers, json = send_data)

        print(res.text)

if __name__ == '__main__':
    engine =wx_robot.get_doris_prd_engine()
    result = pd.read_sql('show databases', engine)
    num_rows = result.shape[0]
    # print(result)
    print(num_rows) #todo 在此处添加SQL查询结果行数校验
    wx_robot = WXRobot()
    wx_robot.robot_send()

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值