|
|
|
@@ -14,6 +14,9 @@ CORS(app)
|
|
|
|
|
def get_csv_path():
|
|
|
|
|
return os.path.join(os.path.dirname(__file__), 'Authorize.csv')
|
|
|
|
|
|
|
|
|
|
def get_info_csv_path():
|
|
|
|
|
return os.path.join(os.path.dirname(__file__), 'Information.csv')
|
|
|
|
|
|
|
|
|
|
def get_public_key():
|
|
|
|
|
csv_path = get_csv_path()
|
|
|
|
|
if not os.path.exists(csv_path):
|
|
|
|
@@ -31,6 +34,57 @@ def get_current_time():
|
|
|
|
|
return datetime(time_data['year'], time_data['month'], time_data['day'])
|
|
|
|
|
else:
|
|
|
|
|
raise Exception("请求时间失败")
|
|
|
|
|
|
|
|
|
|
@app.route('/check_time', methods=['POST'])
|
|
|
|
|
def check_time():
|
|
|
|
|
current_time = get_current_time()
|
|
|
|
|
csv_path = get_info_csv_path()
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(csv_path):
|
|
|
|
|
return jsonify({"valid": False, "message": "信息文件不存在"}), 404
|
|
|
|
|
|
|
|
|
|
df = pd.read_csv(csv_path)
|
|
|
|
|
if df.empty:
|
|
|
|
|
return jsonify({"valid": False, "message": "信息文件为空"}), 404
|
|
|
|
|
|
|
|
|
|
start_time = datetime.strptime(df['StartTime'].iloc[0], '%Y-%m-%d')
|
|
|
|
|
end_time = datetime.strptime(df['EndTime'].iloc[0], '%Y-%m-%d')
|
|
|
|
|
|
|
|
|
|
time_range_message = f"有效时间范围: {start_time.strftime('%Y-%m-%d')} 到 {end_time.strftime('%Y-%m-%d')}"
|
|
|
|
|
|
|
|
|
|
if start_time <= current_time <= end_time:
|
|
|
|
|
days_remaining = (end_time - current_time).days
|
|
|
|
|
return jsonify({
|
|
|
|
|
"valid": True,
|
|
|
|
|
"message": f"{time_range_message}",
|
|
|
|
|
"days_remaining": days_remaining
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return jsonify({
|
|
|
|
|
"valid": False,
|
|
|
|
|
"message": f"{time_range_message}"
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
@app.route('/navigate', methods=['POST'])
|
|
|
|
|
def navigate():
|
|
|
|
|
current_time = get_current_time()
|
|
|
|
|
csv_path = get_info_csv_path()
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(csv_path):
|
|
|
|
|
return jsonify({"valid": False, "message": "信息文件不存在"}), 404
|
|
|
|
|
|
|
|
|
|
df = pd.read_csv(csv_path)
|
|
|
|
|
if df.empty:
|
|
|
|
|
return jsonify({"valid": False, "message": "信息文件为空"}), 404
|
|
|
|
|
|
|
|
|
|
start_time = datetime.strptime(df['StartTime'].iloc[0], '%Y-%m-%d')
|
|
|
|
|
end_time = datetime.strptime(df['EndTime'].iloc[0], '%Y-%m-%d')
|
|
|
|
|
|
|
|
|
|
if start_time <= current_time <= end_time:
|
|
|
|
|
return jsonify({"valid": True, "redirect": "device"})
|
|
|
|
|
|
|
|
|
|
return jsonify({"valid": False, "redirect": "error"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/verify', methods=['POST', 'OPTIONS'])
|
|
|
|
|
def handle_verification():
|
|
|
|
@@ -59,6 +113,11 @@ def handle_verification():
|
|
|
|
|
# Format current_time to "YYYY-MM-DD"
|
|
|
|
|
current_time_str = current_time.strftime('%Y-%m-%d') if current_time else None
|
|
|
|
|
|
|
|
|
|
# Save signature and timestamps to Information.csv if valid
|
|
|
|
|
if is_valid:
|
|
|
|
|
start_time, end_time = time_range
|
|
|
|
|
save_to_information_csv(signature_data, start_time, end_time)
|
|
|
|
|
|
|
|
|
|
return jsonify({
|
|
|
|
|
"valid": is_valid,
|
|
|
|
|
"message": message["time_range"],
|
|
|
|
@@ -107,12 +166,32 @@ def verify_signature(public_key_pem, signature_data):
|
|
|
|
|
end_time = datetime.strptime(end_timestamp_str, '%Y-%m-%d')
|
|
|
|
|
|
|
|
|
|
if start_time <= current_time <= end_time:
|
|
|
|
|
return True, {"valid": True, "time_range": f"成功。时间范围: {start_time.year}-{start_time.month}-{start_time.day}到{end_time.year}-{end_time.month}- {end_time.day}"}, (start_time, end_time), current_time
|
|
|
|
|
return True, {"valid": True, "time_range": f"成功。时间范围: {start_time.year}-{start_time.month}-{start_time.day}到{end_time.year}-{end_time.month}-{end_time.day}"}, (start_time, end_time), current_time
|
|
|
|
|
else:
|
|
|
|
|
return False, {"valid": False, "time_range": f"时间不在有效范围内。时间范围: {start_time.year}-{start_time.month}-{start_time.day}到{end_time.year}-{end_time.month}- {end_time.day}"}, (start_time, end_time), current_time
|
|
|
|
|
return False, {"valid": False, "time_range": f"时间不在有效范围内。时间范围: {start_time.year}-{start_time.month}-{start_time.day}到{end_time.year}-{end_time.month}-{end_time.day}"}, (start_time, end_time), current_time
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print("发生错误:", str(e))
|
|
|
|
|
return False, {"valid": False, "time_range": f"发生错误: {str(e)}"}, None, None
|
|
|
|
|
return False, {"valid": False, "time_range": f"请输入正确的授权码"}, None, None
|
|
|
|
|
|
|
|
|
|
def save_to_information_csv(signature_data, start_time, end_time):
|
|
|
|
|
csv_path = get_info_csv_path()
|
|
|
|
|
|
|
|
|
|
# 创建DataFrame
|
|
|
|
|
data = {
|
|
|
|
|
'SignatureData': [signature_data],
|
|
|
|
|
'StartTime': [start_time.strftime('%Y-%m-%d')],
|
|
|
|
|
'EndTime': [end_time.strftime('%Y-%m-%d')]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 如果文件存在,先读取数据
|
|
|
|
|
if os.path.exists(csv_path):
|
|
|
|
|
existing_df = pd.read_csv(csv_path)
|
|
|
|
|
# 清空文件内容
|
|
|
|
|
existing_df.to_csv(csv_path, index=False, header=False)
|
|
|
|
|
|
|
|
|
|
# 将新的数据写入CSV文件
|
|
|
|
|
df = pd.DataFrame(data)
|
|
|
|
|
df.to_csv(csv_path, index=False)
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
app.run(debug=True, host='0.0.0.0', port=5001)
|
|
|
|
|