|
@@ -47,6 +47,8 @@ class InAppPurchaseView(View):
|
|
|
def validation(self, request_dict, request, operation):
|
|
|
if operation == 'AppStoreServerNotifications': # App Store服务器通知
|
|
|
return self.app_store_server_notifications(request)
|
|
|
+ elif operation == 'VseesNotifications':
|
|
|
+ return self.vsees_notifications(request)
|
|
|
token_code, user_id, response = CommonService.verify_token_get_user_id(request_dict, request)
|
|
|
if token_code != 0:
|
|
|
return response.json(token_code)
|
|
@@ -334,7 +336,6 @@ class InAppPurchaseView(View):
|
|
|
uid = orders_qs[0].UID
|
|
|
user_id = orders_qs[0].userID
|
|
|
# 3. 未使用则删除未使用套餐表,已使用过则删除设备正在使用套餐,并关闭设备云存
|
|
|
- uid_bucket_qs = UID_Bucket.objects.filter(uid=uid, orderId=orderID, use_status=1, endTime__gt=int(time.time()))
|
|
|
uid_bucket_qs = UID_Bucket.objects.filter(uid=uid, orderId=orderID, use_status=1,
|
|
|
endTime__gt=int(time.time()))
|
|
|
unused_uid_meal_qs = Unused_Uid_Meal.objects.filter(order_id=orderID)
|
|
@@ -364,14 +365,60 @@ class InAppPurchaseView(View):
|
|
|
status_code = eur_response.status_code
|
|
|
|
|
|
return HttpResponse(status=status_code)
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def vsees_notifications(cls, request):
|
|
|
+ logger = logging.getLogger('apple_pay')
|
|
|
+ logger.info('Vsees: App Store服务器通知请求类型:{}'.format(request.method))
|
|
|
+ logger.info('Vsees: App Store服务器通知参数:{}'.format(request.POST))
|
|
|
+ logger.info('Vsees: App Store服务器通知请求body:{}'.format(request.body))
|
|
|
+ payload = json.loads(request.body.decode('utf-8'))
|
|
|
+ logger.info('Vsees: App Store服务器通知payload:{}'.format(payload))
|
|
|
+ # 获取 signedPayload
|
|
|
+ signed_payload = payload.get('signedPayload')
|
|
|
+ if not signed_payload:
|
|
|
+ return HttpResponse(status=400)
|
|
|
+
|
|
|
+ in_app_purchase = InAppPurchase(bundle_id="com.cloudlife.commissionf")
|
|
|
+
|
|
|
+ # SignedDataVerifier 用于解析查询到的交易信息
|
|
|
+ verifier = in_app_purchase.verifier
|
|
|
+ decoded_payload = verifier.verify_and_decode_notification(signed_payload)
|
|
|
+
|
|
|
+ logger.info('Vsees: App Store服务器通知decoded_payload: {}'.format(decoded_payload))
|
|
|
+
|
|
|
+ status_code = 200
|
|
|
+
|
|
|
+ if str(decoded_payload.rawNotificationType) == "REFUND":
|
|
|
+ # 一种通知类型,表示 App Store 成功退还了消耗性应用内购买、非消耗性应用内购买、自动续订或不可续订的交易。
|
|
|
+ # revocationDate 包含退款交易的时间戳。originalTransactionId 和 productId 用于标识原始交易和产品。revocationReason 包含原因。
|
|
|
+ # 要请求客户所有退款交易的列表,请参阅 App Store 服务器 API 中的获取退款历史记录。
|
|
|
+ # 1. 找套餐 使用 transaction_id 找orders
|
|
|
+ decoded_transaction_information = verifier.verify_and_decode_signed_transaction(
|
|
|
+ decoded_payload.data.signedTransactionInfo)
|
|
|
+ transaction_id = decoded_transaction_information.transactionId
|
|
|
+ logger.info('Vsees: App Store服务器通知退款, transaction_id:{}'.format(transaction_id))
|
|
|
+ orders_qs = Order_Model.objects.filter(transaction_id=transaction_id)
|
|
|
+
|
|
|
+ # 2. 查找云存套餐使用表 和 云存套餐
|
|
|
+ if orders_qs.exists():
|
|
|
+ orders_qs.update(status=11)
|
|
|
+ orderID = orders_qs[0].orderID
|
|
|
+ uid = orders_qs[0].UID
|
|
|
+ user_id = orders_qs[0].userID
|
|
|
+ # 3. 未使用则删除未使用套餐表,已使用过则删除设备正在使用套餐,并关闭设备云存
|
|
|
+ uid_bucket_qs = UID_Bucket.objects.filter(uid=uid, orderId=orderID, use_status=1,
|
|
|
+ endTime__gt=int(time.time()))
|
|
|
unused_uid_meal_qs = Unused_Uid_Meal.objects.filter(order_id=orderID)
|
|
|
- ai_service_qs = AiService.objects.filter(uid=uid, orderId=orderID, use_status=1, endTime__gt=int(time.time()))
|
|
|
+ ai_service_qs = AiService.objects.filter(uid=uid, orderId=orderID, use_status=1,
|
|
|
+ endTime__gt=int(time.time()))
|
|
|
if unused_uid_meal_qs.exists():
|
|
|
unused_uid_meal_qs.delete()
|
|
|
if uid_bucket_qs.exists():
|
|
|
uid_bucket_qs.update(status=0, use_status=2, endTime=int(time.time()), updateTime=int(time.time()))
|
|
|
if ai_service_qs.exists():
|
|
|
- ai_service_qs.update(detect_status=0, use_status=2, endTime=int(time.time()), updTime=int(time.time()))
|
|
|
+ ai_service_qs.update(detect_status=0, use_status=2, endTime=int(time.time()),
|
|
|
+ updTime=int(time.time()))
|
|
|
# 关闭ai
|
|
|
msg = {'commandType': 'AIDisable'}
|
|
|
thing_name = CommonService.query_serial_with_uid(uid) # 存在序列号则为使用序列号作为物品名
|