|
@@ -4,6 +4,7 @@
|
|
|
import logging
|
|
|
import time
|
|
|
import json
|
|
|
+import threading
|
|
|
|
|
|
import requests
|
|
|
from appstoreserverlibrary.models.Environment import Environment
|
|
@@ -111,6 +112,17 @@ class InAppPurchaseView(View):
|
|
|
else:
|
|
|
return response.json(444, "app_type不存在")
|
|
|
|
|
|
+ # 验证订单是否存在
|
|
|
+ order_qs = Order_Model.objects.filter(orderID=order_id, UID=uid, app_type=app_type).values("rank_id")
|
|
|
+ if not order_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ if order_qs["transaction_id"]:
|
|
|
+ return response.json(0)
|
|
|
+ if UID_Bucket.objects.filter(orderId=order_id).exists():
|
|
|
+ return response.json(0)
|
|
|
+ if Unused_Uid_Meal.objects.filter(order_id=order_id).exists():
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
# 实例化订阅类
|
|
|
in_app_purchase = InAppPurchase(bundle_id=bundle_id)
|
|
|
|
|
@@ -136,14 +148,8 @@ class InAppPurchaseView(View):
|
|
|
created_time=int(time.time()), updated_time=int(time.time()),
|
|
|
access_result="SUCCESS")
|
|
|
|
|
|
- if Order_Model.objects.filter(orderID=order_id, transaction_id=transaction_id).exists():
|
|
|
- return response.json(174, "订单已支付充值")
|
|
|
- if UID_Bucket.objects.filter(orderId=order_id).exists():
|
|
|
- return response.json(174, "订单已充值")
|
|
|
- if Unused_Uid_Meal.objects.filter(order_id=order_id).exists():
|
|
|
- return response.json(174, "订单已充值")
|
|
|
-
|
|
|
# 查询交易信息
|
|
|
+ transaction_info = ""
|
|
|
attempts = 0
|
|
|
while attempts < 6:
|
|
|
try:
|
|
@@ -153,9 +159,12 @@ class InAppPurchaseView(View):
|
|
|
attempts += 1
|
|
|
if attempts == 5:
|
|
|
OrderPayLog.objects.create(order_id=order_id, order_no=transaction_id,
|
|
|
- business_name=f"{order_id}获取transactionInfo",
|
|
|
+ business_name=f"{order_id}获取transactionInfo超时",
|
|
|
created_time=int(time.time()), updated_time=int(time.time()),
|
|
|
access_result="ERROR")
|
|
|
+ return response.json(5)
|
|
|
+ logger.info(
|
|
|
+ f"订单orderId:{order_id}, transaction_id:{transaction_id}, 第{attempts}次获取支付信息超时")
|
|
|
|
|
|
signed_transaction_info = transaction_info.signedTransactionInfo
|
|
|
# 解析交易信息
|
|
@@ -173,15 +182,11 @@ class InAppPurchaseView(View):
|
|
|
logger.info(f"苹果内购认证交易订单orderID:{order_id}, InAppPurchasePackage表未查询到product_id")
|
|
|
return response.json(173, "内购商品id不存在")
|
|
|
|
|
|
- # 验证订单是否存在
|
|
|
- order_qs = Order_Model.objects.filter(orderID=order_id, UID=uid, app_type=app_type).values("rank_id")
|
|
|
- if not order_qs.exists():
|
|
|
- return response.json(173, "订单不存在")
|
|
|
-
|
|
|
# 验证套餐是否存在
|
|
|
store_qs = Store_Meal.objects.filter(id=order_qs[0]['rank_id']).values(
|
|
|
'id', 'currency', 'price', 'lang__content', 'day', 'commodity_type', 'lang__title', 'expire',
|
|
|
'commodity_code', 'discount_price', 'bucket_id', 'bucket__mold', 'cycle_config_id', 'is_ai')
|
|
|
+
|
|
|
if not store_qs.exists():
|
|
|
return response.json(173, "云存套餐不存在")
|
|
|
|
|
@@ -247,7 +252,9 @@ class InAppPurchaseView(View):
|
|
|
sys_msg_text_list = cls.cloud_storage_message(uid)
|
|
|
|
|
|
# 发送云存套餐购买消息
|
|
|
- cls.do_vod_msg_notice(uid, user_id, lang, sys_msg_text_list)
|
|
|
+ asy = threading.Thread(target=cls.do_vod_msg_notice,
|
|
|
+ args=(uid, user_id, lang, sys_msg_text_list))
|
|
|
+ asy.start()
|
|
|
|
|
|
redis_obj.del_data(redis_key)
|
|
|
pay_result_url = CommonService.get_payment_status_url(lang, 'success')
|