51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

使用Python调用企业微信机器人webhook地址发送消息

使用Python调用企业微信机器人webhook地址发送消息

企业微信群机器人使用指南和python示例_企微机器人语法-CSDN博客

使用Python调用企业微信机器人webhook地址发送消息_企业微信webhook-CSDN博客

curl 示例:

curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=6e82e102-641b-41d9-a179-e6795ff0c8d6' -H 'Content-Type: application/json' -d '{"msgtype": "text","text": {"content": "hello world  ",  "mentioned_list": ["zhaozhiyong","@all"]}}' 

python 示例

import requests

def sendAll(message:str):
    # url = "机器人webhook地址"
    url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=8b47af31-e289-47e5-88eb-8923e01738fd"
    headers = {
        "Content-Type": "application/json"
    }
    data = {
        "msgtype": "text",
        "text": {
            "content": message,
            # "mentioned_list": ["@all"]
            # "mentioned_list": ["@zhaozhiyong"]
            "mentioned_list": ["zhaozhiyong", "@all"],
        }
    }
    response = requests.post(url, headers=headers, json=data)
    records = response.json()
    return records

if __name__ == '__main__':

    sendAll("baimeidashu测试 sendAll")

备注

消息内容:

makdown形式

{
    "msgtype": "markdown",
    "markdown": {
        "content": "实时新增用户反馈<font color=\"warning\">132例</font>,请相关同事注意。\n
         >类型:<font color=\"comment\">用户反馈</font> \n
         >普通用户反馈:<font color=\"comment\">117例</font> \n
         >VIP用户反馈:<font color=\"comment\">15例</font>"
    }
}

文本类型

{
    "msgtype": "text",
    "text": {
        "content": "广州今日天气:29度,大部分多云,降雨概率:60%",
        "mentioned_list":["wangqing","@all"],
        "mentioned_mobile_list":["13800001111","@all"]
    }
}

图文类型

{
    "msgtype": "news",
    "news": {
       "articles" : [
           {
               "title" : "中秋节礼品领取",
               "description" : "今年中秋节公司有豪礼相送",
               "url" : "URL",
               "picurl" : "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png"
           }
        ]
    }
}

赞(8)
未经允许不得转载:工具盒子 » 使用Python调用企业微信机器人webhook地址发送消息