Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1042,6 +1042,28 @@ def is_valid(*, query: dict, secret: str) -> bool:
|
|
| 1042 |
# Сравниваем с переданной подписью
|
| 1043 |
return query.get("sign") == decoded_hash_code
|
| 1044 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1045 |
# Чтение ордера по ключу и ВК ИД для приложения
|
| 1046 |
@app.route('/get_order', methods=['POST'])
|
| 1047 |
def get_order():
|
|
@@ -1053,9 +1075,8 @@ def get_order():
|
|
| 1053 |
order = request.form.get('order', '')
|
| 1054 |
apps_id = request.form.get('apps_id', '') # Сюда придёт ИД ВК приложения
|
| 1055 |
fullUrl = request.form.get('fullUrl', '') # Полный URL, который выдаёт ВКонтакте
|
| 1056 |
-
sign = request.form.get('sign', '') # Значение sign полученное при запуске приложения
|
| 1057 |
|
| 1058 |
-
logging.debug(f"Received data: vk_id={vkid}, order={order}, apps_id={apps_id}, fullUrl={fullUrl}
|
| 1059 |
|
| 1060 |
# Проверка подписи для приложения
|
| 1061 |
if str(apps_id) not in api_key_apps_vk: # Приводим apps_id к строке
|
|
@@ -1074,26 +1095,12 @@ def get_order():
|
|
| 1074 |
logging.error("Invalid signature")
|
| 1075 |
return json.dumps({"error": "Invalid signature"}), 400
|
| 1076 |
|
| 1077 |
-
#
|
| 1078 |
-
|
| 1079 |
-
|
| 1080 |
-
|
| 1081 |
-
# Ищем запись по vk_id
|
| 1082 |
-
cursor.execute("SELECT orders FROM contacts WHERE vk_id = ?", (vkid,))
|
| 1083 |
-
result = cursor.fetchone()
|
| 1084 |
-
logging.debug(f"Database result: {result}")
|
| 1085 |
-
|
| 1086 |
-
# Если запись по vk_id не найдена, возвращаем значение "not" для ордера
|
| 1087 |
-
if not result:
|
| 1088 |
-
logging.error(f"VK ID {vkid} not found")
|
| 1089 |
response = {order: 'not'}
|
| 1090 |
return jsonify(response), 200
|
| 1091 |
|
| 1092 |
-
shop_st = result[0] if result[0] else '{}'
|
| 1093 |
-
logging.debug(f"Shop_st: {shop_st}")
|
| 1094 |
-
shop_st_data = json.loads(shop_st)
|
| 1095 |
-
logging.debug(f"Existing record found. Loaded JSON: {shop_st_data}")
|
| 1096 |
-
|
| 1097 |
# Ищем значение по ключу order
|
| 1098 |
value = shop_st_data.get(order, 'not')
|
| 1099 |
logging.debug(f"Value for order {order}: {value}")
|
|
@@ -1128,7 +1135,6 @@ def get_order():
|
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
-
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
|
|
|
| 1042 |
# Сравниваем с переданной подписью
|
| 1043 |
return query.get("sign") == decoded_hash_code
|
| 1044 |
|
| 1045 |
+
# Функция для работы с базой данных
|
| 1046 |
+
def get_order_from_db(vkid):
|
| 1047 |
+
conn = sqlite3.connect(DATABASE_NEW)
|
| 1048 |
+
cursor = conn.cursor()
|
| 1049 |
+
|
| 1050 |
+
# Ищем запись по vk_id
|
| 1051 |
+
cursor.execute("SELECT orders FROM contacts WHERE vk_id = ?", (vkid,))
|
| 1052 |
+
result = cursor.fetchone()
|
| 1053 |
+
logging.debug(f"Database result: {result}")
|
| 1054 |
+
|
| 1055 |
+
# Если запись по vk_id не найдена, возвращаем значение "not" для ордера
|
| 1056 |
+
if not result:
|
| 1057 |
+
logging.error(f"VK ID {vkid} not found")
|
| 1058 |
+
return None
|
| 1059 |
+
|
| 1060 |
+
shop_st = result[0] if result[0] else '{}'
|
| 1061 |
+
logging.debug(f"Shop_st: {shop_st}")
|
| 1062 |
+
shop_st_data = json.loads(shop_st)
|
| 1063 |
+
logging.debug(f"Existing record found. Loaded JSON: {shop_st_data}")
|
| 1064 |
+
|
| 1065 |
+
return shop_st_data
|
| 1066 |
+
|
| 1067 |
# Чтение ордера по ключу и ВК ИД для приложения
|
| 1068 |
@app.route('/get_order', methods=['POST'])
|
| 1069 |
def get_order():
|
|
|
|
| 1075 |
order = request.form.get('order', '')
|
| 1076 |
apps_id = request.form.get('apps_id', '') # Сюда придёт ИД ВК приложения
|
| 1077 |
fullUrl = request.form.get('fullUrl', '') # Полный URL, который выдаёт ВКонтакте
|
|
|
|
| 1078 |
|
| 1079 |
+
logging.debug(f"Received data: vk_id={vkid}, order={order}, apps_id={apps_id}, fullUrl={fullUrl}")
|
| 1080 |
|
| 1081 |
# Проверка подписи для приложения
|
| 1082 |
if str(apps_id) not in api_key_apps_vk: # Приводим apps_id к строке
|
|
|
|
| 1095 |
logging.error("Invalid signature")
|
| 1096 |
return json.dumps({"error": "Invalid signature"}), 400
|
| 1097 |
|
| 1098 |
+
# Получаем данные из базы данных
|
| 1099 |
+
shop_st_data = get_order_from_db(vkid)
|
| 1100 |
+
if not shop_st_data:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1101 |
response = {order: 'not'}
|
| 1102 |
return jsonify(response), 200
|
| 1103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1104 |
# Ищем значение по ключу order
|
| 1105 |
value = shop_st_data.get(order, 'not')
|
| 1106 |
logging.debug(f"Value for order {order}: {value}")
|
|
|
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
|
|
|
| 1138 |
|
| 1139 |
|
| 1140 |
|