mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 19:37:36 +08:00
* 更新了wechatpad接口,以及适配器 * 更新了wechatpad接口,以及适配器 * 修复一些细节问题,比如at回复,以及启动登录和启动ws长连接的线程同步 * importutil中修复了在wi上启动替换斜杠问题,login中加上了一个login,暂时没啥用。wechatpad中做出了一些细节修改 * 更新了wechatpad接口,以及适配器 * 怎加了处理图片链接转换为image_base64发送 * feat(wechatpad): 调整日志+bugfix * feat(wechatpad): fix typo * 修正了发送语音api参数错误,添加了发送链接处理为base64数据(好像只有一部分链接可以) * 修复了部分手抽的typo错误 * chore: remove manager.py --------- Co-authored-by: shinelin <shinelinxx@gmail.com> Co-authored-by: Junyan Qin (Chin) <rockchinq@gmail.com>
123 lines
3.7 KiB
Python
123 lines
3.7 KiB
Python
|
|
from libs.wechatpad_api.util.http_util import async_request, post_json
|
|
|
|
|
|
class MessageApi:
|
|
def __init__(self, base_url, token):
|
|
self.base_url = base_url
|
|
self.token = token
|
|
|
|
def post_text(self, to_wxid, content, ats: list= []):
|
|
'''
|
|
|
|
Args:
|
|
app_id: 微信id
|
|
to_wxid: 发送方的微信id
|
|
content: 内容
|
|
ats: at
|
|
|
|
Returns:
|
|
|
|
'''
|
|
url = self.base_url + "/message/SendTextMessage"
|
|
"""发送文字消息"""
|
|
json_data = {
|
|
"MsgItem": [
|
|
{
|
|
"AtWxIDList": ats,
|
|
"ImageContent": "",
|
|
"MsgType": 0,
|
|
"TextContent": content,
|
|
"ToUserName": to_wxid
|
|
}
|
|
]
|
|
}
|
|
return post_json(base_url=url, token=self.token, data=json_data)
|
|
|
|
|
|
|
|
|
|
def post_image(self, to_wxid, img_url, ats: list= []):
|
|
"""发送图片消息"""
|
|
# 这里好像可以尝试发送多个暂时未测试
|
|
json_data = {
|
|
"MsgItem": [
|
|
{
|
|
"AtWxIDList": ats,
|
|
"ImageContent": img_url,
|
|
"MsgType": 0,
|
|
"TextContent": '',
|
|
"ToUserName": to_wxid
|
|
}
|
|
]
|
|
}
|
|
url = self.base_url + "/message/SendImageMessage"
|
|
return post_json(base_url=url, token=self.token, data=json_data)
|
|
|
|
def post_voice(self, to_wxid, voice_data, voice_forma, voice_duration):
|
|
"""发送语音消息"""
|
|
json_data = {
|
|
"ToUserName": to_wxid,
|
|
"VoiceData": voice_data,
|
|
"VoiceFormat": voice_forma,
|
|
"VoiceSecond": voice_duration
|
|
}
|
|
url = self.base_url + "/message/SendVoice"
|
|
return post_json(base_url=url, token=self.token, data=json_data)
|
|
|
|
|
|
|
|
|
|
|
|
def post_name_card(self, alias, to_wxid, nick_name, name_card_wxid, flag):
|
|
"""发送名片消息"""
|
|
param = {
|
|
"CardAlias": alias,
|
|
"CardFlag": flag,
|
|
"CardNickName": nick_name,
|
|
"CardWxId": name_card_wxid,
|
|
"ToUserName": to_wxid
|
|
}
|
|
url = f"{self.base_url}/message/ShareCardMessage"
|
|
return post_json(base_url=url, token=self.token, data=param)
|
|
|
|
def post_emoji(self, to_wxid, emoji_md5, emoji_size:int=0):
|
|
"""发送emoji消息"""
|
|
json_data = {
|
|
"EmojiList": [
|
|
{
|
|
"EmojiMd5": emoji_md5,
|
|
"EmojiSize": emoji_size,
|
|
"ToUserName": to_wxid
|
|
}
|
|
]
|
|
}
|
|
url = f"{self.base_url}/message/SendEmojiMessage"
|
|
return post_json(base_url=url, token=self.token, data=json_data)
|
|
|
|
def post_app_msg(self, to_wxid,xml_data, contenttype:int=0):
|
|
"""发送appmsg消息"""
|
|
json_data = {
|
|
"AppList": [
|
|
{
|
|
"ContentType": contenttype,
|
|
"ContentXML": xml_data,
|
|
"ToUserName": to_wxid
|
|
}
|
|
]
|
|
}
|
|
url = f"{self.base_url}/message/SendAppMessage"
|
|
return post_json(base_url=url, token=self.token, data=json_data)
|
|
|
|
|
|
|
|
def revoke_msg(self, to_wxid, msg_id, new_msg_id, create_time):
|
|
"""撤回消息"""
|
|
param = {
|
|
"ClientMsgId": msg_id,
|
|
"CreateTime": create_time,
|
|
"NewMsgId": new_msg_id,
|
|
"ToUserName": to_wxid
|
|
}
|
|
url = f"{self.base_url}/message/RevokeMsg"
|
|
return post_json(base_url=url, token=self.token, data=param) |