企业微信基于python推送文本消息&&图片

本文详细介绍了如何使用Python调用企业微信接口,实现向企业成员发送文本消息以及临时图片消息的功能,涵盖了消息类型的创建及发送过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

推送文本类消息:

def __push_to_wechat(self, content):
    """
    文本类消息推送至企业微信
    :return:
    """
    data = {
        "touser": "XXXXXXX",  
        #"toparty": '3',
        # "totag": "TagID1 | TagID2",
        "msgtype": "text",
        "agentid": 1000002,
        "text": {
            "content": content
        },
        "safe": 1
    }
    ''''''
    try:
        curl = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={token}'.format(
            token=self.__get_token())
        res = self.__http_request.post(curl, data)
        self.__check_push_result(res['errcode'])
    except Exception:
        self.__logger.error("消息推送失败,请检查网络连接.")

推送临时图片类消息:

#获取图片的media_id
def get_media_id(self):
    gurl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={}&corpsecret={}".format(self.__corp_id,
                                                                                         self.__corpsecret)
    r = requests.get(gurl)
    dict_resu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值