Skip to content

Commit

Permalink
Server酱推送渠道可配置修改
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadownc committed Oct 8, 2024
1 parent fd68ba3 commit 66ab88a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/follow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
FOLLOW_COOKIE: ${{ secrets.FOLLOW_COOKIE }}
WEBHOOK_KEY: ${{ secrets.WEBHOOK_KEY }}
SERVER_CHAN_KEY: ${{ secrets.SERVER_CHAN_KEY }}
SERVER_CHAN_CHANNEL: ${{secrets.SERVER_CHAN_CHANNEL}}
QMSG_KEY: ${{ secrets.QMSG_KEY }}
run: |
python scripts/follow.py
1 change: 1 addition & 0 deletions .github/workflows/webp-cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
WEBPCLOUD_TOKEN: ${{ secrets.WEBPCLOUD_TOKEN }}
WEBHOOK_KEY: ${{ secrets.WEBHOOK_KEY }}
SERVER_CHAN_KEY: ${{ secrets.SERVER_CHAN_KEY }}
SERVER_CHAN_CHANNEL: ${{secrets.SERVER_CHAN_CHANNEL}}
QMSG_KEY: ${{ secrets.QMSG_KEY }}
run: |
python scripts/webpCloud.py
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
**配置步骤:**
1. 前往 `GitHub` 仓库的 `Settings` > `Secrets and variables` > `Actions`
2. 添加名称为 `SERVER_CHAN_KEY` 的新 `secret`,并将管理后台的`key` 作为值输入。
3. 添加名称为`SERVER_CHAN_CHANNEL` 不设置则为默认推送渠道 具体值详见文档。

### **Qmsg酱消息推送**
[文档地址](https://qmsg.zendee.cn/)
Expand Down
12 changes: 7 additions & 5 deletions utils/serve_chan_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,29 @@

def send_server_chan_notification(title, desp):
server_chan_key = os.getenv('SERVER_CHAN_KEY')
channel = os.getenv('SERVER_CHAN_CHANNEL', '9') # 从环境变量读取channel 默认为9

# 检查 server_chan_key 是否为 None 或空字符串
if not server_chan_key:
print("⚠️ SERVER_CHAN_KEY 未设置 请设置后重试!")
return

data = {
'title': title,
'desp': desp
}

# 根据 server_chan_key 的前缀决定使用不同的推送URL
if server_chan_key.startswith('sctp'):
server_chan_url = f'https://{server_chan_key}.push.ft07.com/send'
else:
server_chan_url = f'https://sctapi.ftqq.com/{server_chan_key}.send'
data['channel'] = channel # 推送通道 默认9

headers = {
'Content-Type': 'application/json;charset=utf-8'
}

data = {
'title': title,
'desp': desp
}

try:
response = requests.post(server_chan_url, json=data, headers=headers)
response.raise_for_status()
Expand Down

0 comments on commit 66ab88a

Please sign in to comment.