使用要求:电脑,手机处于同一局域网
接收到验证码后电脑右下角会有系统弹窗。

微信图片编辑_20250506103011.jpg (114.72 KB, 下载次数: 0)
下载附件
2025-5-6 10:31 上传
环境:python 3.9
系统:win10 神州网信版 21H2
手机:iphon
python代码如下:
[Python] 纯文本查看 复制代码from flask import Flask, request, jsonify
import time
import logging
from win10toast import ToastNotifier
from datetime import datetime
app = Flask(__name__)
# 配置日志
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
# 存储验证码的全局变量
verification_codes = {}
# 验证码有效期(秒)
CODE_EXPIRE_TIME = 300
# 创建通知器实例
toaster = ToastNotifier()
def send_notification(code, client_ip):
"""
发送桌面通知
"""
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
message = f'验证码: {code}\n来源IP: {client_ip}\n接收时间: {current_time}\n有效期: {CODE_EXPIRE_TIME}秒'
try:
toaster.show_toast(
"验证码提醒",
message,
duration=10, # 显示10秒
threaded=True # 使用线程显示通知,避免阻塞主程序
)
except Exception as e:
logger.error(f"发送通知失败: {str(e)}")
@app.route('/api/code', methods=['POST'])
def receive_code():
"""
接收来自快捷指令的验证码
"""
data = request.json
if not data or 'code' not in data:
return jsonify({'status': 'error', 'message': 'Invalid request'}), 400
# 添加时间戳并存储验证码
code_data = {
'code': data['code'],
'timestamp': int(time.time())
}
# 获取客户端IP
client_ip = request.remote_addr
# 使用IP作为键存储验证码
verification_codes[client_ip] = code_data
# 清理过期验证码
current_time = int(time.time())
expired_keys = [ip for ip, data in verification_codes.items()
if current_time - data['timestamp'] > CODE_EXPIRE_TIME]
for ip in expired_keys:
del verification_codes[ip]
# 记录接收到的验证码信息
logger.info(f"收到验证码 - 来源IP: {client_ip}, 验证码: {data['code']}")
# 发送桌面通知
send_notification(data['code'], client_ip)
return jsonify({'status': 'success'})
@app.route('/api/codes', methods=['GET'])
def get_codes():
"""
获取所有存储的验证码
"""
# 返回时过滤掉过期验证码
current_time = int(time.time())
valid_codes = [data for data in verification_codes.values()
if current_time - data['timestamp']
IOS快捷指令设置:
快捷指令→自动化→创建个人自动化→信息→选择发件人或包含信息→下一步→添加操作→脚本→添加到变量→输入→选择输入快捷指令的信息→设置变量名称→网页→获取URL内容→http://11.234.100.97:5000/api/codes。这个地址填你实际的接口地址→发放post→请求体→{"code": "设置的变量名称"} 不要手动输入 要选择