fix wechat message
This commit is contained in:
parent
a07afba245
commit
04c22d112f
@ -72,7 +72,7 @@ class WeChat(metaclass=Singleton):
|
|||||||
return None
|
return None
|
||||||
return self._access_token
|
return self._access_token
|
||||||
|
|
||||||
def __send_message(self, title: str, text: str, userid: str = None) -> Optional[bool]:
|
def __send_message(self, title: str, text: str = None, userid: str = None) -> Optional[bool]:
|
||||||
"""
|
"""
|
||||||
发送文本消息
|
发送文本消息
|
||||||
:param title: 消息标题
|
:param title: 消息标题
|
||||||
@ -196,23 +196,35 @@ class WeChat(metaclass=Singleton):
|
|||||||
logger.error("获取微信access_token失败,请检查参数配置")
|
logger.error("获取微信access_token失败,请检查参数配置")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
# 先发送标题
|
||||||
index, caption = 1, "*%s*" % title
|
if title:
|
||||||
|
self.__send_message(title=title)
|
||||||
|
|
||||||
|
# 发送列表
|
||||||
|
message_url = self._send_msg_url % self.__get_access_token()
|
||||||
|
if not userid:
|
||||||
|
userid = "@all"
|
||||||
|
articles = []
|
||||||
|
index = 1
|
||||||
for context in torrents:
|
for context in torrents:
|
||||||
torrent = context.torrent_info
|
torrent = context.torrent_info
|
||||||
link = torrent.page_url
|
articles.append({
|
||||||
title = torrent.title
|
"title": f"{torrent.title}",
|
||||||
free = torrent.get_volume_factor_string()
|
"description": f"【{torrent.site_name}】{torrent.description} "
|
||||||
seeder = f"{torrent.seeders}↑"
|
f"{torrent.get_volume_factor_string()} {torrent.seeders}↑",
|
||||||
description = torrent.description
|
"url": torrent.page_url
|
||||||
caption = f"{caption}\n{index}. [{title}]({link}) {free} {seeder}\n{description}"
|
})
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
return self.__send_message(title, caption, userid)
|
req_json = {
|
||||||
|
"touser": userid,
|
||||||
except Exception as msg_e:
|
"msgtype": "news",
|
||||||
logger.error(f"发送消息失败:{msg_e}")
|
"agentid": self._appid,
|
||||||
return False
|
"news": {
|
||||||
|
"articles": articles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return self.__post_request(message_url, req_json)
|
||||||
|
|
||||||
def __post_request(self, message_url: str, req_json: dict) -> bool:
|
def __post_request(self, message_url: str, req_json: dict) -> bool:
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user