Pārlūkot izejas kodu

Merge branch 'test' of http://192.168.136.99:3000/servers/ASJServer into peng

peng 9 mēneši atpakaļ
vecāks
revīzija
89b21d78fd
1 mainītis faili ar 43 papildinājumiem un 5 dzēšanām
  1. 43 5
      Controller/InAppPurchaseController.py

+ 43 - 5
Controller/InAppPurchaseController.py

@@ -26,7 +26,7 @@ from django.http import HttpResponse
 from Ansjer.config import LOGGER, CONFIG_INFO, CONFIG_TEST, PAY_TYPE_IN_APP_PURCHASE, BASE_DIR, CONFIG_US
 from Controller.CheckUserData import DataValid
 from Model.models import Order_Model, Store_Meal, Device_Info, UID_Bucket, Unused_Uid_Meal, AiService, Device_User, \
-    SysMsgModel, DeviceApplePackage, InAppPurchasePackage, InAppRefund
+    SysMsgModel, DeviceApplePackage, InAppPurchasePackage, InAppRefund, OrderPayLog
 from Object.AWS.S3Email import S3Email
 from Object.AliSmsObject import AliSmsObject
 from Object.AppleInAppPurchaseSubscriptionObject import InAppPurchase
@@ -58,7 +58,7 @@ class InAppPurchaseView(View):
         elif operation == 'serverNotifications':  # App Store服务器通知
             return self.server_notifications(request)
         elif operation == 'putRefundOrder':  # App Store服务器通知
-            return self.put_refund_order(request)
+            return self.put_refund_order()
         token_code, user_id, response = CommonService.verify_token_get_user_id(request_dict, request)
         if token_code != 0:
             return response.json(token_code)
@@ -129,10 +129,33 @@ class InAppPurchaseView(View):
                 logger.info(f"苹果内购认证交易订单orderID:{order_id}, 没有transaction_id")
                 pay_result_url = CommonService.get_payment_status_url(lang, 'fail')
                 return response.json(0, {'url': pay_result_url})
-            logger.info(f"苹果内购认证交易订单orderID:{order_id}, transaction_id:{transaction_id}")
+            logger.info(f"苹果内购认证交易订单orderID:{order_id}, transaction_id:{transaction_id}, 时间戳: {int(time.time())}")
+
+            OrderPayLog.objects.create(order_id=order_id, order_no=transaction_id,
+                                       business_name=f"内购验单",
+                                       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 = client.get_transaction_info(transaction_id)
+            attempts = 0
+            while attempts < 6:
+                try:
+                    transaction_info = client.get_transaction_info(transaction_id)
+                except ConnectionError as err:
+                    attempts += 1
+                    if attempts == 5:
+                        OrderPayLog.objects.create(order_id=order_id, order_no=transaction_id,
+                                                   business_name=f"{order_id}获取transactionInfo",
+                                                   created_time=int(time.time()), updated_time=int(time.time()),
+                                                   access_result="ERROR")
+
             signed_transaction_info = transaction_info.signedTransactionInfo
             # 解析交易信息
             payload = signed_data_verifier.verify_and_decode_signed_transaction(signed_transaction_info)
@@ -227,6 +250,12 @@ class InAppPurchaseView(View):
 
             redis_obj.del_data(redis_key)
             pay_result_url = CommonService.get_payment_status_url(lang, 'success')
+
+            OrderPayLog.objects.create(order_id=order_id, order_no=transaction_id,
+                                       business_name=f"内购充值成功",
+                                       created_time=int(time.time()), updated_time=int(time.time()),
+                                       access_result="SUCCESS")
+
             return response.json(0, {'url': pay_result_url})
         except Exception as e:
             redis_obj.del_data(redis_key)
@@ -709,6 +738,15 @@ class InAppPurchaseView(View):
                 logger.info(
                     'App Store服务器通知,撤销了批准的退款,不恢复套餐,手动处理 transaction_id:{}'.format(transaction_id))
 
+            elif str(decoded_payload.rawNotificationType) == "REFUND_DECLINED":
+                decoded_transaction_information = signed_data_verifier.verify_and_decode_signed_transaction(
+                    decoded_payload.data.signedTransactionInfo)
+                transaction_id = decoded_transaction_information.transactionId
+                orders_qs = Order_Model.objects.filter(transaction_id=transaction_id)
+                if not orders_qs.exists():
+                    return HttpResponse(status=400)
+                InAppRefund.objects.filter(transaction_id=transaction_id).update(refund_progress=3)
+
             else:
                 logger.info(f"App Store服务器通知decoded_payload.rawNotificationType 未处理")
                 return HttpResponse(status=200)
@@ -821,7 +859,7 @@ class InAppPurchaseView(View):
         return HttpResponse(status=status_code)
 
     @staticmethod
-    def put_refund_order(response):
+    def put_refund_order():
         put_time = int(time.time())
         in_app_refund_qs = InAppRefund.objects.filter(refund_progress=0, put_time__lt=put_time)
         for in_app_refund in in_app_refund_qs: