Update app.py
Browse files
app.py
CHANGED
@@ -1033,34 +1033,31 @@ def get_order():
|
|
1033 |
logging.debug("Starting get_order")
|
1034 |
|
1035 |
# Читаем параметры из POST-запроса
|
1036 |
-
vkid =
|
1037 |
-
order =
|
1038 |
-
apps_id =
|
1039 |
-
sign =
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
logging.error("Invalid apps_id")
|
1051 |
return json.dumps({"error": "Invalid apps_id"}), 400
|
1052 |
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
#
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
logging.error("Invalid signature")
|
1061 |
-
return json.dumps({"error": "Invalid signature"}), 400
|
1062 |
|
1063 |
-
#
|
1064 |
conn = sqlite3.connect(DATABASE_NEW)
|
1065 |
cursor = conn.cursor()
|
1066 |
|
@@ -1068,26 +1065,15 @@ def get_order():
|
|
1068 |
cursor.execute("SELECT orders FROM contacts WHERE vk_id = ?", (vkid,))
|
1069 |
result = cursor.fetchone()
|
1070 |
|
1071 |
-
# Если запись по vk_id не найдена, возвращаем значение "not" для ордера
|
1072 |
if not result:
|
1073 |
logging.error(f"VK ID {vkid} not found")
|
1074 |
response = {order: 'not'}
|
1075 |
return jsonify(response), 200
|
1076 |
|
1077 |
shop_st = result[0] if result[0] else '{}'
|
1078 |
-
|
1079 |
-
shop_st_data = json.loads(shop_st)
|
1080 |
-
except json.JSONDecodeError as e:
|
1081 |
-
logging.error(f"JSON decoding error for shop_st: {e}")
|
1082 |
-
return jsonify({"error": f"Invalid JSON format for shop_st: {e}"}), 400
|
1083 |
-
|
1084 |
logging.debug(f"Existing record found. Loaded JSON: {shop_st_data}")
|
1085 |
|
1086 |
-
# Проверяем, есть ли в данных необходимый ордер
|
1087 |
-
if order not in shop_st_data:
|
1088 |
-
logging.error(f"Order '{order}' not found in shop_st data")
|
1089 |
-
return jsonify({"error": f"Order '{order}' not found"}), 400
|
1090 |
-
|
1091 |
# Ищем значение по ключу order
|
1092 |
value = shop_st_data.get(order, 'not')
|
1093 |
|
@@ -1095,12 +1081,10 @@ def get_order():
|
|
1095 |
response = {order: value}
|
1096 |
return jsonify(response), 200
|
1097 |
|
1098 |
-
except KeyError as e:
|
1099 |
-
logging.error(f"KeyError: Missing key {e}")
|
1100 |
-
return jsonify({"error": f"Missing key: {e}"}), 400
|
1101 |
except Exception as e:
|
1102 |
-
logging.error(f"An
|
1103 |
-
return
|
|
|
1104 |
|
1105 |
|
1106 |
|
|
|
1033 |
logging.debug("Starting get_order")
|
1034 |
|
1035 |
# Читаем параметры из POST-запроса
|
1036 |
+
vkid = request.form.get('vk_id', '')
|
1037 |
+
order = request.form.get('order', '')
|
1038 |
+
apps_id = request.form.get('apps_id', '') # ИД ВК приложения
|
1039 |
+
sign = request.form.get('sign', '') # Подпись
|
1040 |
+
|
1041 |
+
# Проверка на обязательные параметры
|
1042 |
+
if not vkid or not order or not apps_id or not sign:
|
1043 |
+
logging.error("VK ID, order, apps_id, and sign are required")
|
1044 |
+
return json.dumps({"error": "VK ID, order, apps_id, and sign are required"}), 400
|
1045 |
+
|
1046 |
+
# Валидация подписи
|
1047 |
+
secret_key = api_key_apps_vk.get(apps_id)
|
1048 |
+
if not secret_key:
|
1049 |
+
logging.error(f"Secret key not found for apps_id: {apps_id}")
|
|
|
1050 |
return json.dumps({"error": "Invalid apps_id"}), 400
|
1051 |
|
1052 |
+
# Здесь должна быть логика проверки подписи
|
1053 |
+
# Для примера предполагаем, что подпись — это хэш от данных запроса, сгенерированный с помощью secret_key
|
1054 |
+
# Псевдокод для проверки подписи:
|
1055 |
+
expected_sign = generate_sign(vkid, order, secret_key) # Здесь предполагаемая функция для генерации подписи
|
1056 |
+
if sign != expected_sign:
|
1057 |
+
logging.error(f"Invalid sign. Expected {expected_sign}, got {sign}")
|
1058 |
+
return json.dumps({"error": "Invalid sign"}), 400
|
|
|
|
|
1059 |
|
1060 |
+
# Если подпись валидна, продолжаем обработку
|
1061 |
conn = sqlite3.connect(DATABASE_NEW)
|
1062 |
cursor = conn.cursor()
|
1063 |
|
|
|
1065 |
cursor.execute("SELECT orders FROM contacts WHERE vk_id = ?", (vkid,))
|
1066 |
result = cursor.fetchone()
|
1067 |
|
|
|
1068 |
if not result:
|
1069 |
logging.error(f"VK ID {vkid} not found")
|
1070 |
response = {order: 'not'}
|
1071 |
return jsonify(response), 200
|
1072 |
|
1073 |
shop_st = result[0] if result[0] else '{}'
|
1074 |
+
shop_st_data = json.loads(shop_st)
|
|
|
|
|
|
|
|
|
|
|
1075 |
logging.debug(f"Existing record found. Loaded JSON: {shop_st_data}")
|
1076 |
|
|
|
|
|
|
|
|
|
|
|
1077 |
# Ищем значение по ключу order
|
1078 |
value = shop_st_data.get(order, 'not')
|
1079 |
|
|
|
1081 |
response = {order: value}
|
1082 |
return jsonify(response), 200
|
1083 |
|
|
|
|
|
|
|
1084 |
except Exception as e:
|
1085 |
+
logging.error(f"An error occurred: {str(e)}")
|
1086 |
+
return json.dumps({"error": str(e)}), 500
|
1087 |
+
|
1088 |
|
1089 |
|
1090 |
|