Spaces:
Runtime error
Runtime error
远兮
commited on
Commit
·
b087940
1
Parent(s):
56c9cc1
添加查询订单接口
Browse files- chatgpt-next-web/service.py +42 -0
chatgpt-next-web/service.py
CHANGED
@@ -266,6 +266,41 @@ def order_center():
|
|
266 |
})
|
267 |
|
268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
@app.route('/pay/notify', methods=['POST'])
|
270 |
def handle_payment_notification():
|
271 |
# 获取POST请求中的JSON数据,这是微信支付发送的通知数据
|
@@ -302,6 +337,13 @@ def get_user_orders(user_id):
|
|
302 |
return user_orders
|
303 |
|
304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
def is_order_expired(order_data):
|
306 |
print("is_order_expired", order_data)
|
307 |
# 获取订单创建时间
|
|
|
266 |
})
|
267 |
|
268 |
|
269 |
+
@app.route('/query_order', methods=['POST'])
|
270 |
+
def query_order():
|
271 |
+
data = request.json
|
272 |
+
if 'order_id' not in data:
|
273 |
+
return jsonify({'code': 400, 'message': '订单无效'})
|
274 |
+
|
275 |
+
token = parse_token(request)
|
276 |
+
|
277 |
+
# 验证令牌
|
278 |
+
if not validate_token(token):
|
279 |
+
return jsonify({'code': 401, 'message': 'Invalid token'})
|
280 |
+
|
281 |
+
# 获取用户ID
|
282 |
+
user_id = get_user_id_from_token(token)
|
283 |
+
if not user_id:
|
284 |
+
return jsonify({'code': 400, 'message': 'User not found'})
|
285 |
+
|
286 |
+
order_id = data['order_id']
|
287 |
+
|
288 |
+
# 从Redis中获取指定订单数据
|
289 |
+
order_key = f'order:{user_id}:{order_id}'
|
290 |
+
order_data = redis.hgetall(order_key)
|
291 |
+
|
292 |
+
if not order_data:
|
293 |
+
return jsonify({'code': 404, 'message': 'Order not found'})
|
294 |
+
|
295 |
+
# 将bytes类型的键和值转换为str类型
|
296 |
+
order_data_str = {
|
297 |
+
k.decode('utf-8'): int(v.decode('utf-8')) if k.decode('utf-8') == 'amount' else v.decode('utf-8')
|
298 |
+
for k, v in order_data.items()
|
299 |
+
}
|
300 |
+
|
301 |
+
return jsonify({'code': 0, 'message': 'Success', 'data': order_data_str})
|
302 |
+
|
303 |
+
|
304 |
@app.route('/pay/notify', methods=['POST'])
|
305 |
def handle_payment_notification():
|
306 |
# 获取POST请求中的JSON数据,这是微信支付发送的通知数据
|
|
|
337 |
return user_orders
|
338 |
|
339 |
|
340 |
+
def get_order_by_id(user_id, order_id):
|
341 |
+
# 从Redis中获取指定订单数据
|
342 |
+
order_key = f'order:{user_id}:{order_id}'
|
343 |
+
order_data = redis.hgetall(order_key)
|
344 |
+
return order_data
|
345 |
+
|
346 |
+
|
347 |
def is_order_expired(order_data):
|
348 |
print("is_order_expired", order_data)
|
349 |
# 获取订单创建时间
|