Spaces:
Runtime error
Runtime error
远兮
commited on
Commit
·
4eb1abb
1
Parent(s):
1532712
create_order中生成微信支付二维码
Browse files- chatgpt-next-web/service.py +17 -5
chatgpt-next-web/service.py
CHANGED
@@ -2,7 +2,6 @@ import json
|
|
2 |
import random
|
3 |
import string
|
4 |
import uuid
|
5 |
-
import time
|
6 |
import jwt
|
7 |
import datetime
|
8 |
import requests
|
@@ -204,14 +203,27 @@ def create_order():
|
|
204 |
order_key = f'order:{user_id}:{order_id}'
|
205 |
redis.hmset(order_key, order_data)
|
206 |
redis.expire(order_key, datetime.timedelta(hours=2))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
return jsonify({
|
209 |
'code': 0,
|
210 |
'message': 'Order created',
|
211 |
-
'data':
|
212 |
-
'order_id': order_id,
|
213 |
-
'amount': package['price']
|
214 |
-
}
|
215 |
})
|
216 |
|
217 |
|
|
|
2 |
import random
|
3 |
import string
|
4 |
import uuid
|
|
|
5 |
import jwt
|
6 |
import datetime
|
7 |
import requests
|
|
|
203 |
order_key = f'order:{user_id}:{order_id}'
|
204 |
redis.hmset(order_key, order_data)
|
205 |
redis.expire(order_key, datetime.timedelta(hours=2))
|
206 |
+
|
207 |
+
# 发起POST请求到http://localhost:8080/payPre获取codeUrl
|
208 |
+
payload = {
|
209 |
+
'order_id': order_id,
|
210 |
+
'amount': package['price'],
|
211 |
+
'user_id': user_id
|
212 |
+
}
|
213 |
+
response = requests.post('http://localhost:8080/payPre', json=payload)
|
214 |
+
|
215 |
+
if response.status_code == 200:
|
216 |
+
data = response.json()
|
217 |
+
code_url = data.get('data', {}).get('codeUrl')
|
218 |
+
if code_url:
|
219 |
+
order_data['codeUrl'] = code_url
|
220 |
+
else:
|
221 |
+
return jsonify({'code': 401, 'message': '支付二维码生成失败,请重试'})
|
222 |
|
223 |
return jsonify({
|
224 |
'code': 0,
|
225 |
'message': 'Order created',
|
226 |
+
'data': order_data
|
|
|
|
|
|
|
227 |
})
|
228 |
|
229 |
|