-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from nfe-w/feat/push-channel/wecom-bot
Feat/push channel/wecom bot
- Loading branch information
Showing
7 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
|
||
from common import util | ||
from common.logger import log | ||
from . import PushChannel | ||
|
||
|
||
class WeComBot(PushChannel): | ||
def __init__(self, config): | ||
super().__init__(config) | ||
self.key = str(config.get("key", "")) | ||
if self.key == "": | ||
log.error(f"【推送_{self.name}】配置不完整,推送功能将无法正常使用") | ||
|
||
def push(self, title, content, jump_url=None, pic_url=None): | ||
push_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send" | ||
headers = { | ||
"Content-Type": "application/json" | ||
} | ||
params = { | ||
"key": self.key | ||
} | ||
body = { | ||
"msgtype": "news", | ||
"news": { | ||
"articles": [ | ||
{ | ||
"title": title, | ||
"description": content, | ||
"url": jump_url, | ||
} | ||
] | ||
} | ||
} | ||
|
||
if pic_url is not None: | ||
body["news"]["articles"][0]["picurl"] = pic_url | ||
|
||
response = util.requests_post(push_url, self.name, headers=headers, params=params, data=json.dumps(body)) | ||
push_result = "成功" if util.check_response_is_ok(response) else "失败" | ||
log.info(f"【推送_{self.name}】{push_result}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ PyYAML==6.0.1 | |
requests==2.31.0 | ||
requests_toolbelt==1.0.0 | ||
schedule==1.2.1 | ||
urllib3==1.26.9 |