Skip to main content

send message to wechat robot

Project description

功能

  • 发送消息到企业微信机器人。
  • 支持所有企业微信机器人消息类型。
  • 企业微信机器人

安装

1. 安装该模块
pip install wechatrobot

使用

  • 获取微信机器人的 key

    创建机器人时,会返回一个 webhook 的地址,如 https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=5cb94c2b-1238-4414-b830-a521523d7a,则 key5cb94c2b-1238-4414-b830-a521523d7a

  • 使用

    key = '5cb94c2b-1238-4414-b830-a521523d7a'
    
    import wechatrobot
    wxrobot = wechatrobot.WechatRobot(key)
    
  • 发送文本消息

    # 签名
    wxrobot.send_text(content, at_mobiles=None)
    
    # content 为要发送的文本内容
    # at_mobiles 需要 @ 人的手机号,可以是列表或字符串(多个人使用逗号分隔)。如果要 @所有人,则设置 at_mobiles='all'。@ 多个人时,指定 at_mobiles='18600000000,18600000001'
    
  • 发送 markdown 消息

    # 签名
    wxrobot.send_markdown(contents)
    
    # 如果 contents 为列表、元组, 每一行为一个 markdown 格式的字符串。默认会在每个元素后增加一个 '\n' 换行符。
    # 如果 contents 是字符串,则用户自己控制markdown的格式。
    # 支持的格式参考:https://work.weixin.qq.com/api/doc/90000/90136/91770#markdown%E7%B1%BB%E5%9E%8B
    
  • 发送图片

    # 签名
    wxrobot.send_image(image_path)
    
    # image_path 支持 HTTP、HTTPS、FTP,互联网上的图片URL。也支持本地的图片路径。
    # 如 wxrobot.send_image('https://img1.maka.im/template/T_G29KRHKN_t1.jpg')
    
  • 发送图文类型

    # 签名
    wxrobot.send_news(news_title, jump_url, picurl=None, news_description=None)
    
    # news_title          消息标题
    # jump_url            跳转url
    # picurl              图片的url
    # news_description    消息描述
    
  • 发送文件

    # 签名
    wxrobot.send_file(file_path)
    
    # file_path   要上传的本地文件路径。大小不能超过20M
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

wechatrobot-1.0.6-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page