Skip to content

Commit

Permalink
Merge pull request #408 from WittF/main
Browse files Browse the repository at this point in the history
添加Server酱推送
  • Loading branch information
mikumifa authored Aug 4, 2024
2 parents dcb8d15 + d5198d7 commit 3fac776
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 24 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ Running on local URL: http://127.0.0.1:xxx
<table>
<tbody>
<tr>
<td align="center">
<a href="https://github.com/WittF">
<img src="https://avatars.githubusercontent.com/u/108567138?v=4" width="100;" alt="WittF"/>
<br />
<sub><b>W1ttF</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/mikumifa">
<img src="https://avatars.githubusercontent.com/u/99951454?v=4" width="100;" alt="mikumifa"/>
Expand All @@ -78,13 +85,6 @@ Running on local URL: http://127.0.0.1:xxx
<sub><b>gpc123456</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/WittF">
<img src="https://avatars.githubusercontent.com/u/108567138?v=4" width="100;" alt="WittF"/>
<br />
<sub><b>W1ttF</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Amorter">
<img src="https://avatars.githubusercontent.com/u/63935225?v=4" width="100;" alt="Amorter"/>
Expand Down
14 changes: 10 additions & 4 deletions tab/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from geetest.CapSolverValidator import CapSolverValidator
from geetest.NormalValidator import NormalValidator
from geetest.RROCRValidator import RROCRValidator
from util import PlusUtil
from util import PushPlusUtil
from util import ServerChanUtil
from util.dynimport import bili_ticket_gt_python
from util.error import ERRNO_DICT, withTimeString
from util.order_qrcode import get_qrcode_url
Expand Down Expand Up @@ -625,9 +626,14 @@ def inner_request():
gr.update(),
gr.update(),
]
plusToken = configDB.get("plusToken")
if plusToken is not None and plusToken != "":
PlusUtil.send_message(plusToken, "抢票成功", "前往订单中心付款吧")
pushplusToken = configDB.get("pushplusToken")
if pushplusToken is not None and pushplusToken != "":
PushPlusUtil.send_message(pushplusToken, "抢票成功", "前往订单中心付款吧")

serverchanToken = configDB.get("serverchanToken")
if serverchanToken is not None and serverchanToken != "":
ServerChanUtil.send_message(serverchanToken, "抢票成功", "前往订单中心付款吧")

if audio_path is not None and audio_path != "":
def play_sound_in_loop(file_path):
while True:
Expand Down
38 changes: 26 additions & 12 deletions tab/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,34 @@ def add():
outputs=[info_ui, username_ui, gr_file_ui]
)
gr.Markdown("""
> **微信消息推送功能如何添加**
> 参考 https://cloud.tencent.com/developer/article/2139538
> 粘贴token到下面即可
> 关闭的方式是直接删除token即可
""")
> **微信消息推送功能如何添加**
> [Server酱](https://sct.ftqq.com/) 和 [pushplus](https://www.pushplus.plus/)
> 等哪个哥们有空写个wiki
> 留空则表示不使用提醒功能
> 关闭直接删除token即可
""")
with gr.Row():
plus_ui = gr.Textbox(
value=configDB.get("plusToken") if configDB.get("plusToken") is not None else "",
label="PlusPlus的Token",
serverchan_ui = gr.Textbox(
value=configDB.get("serverchanToken") if configDB.get("serverchanToken") is not None else "",
label="Server酱的Token",
interactive=True,
info="留空则表示不使用PlusPlus的提醒功能",
info="[https://sct.ftqq.com/](https://sct.ftqq.com/)",
)

def inner_input(x):
return configDB.insert("plusToken", x)
pushplus_ui = gr.Textbox(
value=configDB.get("pushplusToken") if configDB.get("pushplusToken") is not None else "",
label="pushplus的Token",
interactive=True,
info="[https://www.pushplus.plus/](https://www.pushplus.plus/)",
)

def inner_input_serverchan(x):
return configDB.insert("serverchanToken", x)
def inner_input_pushplus(x):
return configDB.insert("pushplusToken", x)

serverchan_ui.change(fn=inner_input_serverchan, inputs=serverchan_ui)

pushplus_ui.change(fn=inner_input_pushplus, inputs=pushplus_ui)

plus_ui.change(fn=inner_input, inputs=plus_ui)
2 changes: 1 addition & 1 deletion util/PlusUtil.py → util/PushPlusUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def send_message(token, content, title):
}
requests.post(url, headers=headers, data=json.dumps(data))
except Exception as e:
loguru.logger.info("PlusPlus消息发送失败")
loguru.logger.info("pushplus消息发送失败")



Expand Down
31 changes: 31 additions & 0 deletions util/ServerChanUtil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import json

import loguru
import requests
import playsound
import os

from config import get_application_tmp_path


def send_message(token, desp, title):
try:
url = f"https://sctapi.ftqq.com/{token}.send"
headers = {
"Content-Type": "application/json"
}

data = {
"desp": desp,
"title": title
}
requests.post(url, headers=headers, data=json.dumps(data))
except Exception as e:
loguru.logger.info("ServerChan消息发送失败")





if __name__ == '__main__':
playsound.playsound(os.path.join(get_application_tmp_path(), "default.mp3"))

0 comments on commit 3fac776

Please sign in to comment.