Skip to content

Commit

Permalink
feat: add wecom
Browse files Browse the repository at this point in the history
  • Loading branch information
jetsung committed Jan 19, 2024
1 parent b8efe5e commit 2c040cf
Show file tree
Hide file tree
Showing 16 changed files with 259 additions and 65 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ notify.send("iPush test")

## 支持平台

| 状态 | **国内**平台 | 官网 | 备注 |
| :------- | :---------------- | :-------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------- |
|**** | **钉钉群机器人** | [https://open.dingtalk.com/](https://open.dingtalk.com/document/robots/customize-robot-security-settings) |
|**** | **飞书群机器人** | [https://open.feishu.cn/](https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot) | |
|**** | **Lark 群机器人** | [https://open.larksuite.com/](https://open.larksuite.com/document/client-docs/bot-v3/add-custom-bot) | |
|**** | **Bark** | [https://day.app/2021/06/barkfaq/](https://day.app/2021/06/barkfaq/) | 仅支持 `iOS` |
|| **Chanify** | [https://www.chanify.net/](https://www.chanify.net/) | 仅支持 `iOS` |
|| **PushDeer** | https://www.pushdeer.com/ | |
| // | // | **基于微信公众号** | \\\\ |
|| **PushPlus** | [https://www.pushplus.plus/](https://www.pushplus.plus/doc) | |
|| **Showdoc** | [https://push.showdoc.com.cn/](https://www.showdoc.com.cn/push) | |
|| **息知** | [https://xz.qqoq.net/](https://xz.qqoq.net/) | |
|| **聚合云推** | [https://tui.juhe.cn/](https://tui.juhe.cn/docs) | 聚合推送。支持 `邮箱``微信公众号``钉钉机器人``WebHook``企业微信``Bark` |
| 状态 | **国内**平台 | 官网 | 备注 |
| :------- | :------------------- | :--------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------- |
|**** | **钉钉群机器人** | [https://open.dingtalk.com/](https://open.dingtalk.com/document/robots/customize-robot-security-settings) |
|**** | **飞书群机器人** | [https://open.feishu.cn/](https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot) | |
|**** | **Lark 群机器人** | [https://open.larksuite.com/](https://open.larksuite.com/document/client-docs/bot-v3/add-custom-bot) | |
|**** | **Bark** | [https://day.app/2021/06/barkfaq/](https://day.app/2021/06/barkfaq/) | 仅支持 `iOS` |
|| **Chanify** | [https://www.chanify.net/](https://www.chanify.net/) | 仅支持 `iOS` |
|| **PushDeer** | https://www.pushdeer.com/ | |
|**** | **企业微信群机器人** | [https://developer.work.weixin.qq.com](https://developer.work.weixin.qq.com/document/path/91770?notreplace=true) | |
| // | // | **基于微信公众号** | \\\\ |
|| **PushPlus** | [https://www.pushplus.plus/](https://www.pushplus.plus/doc) | |
|| **Showdoc** | [https://push.showdoc.com.cn/](https://www.showdoc.com.cn/push) | |
|| **息知** | [https://xz.qqoq.net/](https://xz.qqoq.net/) | |
|| **聚合云推** | [https://tui.juhe.cn/](https://tui.juhe.cn/docs) | 聚合推送。支持 `邮箱``微信公众号``钉钉机器人``WebHook``企业微信``Bark` |

| 状态 | **国外**平台 | 官网 | 备注 |
| :------- | :----------- | :-------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand Down
87 changes: 53 additions & 34 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,122 +15,141 @@ pip install ipush
```python
from ipush import Dingtalk

notify = Dingtalk("token", "secret")
notify.send("ipush test")
notify = Dingtalk('token', "secret")
notify.send('ipush test')
# or 'text', 'markdown'
notify.settype('markdown').send('**ipush** markdown test')
```

- **飞书群**

```python
from ipush import Feishu

notify = Feishu("token", "secret")
notify.send("ipush test")
notify = Feishu('token', "secret")
notify.send('ipush test')
```

- **Lark 群**

```python
from ipush import Lark

notify = Lark("token", "secret")
notify.send("ipush test")
notify = Lark('token', "secret")
notify.send('ipush test')
```

- **Bark**

```python
from ipush import Bark

notify = Bark("token")
notify.send("ipush test", "title")
notify.seturl("https://self-hosted")
notify.send("ipush test custom url")
notify = Bark('token')
notify.send('ipush test', 'title')
notify.seturl('https://self-hosted')
notify.send('ipush test custom url')
```

- **Chanify**

```python
from ipush import Chanify

notify = Chanify("token")
notify.send("ipush test")
notify.seturl("https://self-hosted")
notify.send("ipush test custom url")
notify = Chanify('token')
notify.send('ipush test')
notify.seturl('https://self-hosted')
notify.send('ipush test custom url')
```

- **PushDeer**

```python
from ipush import PushDeer

notify = PushDeer("token")
notify.send("ipush test")
notify.seturl("https://self-hosted")
notify.send("ipush test custom url")
notify = PushDeer('token')
notify.send('ipush test')
notify.seturl('https://self-hosted')
notify.send('ipush test custom url')
# or 'text', 'markdown'
notify.settype('text').send('ipush test')
```

- **PushPlus**

```python
from ipush import PushPlus

notify = PushPlus("token")
notify.send("ipush test", "title")
notify = PushPlus('token')
notify.send('ipush test', 'title')
# or 'html', 'markdown', 'txt', 'json'
notify.settemplate('markdown').send('**ipush** markdown test')
```

- **Showdoc**

```python
from ipush import Showdoc

notify = Showdoc("token")
notify.send("ipush test", "title")
notify = Showdoc('token')
notify.send('ipush test', 'title')
```

- **Xizhi**

```python
from ipush import Xizhi

notify = Xizhi("token")
notify.send("ipush test", "title")
notify = Xizhi('token')
notify.send('ipush test', 'title')
```

- **Telegram**

```python
from ipush import Telegram

notify = Telegram("token")
notify.send("ipush test", "chat_id")
notify.seturl("https://self-hosted")
notify.send("ipush test custom url")
notify = Telegram('token')
notify.send('ipush test', 'chat_id')
notify.seturl('https://self-hosted')
notify.send('ipush test custom url')
```

- **Alertzy**

```python
from ipush import Alertzy

notify = Alertzy("token")
notify.send("ipush test", "title")
notify = Alertzy('token')
notify.send('ipush test', 'title')
```

- **Notify**

```python
from ipush import Notify

notify = Notify("token", "user_id")
notify.send("ipush test", "title")
notify = Notify('token', "user_id")
notify.send('ipush test', 'title')
```

- **Juhe**

```python
from ipush import Juhe

notify = Juhe("token", "service_id")
notify.send("ipush test", "title")
notify = Juhe('token', 'service_id')
notify.send('ipush test', 'title')
# or 'html', 'markdown', 'txt', 'json'
notify.setdoctype('markdown').send('**ipush** markdown test')
```

- **WeCom**

```python
from ipush import WeCom

notify = WeCom('token')
notify.send('ipush test', 'title')
# or 'text', 'markdown'
notify.setmsgtype('markdown').send('**ipush** markdown test')
```
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "ipush"
version = "0.5.0"
description = "向 APP、微信平台推送通知。支持 Telegram、钉钉群、飞书群、Lark 群、Bark 等平台。"
version = "0.6.0"
description = "向 APP、微信平台推送通知。支持 Telegram、钉钉群、飞书群、企业微信群、Lark 群、Bark 等平台。"
authors = [
{ name = "Jetsung Chan", email = "[email protected]" }
]
Expand All @@ -10,7 +10,7 @@ dependencies = [
"lxml>=4.9.4",
]
readme = "README.md"
keywords = ["push", "notify", "telegram", "dingtalk", "feishu", "lark", "bark", "chanify", "pushdeer", "pushplus", "showdoc", "xizhi"]
keywords = ["push", "notify", "telegram", "dingtalk", "feishu", "wechat", "lark", "bark", "chanify", "pushdeer", "pushplus", "showdoc", "xizhi"]
requires-python = ">= 3.8"
classifiers = [
'Development Status :: 4 - Beta',
Expand Down
1 change: 1 addition & 0 deletions src/ipush/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
from .provider.pushplus import PushPlus
from .provider.showdoc import Showdoc
from .provider.telegram import Telegram
from .provider.wecom import WeCom
from .provider.xizhi import Xizhi
6 changes: 3 additions & 3 deletions src/ipush/provider/chanify.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ def __init__(self, token=''):
def _signature(self):
pass

def seturl(self, url):
self.url = url

def _geturl(self):
"""
生成请求的 URL
"""
return f'{self.url}/v1/sender/{self.token}'

def seturl(self, url):
self.url = url

def send(self, message):
"""
发送通知
Expand Down
18 changes: 14 additions & 4 deletions src/ipush/provider/dingtalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Dingtalk(Provider):
def __init__(self, token='', secret=''):
self.token = token
self.secret = secret
self.msgtype = 'text'

def _signature(self):
"""
Expand All @@ -32,7 +33,15 @@ def _geturl(self, sign):
"""
return f'https://oapi.dingtalk.com/robot/send?access_token={self.token}{sign}'

def send(self, message):
def setmsgtype(self, msgtype):
"""
设置消息类型
:param msgtype: 消息类型
"""
self.msgtype = msgtype if msgtype in ['text', 'markdown'] else 'text'
return self

def send(self, message, title=''):
"""
发送通知
:param message: 消息内容
Expand All @@ -49,9 +58,10 @@ def send(self, message):
req.update_headers(headers)

data = {
'msgtype': 'text',
'text': {
'content': message,
'msgtype': self.msgtype,
self.msgtype: {
'title': '新消息' if title == '' else title,
'content' if self.msgtype != 'markdown' else 'text': message,
},
}
data = json.dumps(data, indent=4)
Expand Down
8 changes: 8 additions & 0 deletions src/ipush/provider/juhe.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Juhe(Provider):
def __init__(self, token='', service_id=''):
self.token = token
self.service_id = service_id
self.doc_type = 'txt'

def _signature(self):
pass
Expand All @@ -20,6 +21,12 @@ def _geturl(self):
"""
return 'https://tui.juhe.cn/api/plus/pushApi'

def setdoctype(self, doc_type):
self.doc_type = (
doc_type if doc_type in ['html', 'markdown', 'txt', 'json'] else 'txt'
)
return self

def send(self, message, title=''):
"""
发送通知
Expand All @@ -34,6 +41,7 @@ def send(self, message, title=''):
'service_id': self.service_id,
'title': '新消息' if title == '' else title,
'content': message,
'doc_type': self.doc_type,
}
req.post(req_url, data)
return req.response
12 changes: 9 additions & 3 deletions src/ipush/provider/pushdeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ class PushDeer(Provider):

def __init__(self, token=''):
self.token = token
self.type = 'markdown'
self.url = 'https://api2.pushdeer.com'

def _signature(self):
pass

def seturl(self, url):
self.url = url

def _geturl(self):
"""
生成请求的 URL
"""
return f'{self.url}/message/push'

def seturl(self, url):
self.url = url
return self

def settype(self, type):
self.type = type if type in ['text', 'markdown'] else 'markdown'
return self

def send(self, message):
"""
发送通知
Expand Down
10 changes: 9 additions & 1 deletion src/ipush/provider/pushplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class PushPlus(Provider):

def __init__(self, token=''):
self.token = token
self.template = 'html'

def _signature(self):
pass
Expand All @@ -21,6 +22,12 @@ def _geturl(self):
"""
return 'https://www.pushplus.plus/send'

def settemplate(self, template):
self.template = (
template if template in ['html', 'markdown', 'txt', 'json'] else 'html'
)
return self

def send(self, message, title=''):
"""
发送通知
Expand All @@ -35,9 +42,10 @@ def send(self, message, title=''):
req.update_headers(headers)

data = {
'token': self.token,
'title': '新消息' if title == '' else title,
'content': message,
'token': self.token,
'template': self.template,
}
data = json.dumps(data, indent=4)
req.post(req_url, data=data.encode('utf-8'))
Expand Down
Loading

0 comments on commit 2c040cf

Please sign in to comment.