python 推送企业微信机器人1-文本类型

参数说明

参数是否必填说明
msgtype消息类型,此时固定为text
content文本内容,最长不超过2048个字节,必须是utf8编码
mentioned_listuserid的列表,提醒群中的指定成员(@某个成员),@all表示提醒所有人,如果开发者获取不到userid,可以使用mentioned_mobile_list
mentioned_mobile_list手机号列表,提醒手机号对应的群成员(@某个成员),@all表示提醒所有人

效果展示

在这里插入图片描述

Demo Code

# -*- coding: utf-8 -*-
# coding:unicode_escape
#Created on 2021年12月31日

#@author: LinHuang(Joker)

import requests
import json

#mian function
def main():
    oWX_URL='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=50d640d9-9ad6-4d39-98aa-c94c200212345'
    sent_msg = {
        'msgtype': 'text',                                          
        'text': {                                                   
            'content': 'Joker test for wechat Message!',                
            'mentioned_list':['linhuang','@all'],          #'userid的列表,提醒群中的指定成员(@某个成员),@all表示提醒所有人,如果开发者获取不到userid,可以使用mentioned_mobile_list
            'mentioned_mobile_list':['17688869999','@all'] #'手机号列表,提醒手机号对应的群成员(@某个成员),@all表示提醒所有人
            }
    }#转换为json字符串
    headers = {'Content-Type':'application/json'}#指定提交的是json
    try:
        r = requests.post(url=oWX_URL,data=json.dumps(sent_msg),headers=headers,timeout=5)
    except  Exception as e:
        e.args[0]
if __name__ == '__main__':   
    main()

posted @ 2021-12-31 14:33  linhuang  阅读(39)  评论(0编辑  收藏  举报  来源