diff --git a/config/config.ini b/config/config.ini index 29acdc2..203bd95 100644 --- a/config/config.ini +++ b/config/config.ini @@ -30,7 +30,7 @@ mp4格式重新编码为h264 = 否 额外使用代理录制的平台(逗号分隔) = [推送配置] -# 可选微信|钉钉|tg|邮箱|bark|ntfy 可填多个 +# 可选微信|钉钉|tg|邮箱|bark|ntfy|pushplus 可填多个 直播状态推送渠道 = 钉钉推送接口链接 = 微信推送接口链接 = @@ -52,6 +52,7 @@ SMTP邮件服务器端口 = ntfy推送地址 = https://ntfy.sh/xxxx ntfy推送标签 = tada ntfy推送邮箱 = +pushplus推送token = 自定义推送标题 = 自定义开播推送内容 = 自定义关播推送内容 = diff --git a/main.py b/main.py index 3fd6848..6878e4f 100644 --- a/main.py +++ b/main.py @@ -32,7 +32,7 @@ from src.proxy import ProxyDetector from src.utils import logger from src import utils from msg_push import ( - dingtalk, xizhi, tg_bot, send_email, bark, ntfy + dingtalk, xizhi, tg_bot, send_email, bark, ntfy, pushplus ) from ffmpeg_install import ( check_ffmpeg, ffmpeg_path, current_env_path @@ -340,6 +340,7 @@ def push_message(record_name: str, live_url: str, content: str) -> None: 'NTFY': lambda: ntfy( ntfy_api, title=msg_title, content=content, tags=ntfy_tags, action_url=live_url, email=ntfy_email ), + 'PUSHPLUS': lambda: pushplus(pushplus_token, msg_title, content), } for platform, func in push_functions.items(): @@ -1727,6 +1728,7 @@ while True: ntfy_api = read_config_value(config, '推送配置', 'ntfy推送地址', "") ntfy_tags = read_config_value(config, '推送配置', 'ntfy推送标签', "tada") ntfy_email = read_config_value(config, '推送配置', 'ntfy推送邮箱', "") + pushplus_token = read_config_value(config, '推送配置', 'pushplus推送token', "") push_message_title = read_config_value(config, '推送配置', '自定义推送标题', "直播间状态更新通知") begin_push_message_text = read_config_value(config, '推送配置', '自定义开播推送内容', "") over_push_message_text = read_config_value(config, '推送配置', '自定义关播推送内容', "") diff --git a/msg_push.py b/msg_push.py index 96f4681..c682b20 100644 --- a/msg_push.py +++ b/msg_push.py @@ -213,6 +213,42 @@ def ntfy(api: str, title: str = "message", content: str = 'test', tags: str = 't return {"success": success, "error": error} +def pushplus(token: str, title: str, content: str) -> Dict[str, Any]: + """ + PushPlus推送通知 + API文档: https://www.pushplus.plus/doc/ + """ + success = [] + error = [] + token_list = token.replace(',', ',').split(',') if token.strip() else [] + + for _token in token_list: + json_data = { + 'token': _token, + 'title': title, + 'content': content + } + + try: + url = 'https://www.pushplus.plus/send' + data = json.dumps(json_data).encode('utf-8') + req = urllib.request.Request(url, data=data, headers=headers) + response = opener.open(req, timeout=10) + json_str = response.read().decode('utf-8') + json_data = json.loads(json_str) + + if json_data.get('code') == 200: + success.append(_token) + else: + error.append(_token) + print(f'PushPlus推送失败, Token:{_token}, 失败信息:{json_data.get("msg", "未知错误")}') + except Exception as e: + error.append(_token) + print(f'PushPlus推送失败, Token:{_token}, 错误信息:{e}') + + return {"success": success, "error": error} + + if __name__ == '__main__': send_title = '直播通知' # 标题 send_content = '张三 开播了!' # 推送内容 @@ -252,4 +288,8 @@ if __name__ == '__main__': api="https://ntfy.sh/xxxxx", title="直播推送", content="xxx已开播", - ) \ No newline at end of file + ) + + # PushPlus推送通知 + pushplus_token = '' # 替换成自己的PushPlus Token,获取地址:https://www.pushplus.plus/ + # pushplus(pushplus_token, send_title, send_content)