wechat
qywechat
WechatWork
- class dramkit.wechat.qywechat.WechatWork(corpid: str, appid: str, corpsecret: str)
Bases:
object
企业微信消息推送
- __init__(corpid: str, appid: str, corpsecret: str) None
初始化消息通知应用
- Parameters:
corpid (str) – 企业ID
appid (str) – 应用ID(企业微信网页后台应用管理界面的AgentId)
corpsecret (str) – 应用Secret(企业微信网页后台应用管理界面的Secret)
- access_token: str = None
- access_token_expires_time: datetime = None
- get_access_token() str
获取企业微信应用 token
- Returns:
企业微信程序 token
- Return type:
str
- Raises:
Exception – 当无法获取 token 时
- send(msg_type: str, users: List[str], content: Optional[str] = None, media_id: Optional[str] = None, logger: Optional[Logger] = None) bool
发送消息
- Parameters:
msg_type (str) –
消息类型
部分可选值及示例如下 -
'text'
纯文本 -'markdown'
Markdown 文本 -'image'
图片 -'file'
文件users (List[str]) – 接受消息的的用户账号列表 例如
['ZhangSan','LiSi']
content (str, optional) – 消息内容, 默认为
None
media_id (str, optional) – 文件 ID, 默认为
None
- Returns:
是否发送成功
- Return type:
bool
- send_file(file_path: str, users: List[str]) bool
发送文件给多个用户
- Parameters:
file_path (str) – 本地文件路径
users (List[str]) – 接受消息的用户账号列表
- send_image(image_path: str, users: List[str]) bool
发送图片给多个用户
- Parameters:
image_path (str) – 本地图片路径
users (List[str]) – 接受消息的的用户账号列表
- send_markdown(content: str, users: List[str]) bool
发送Markdown消息给多个用户
- Parameters:
content (str) – Markdown 内容
users (List[str]) – 接受消息的用户账号列表
- send_text(content: str, users: List[str]) bool
发送文本消息给多个用户
- Parameters:
content (str) – 文本内容
users (List[str]) – 接受消息的用户账号列表
- upload_file(filepath: str, filename: str) str
上传文件
- Parameters:
filepath (str) – 本地文件路径
filename (str) – 云端存储的文件名
- Returns:
上传的文件的 ID
- Return type:
str