From 4d10b39747726a0cf6242c99e6a96d5f8b61eb6b Mon Sep 17 00:00:00 2001 From: nelson Date: Mon, 8 Jan 2024 10:15:02 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0PushPlus=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=8E=A8=E9=80=81=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 8 ++ plugins/pushplusmsg/__init__.py | 197 ++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+) create mode 100644 plugins/pushplusmsg/__init__.py diff --git a/package.json b/package.json index e96e86d..9a3cf62 100644 --- a/package.json +++ b/package.json @@ -326,5 +326,13 @@ "icon": "ffmpeg.png", "author": "jxxghp", "level": 1 + }, + "PushPlusMsg": { + "name": "PushPlus消息推送", + "description": "支持使用PushPlus发送消息通知。", + "version": "1.0", + "icon": "Pushplus_A.png", + "author": "cheng", + "level": 1 } } diff --git a/plugins/pushplusmsg/__init__.py b/plugins/pushplusmsg/__init__.py new file mode 100644 index 0000000..65d4b08 --- /dev/null +++ b/plugins/pushplusmsg/__init__.py @@ -0,0 +1,197 @@ +from urllib.parse import urlencode + +from app.plugins import _PluginBase +from app.core.event import eventmanager, Event +from app.schemas.types import EventType, NotificationType +from app.utils.http import RequestUtils +from typing import Any, List, Dict, Tuple +from app.log import logger + + +class PushPlusMsg(_PluginBase): + # 插件名称 + plugin_name = "PushPlus消息推送" + # 插件描述 + plugin_desc = "支持使用PushPlus发送消息通知。" + # 插件图标 + plugin_icon = "Pushplus_A.png" + # 插件版本 + plugin_version = "1.0" + # 插件作者 + plugin_author = "cheng" + # 作者主页 + author_url = "https://github.com/small-ora" + # 插件配置项ID前缀 + plugin_config_prefix = "pushplusmsg_" + # 加载顺序 + plugin_order = 29 + # 可使用的用户级别 + auth_level = 1 + + # 私有属性 + _enabled = False + _token = None + _msgtypes = [] + + def init_plugin(self, config: dict = None): + if config: + self._enabled = config.get("enabled") + self._token = config.get("token") + self._msgtypes = config.get("msgtypes") or [] + + def get_state(self) -> bool: + return self._enabled and (True if self._token else False) + + @staticmethod + def get_command() -> List[Dict[str, Any]]: + pass + + def get_api(self) -> List[Dict[str, Any]]: + pass + + def get_form(self) -> Tuple[List[dict], Dict[str, Any]]: + """ + 拼装插件配置页面,需要返回两块数据:1、页面配置;2、数据结构 + """ + # 编历 NotificationType 枚举,生成消息类型选项 + MsgTypeOptions = [] + for item in NotificationType: + MsgTypeOptions.append({ + "title": item.value, + "value": item.name + }) + return [ + { + 'component': 'VForm', + 'content': [ + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'enabled', + 'label': '启用插件', + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12 + }, + 'content': [ + { + 'component': 'VTextField', + 'props': { + 'model': 'token', + 'label': 'PushPlus令牌', + 'placeholder': 'c3f0**', + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12 + }, + 'content': [ + { + 'component': 'VSelect', + 'props': { + 'multiple': True, + 'chips': True, + 'model': 'msgtypes', + 'label': '消息类型', + 'items': MsgTypeOptions + } + } + ] + } + ] + }, + ] + } + ], { + "enabled": False, + 'token': '', + 'msgtypes': [] + } + + def get_page(self) -> List[dict]: + pass + + @eventmanager.register(EventType.NoticeMessage) + def send(self, event: Event): + """ + 消息发送事件 + """ + if not self.get_state(): + return + + if not event.event_data: + return + + msg_body = event.event_data + # 渠道 + channel = msg_body.get("channel") + if channel: + return + # 类型 + msg_type: NotificationType = msg_body.get("type") + # 标题 + title = msg_body.get("title") + # 文本 + text = msg_body.get("text") + + if not title and not text: + logger.warn("标题和内容不能同时为空") + return + + if (msg_type and self._msgtypes + and msg_type.name not in self._msgtypes): + logger.info(f"消息类型 {msg_type.value} 未开启消息发送") + return + + try: + sc_url = "http://www.pushplus.plus/send?token=%s&title=%s&content=%s&template=json" % (self._token, urlencode(title), urlencode(text)) + res = RequestUtils().get_res(sc_url) + if res and res.status_code == 200: + ret_json = res.json() + errno = ret_json.get('errcode') + error = ret_json.get('errmsg') + if errno == 0: + logger.info("PushPlus消息发送成功") + else: + logger.warn(f"PushPlus消息发送失败,错误码:{errno},错误原因:{error}") + elif res is not None: + logger.warn(f"PushPlus消息发送失败,错误码:{res.status_code},错误原因:{res.reason}") + else: + logger.warn("PushPlus消息发送失败,未获取到返回信息") + except Exception as msg_e: + logger.error(f"PushPlus消息发送失败,{str(msg_e)}") + + def stop_service(self): + """ + 退出插件 + """ + pass From 4b5d985363e8e1f9bbc2705deab511bf4be15553 Mon Sep 17 00:00:00 2001 From: nelson Date: Mon, 8 Jan 2024 10:52:53 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0PushPlus=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=8E=A8=E9=80=81=E6=8F=92=E4=BB=B6=E7=9A=84=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/pushplusmsg/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/pushplusmsg/__init__.py b/plugins/pushplusmsg/__init__.py index 65d4b08..062f0d4 100644 --- a/plugins/pushplusmsg/__init__.py +++ b/plugins/pushplusmsg/__init__.py @@ -174,21 +174,23 @@ class PushPlusMsg(_PluginBase): try: sc_url = "http://www.pushplus.plus/send?token=%s&title=%s&content=%s&template=json" % (self._token, urlencode(title), urlencode(text)) + logger.info(f"PushPlus消息准备发送,信息内容:{sc_url}") res = RequestUtils().get_res(sc_url) if res and res.status_code == 200: + logger.info(f"PushPlus消息发送成功,返回信息:{res}") ret_json = res.json() - errno = ret_json.get('errcode') - error = ret_json.get('errmsg') - if errno == 0: + code = ret_json.get('code') + msg = ret_json.get('msg') + if code == 200: logger.info("PushPlus消息发送成功") else: - logger.warn(f"PushPlus消息发送失败,错误码:{errno},错误原因:{error}") + logger.warn(f"PushPlus消息发送,接口返回失败,错误码:{code},错误原因:{msg}") elif res is not None: logger.warn(f"PushPlus消息发送失败,错误码:{res.status_code},错误原因:{res.reason}") else: logger.warn("PushPlus消息发送失败,未获取到返回信息") except Exception as msg_e: - logger.error(f"PushPlus消息发送失败,{str(msg_e)}") + logger.error(f"PushPlus消息发送异常,{str(msg_e)}") def stop_service(self): """ From 3e14552a8c0e0938732e68daafa1328f36c21628 Mon Sep 17 00:00:00 2001 From: nelson Date: Mon, 8 Jan 2024 10:59:06 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/pushplusmsg/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9a3cf62..5979735 100644 --- a/package.json +++ b/package.json @@ -330,7 +330,7 @@ "PushPlusMsg": { "name": "PushPlus消息推送", "description": "支持使用PushPlus发送消息通知。", - "version": "1.0", + "version": "1.0.1", "icon": "Pushplus_A.png", "author": "cheng", "level": 1 diff --git a/plugins/pushplusmsg/__init__.py b/plugins/pushplusmsg/__init__.py index 062f0d4..6780248 100644 --- a/plugins/pushplusmsg/__init__.py +++ b/plugins/pushplusmsg/__init__.py @@ -16,7 +16,7 @@ class PushPlusMsg(_PluginBase): # 插件图标 plugin_icon = "Pushplus_A.png" # 插件版本 - plugin_version = "1.0" + plugin_version = "1.0.1" # 插件作者 plugin_author = "cheng" # 作者主页 From 29e3833f6c11485b1d4cba4ff2624959342648a9 Mon Sep 17 00:00:00 2001 From: nelson Date: Mon, 8 Jan 2024 11:16:37 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/pushplusmsg/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5979735..46423e4 100644 --- a/package.json +++ b/package.json @@ -330,7 +330,7 @@ "PushPlusMsg": { "name": "PushPlus消息推送", "description": "支持使用PushPlus发送消息通知。", - "version": "1.0.1", + "version": "0.1", "icon": "Pushplus_A.png", "author": "cheng", "level": 1 diff --git a/plugins/pushplusmsg/__init__.py b/plugins/pushplusmsg/__init__.py index 6780248..dac8e38 100644 --- a/plugins/pushplusmsg/__init__.py +++ b/plugins/pushplusmsg/__init__.py @@ -16,7 +16,7 @@ class PushPlusMsg(_PluginBase): # 插件图标 plugin_icon = "Pushplus_A.png" # 插件版本 - plugin_version = "1.0.1" + plugin_version = "0.1" # 插件作者 plugin_author = "cheng" # 作者主页 From 9cd9ecd5ecb726db48a6e92060dc3e52594496fd Mon Sep 17 00:00:00 2001 From: nelson Date: Mon, 8 Jan 2024 13:33:52 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9PushPlus=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=8E=A8=E9=80=81=E6=8F=92=E4=BB=B6=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/pushplusmsg/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 46423e4..e9677d9 100644 --- a/package.json +++ b/package.json @@ -330,7 +330,7 @@ "PushPlusMsg": { "name": "PushPlus消息推送", "description": "支持使用PushPlus发送消息通知。", - "version": "0.1", + "version": "0.2", "icon": "Pushplus_A.png", "author": "cheng", "level": 1 diff --git a/plugins/pushplusmsg/__init__.py b/plugins/pushplusmsg/__init__.py index dac8e38..c5bd6d2 100644 --- a/plugins/pushplusmsg/__init__.py +++ b/plugins/pushplusmsg/__init__.py @@ -173,7 +173,7 @@ class PushPlusMsg(_PluginBase): return try: - sc_url = "http://www.pushplus.plus/send?token=%s&title=%s&content=%s&template=json" % (self._token, urlencode(title), urlencode(text)) + sc_url = "http://www.pushplus.plus/send?token=%s&title=%s&content=%s&template=json" % (self._token, title, text) logger.info(f"PushPlus消息准备发送,信息内容:{sc_url}") res = RequestUtils().get_res(sc_url) if res and res.status_code == 200: @@ -190,7 +190,7 @@ class PushPlusMsg(_PluginBase): else: logger.warn("PushPlus消息发送失败,未获取到返回信息") except Exception as msg_e: - logger.error(f"PushPlus消息发送异常,{str(msg_e)}") + logger.error(f"PushPlus消息发送异常,{msg_e}") def stop_service(self): """ From 670bde481df44d3d8d31b7893b95775b949a799a Mon Sep 17 00:00:00 2001 From: nelson Date: Mon, 8 Jan 2024 13:42:18 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9PushPlus=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=8E=A8=E9=80=81=E6=8F=92=E4=BB=B6=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/pushplusmsg/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pushplusmsg/__init__.py b/plugins/pushplusmsg/__init__.py index c5bd6d2..8dd8731 100644 --- a/plugins/pushplusmsg/__init__.py +++ b/plugins/pushplusmsg/__init__.py @@ -16,7 +16,7 @@ class PushPlusMsg(_PluginBase): # 插件图标 plugin_icon = "Pushplus_A.png" # 插件版本 - plugin_version = "0.1" + plugin_version = "0.2" # 插件作者 plugin_author = "cheng" # 作者主页 From ff1a38fc68778df99bae4b28cfea1a44f5b28c4e Mon Sep 17 00:00:00 2001 From: nelson Date: Mon, 8 Jan 2024 14:16:50 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9PushPlus=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=8E=A8=E9=80=81=E6=8F=92=E4=BB=B6=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/pushplusmsg/__init__.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index e9677d9..0423b12 100644 --- a/package.json +++ b/package.json @@ -330,7 +330,7 @@ "PushPlusMsg": { "name": "PushPlus消息推送", "description": "支持使用PushPlus发送消息通知。", - "version": "0.2", + "version": "0.3", "icon": "Pushplus_A.png", "author": "cheng", "level": 1 diff --git a/plugins/pushplusmsg/__init__.py b/plugins/pushplusmsg/__init__.py index 8dd8731..e97638e 100644 --- a/plugins/pushplusmsg/__init__.py +++ b/plugins/pushplusmsg/__init__.py @@ -16,7 +16,7 @@ class PushPlusMsg(_PluginBase): # 插件图标 plugin_icon = "Pushplus_A.png" # 插件版本 - plugin_version = "0.2" + plugin_version = "0.3" # 插件作者 plugin_author = "cheng" # 作者主页 @@ -173,11 +173,16 @@ class PushPlusMsg(_PluginBase): return try: - sc_url = "http://www.pushplus.plus/send?token=%s&title=%s&content=%s&template=json" % (self._token, title, text) - logger.info(f"PushPlus消息准备发送,信息内容:{sc_url}") - res = RequestUtils().get_res(sc_url) + sc_url = "http://www.pushplus.plus/send" + event_info = { + "token": self._token, + "title": title, + "content": text, + "template": "txt", + "channel":"wechat" + } + res = RequestUtils(content_type="application/json").post_res(sc_url, json=event_info) if res and res.status_code == 200: - logger.info(f"PushPlus消息发送成功,返回信息:{res}") ret_json = res.json() code = ret_json.get('code') msg = ret_json.get('msg') @@ -190,7 +195,7 @@ class PushPlusMsg(_PluginBase): else: logger.warn("PushPlus消息发送失败,未获取到返回信息") except Exception as msg_e: - logger.error(f"PushPlus消息发送异常,{msg_e}") + logger.error(f"PushPlus消息发送异常,{str(msg_e)}") def stop_service(self): """ From 45fdcce3ed5e5aa15969620867f6c39fd1bdc9c0 Mon Sep 17 00:00:00 2001 From: nelson Date: Mon, 8 Jan 2024 14:28:50 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9pushplus=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=B8=BA=E6=AD=A3=E5=BC=8F=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/pushplusmsg/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0423b12..9a3cf62 100644 --- a/package.json +++ b/package.json @@ -330,7 +330,7 @@ "PushPlusMsg": { "name": "PushPlus消息推送", "description": "支持使用PushPlus发送消息通知。", - "version": "0.3", + "version": "1.0", "icon": "Pushplus_A.png", "author": "cheng", "level": 1 diff --git a/plugins/pushplusmsg/__init__.py b/plugins/pushplusmsg/__init__.py index e97638e..dfca44b 100644 --- a/plugins/pushplusmsg/__init__.py +++ b/plugins/pushplusmsg/__init__.py @@ -16,7 +16,7 @@ class PushPlusMsg(_PluginBase): # 插件图标 plugin_icon = "Pushplus_A.png" # 插件版本 - plugin_version = "0.3" + plugin_version = "1.0" # 插件作者 plugin_author = "cheng" # 作者主页