|
@@ -21,7 +21,7 @@ from django.http import HttpResponse
|
|
|
from Ansjer.config import LOGGER, CONFIG_INFO, CONFIG_TEST, PAY_TYPE_IN_APP_PURCHASE, BASE_DIR
|
|
|
from Controller.CheckUserData import DataValid
|
|
|
from Model.models import Order_Model, Store_Meal, Device_Info, UID_Bucket, Unused_Uid_Meal, AiService, Device_User, \
|
|
|
- SysMsgModel
|
|
|
+ SysMsgModel, DeviceApplePackage
|
|
|
from Object.AWS.S3Email import S3Email
|
|
|
from Object.AliSmsObject import AliSmsObject
|
|
|
from Object.RedisObject import RedisObject
|
|
@@ -61,15 +61,17 @@ class InAppPurchaseView(View):
|
|
|
@return: response
|
|
|
"""
|
|
|
receipt = request_dict.get('receipt', None)
|
|
|
+ transaction_identifier = request_dict.get('transactionIdentifier', None)
|
|
|
+ original_transaction_identifier = request_dict.get('originalTransactionIdentifier', None)
|
|
|
order_id = request_dict.get('orderID', None)
|
|
|
uid = request_dict.get('uid', None)
|
|
|
lang = request_dict.get('lang', 'en')
|
|
|
channel = request_dict.get('channel', None)
|
|
|
-
|
|
|
logger = logging.getLogger('apple_pay')
|
|
|
- logger.info(f"认证交易receipt:{receipt}, 订单orderId:{order_id}")
|
|
|
+ logger.info(
|
|
|
+ f"transactionIdentifier:{transaction_identifier}, original_transaction_identifier:{original_transaction_identifier} ,订单orderId:{order_id}")
|
|
|
|
|
|
- if not all([receipt, uid, channel, order_id]):
|
|
|
+ if not all([transaction_identifier, uid, channel, order_id]):
|
|
|
return response.json(444)
|
|
|
|
|
|
# redis加锁,防止订单重复
|
|
@@ -93,18 +95,30 @@ class InAppPurchaseView(View):
|
|
|
environment = ENV
|
|
|
|
|
|
client = AppStoreServerAPIClient(private_key, key_id, issuer_id, bundle_id, environment)
|
|
|
- receipt_util = ReceiptUtility()
|
|
|
+ transaction_id = transaction_identifier
|
|
|
|
|
|
- transaction_id = receipt_util.extract_transaction_id_from_app_receipt(receipt)
|
|
|
if transaction_id is None:
|
|
|
pay_result_url = CommonService.get_payment_status_url(lang, 'fail')
|
|
|
return response.json(0, {'url': pay_result_url})
|
|
|
|
|
|
transaction_info = client.get_transaction_info(transaction_id)
|
|
|
+
|
|
|
signed_transaction_info = transaction_info.signedTransactionInfo
|
|
|
- if Order_Model.objects.filter(payType=5, transaction_id=transaction_id).exists():
|
|
|
+ if Order_Model.objects.filter(payType=5, transaction_id=original_transaction_identifier).exists():
|
|
|
logger.info(f"该transaction_id已订阅过:{transaction_id}")
|
|
|
- # return response.json(10048)
|
|
|
+ return response.json(10048)
|
|
|
+
|
|
|
+ # 处理一台手机多账号登录订阅情况
|
|
|
+ device_apple_package_qs = DeviceApplePackage.objects.filter(
|
|
|
+ original_transaction_id=original_transaction_identifier)
|
|
|
+ if device_apple_package_qs.exists():
|
|
|
+ if device_apple_package_qs[0]["userID"] != user_id:
|
|
|
+ return response.json(10050)
|
|
|
+ elif device_apple_package_qs[0]["uid"] == uid:
|
|
|
+ device_apple_package_qs.update(subscription_status=1)
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(10048)
|
|
|
|
|
|
root_certificates = []
|
|
|
for cert_name in [
|
|
@@ -139,12 +153,12 @@ class InAppPurchaseView(View):
|
|
|
now_time = int(time.time())
|
|
|
order_qs = Order_Model.objects.filter(orderID=order_id, UID=uid).values("rank_id")
|
|
|
if not order_qs.exists():
|
|
|
- return response.json(173)
|
|
|
+ return response.json(173, "订单不存在")
|
|
|
store_qs = Store_Meal.objects.filter(id=order_qs[0]['rank_id'], product_id=product_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)
|
|
|
+ return response.json(173, "套餐不存在")
|
|
|
|
|
|
bucket_id = store_qs[0]['bucket_id']
|
|
|
is_ai = store_qs[0]['is_ai']
|
|
@@ -187,6 +201,8 @@ class InAppPurchaseView(View):
|
|
|
uid=uid, channel=channel, detect_status=1, use_status=1, orders_id=order_id,
|
|
|
addTime=now_time, updTime=now_time, endTime=end_time)
|
|
|
|
|
|
+ DeviceApplePackage.objects.filter(userID=user_id, uid=uid).update(subscription_status=1,
|
|
|
+ original_transaction_id=original_transaction_id)
|
|
|
order_qs.update(status=1, uid_bucket_id=uid_bucket_id,
|
|
|
transaction_id=transaction_id, create_vod=1,
|
|
|
original_transaction_id=original_transaction_id)
|
|
@@ -455,6 +471,10 @@ class InAppPurchaseView(View):
|
|
|
# 没有子类型的通知表示订阅因其他原因过期。
|
|
|
pass
|
|
|
|
|
|
+ elif str(decoded_payload.rawNotificationType) == "CONSUMPTION_REQUEST":
|
|
|
+ # 一种通知类型,指示客户发起了消费型 App 内购买项目或自动续期订阅的退款请求,并且 App Store 要求您提供消费数据。有关详细信息,请参阅发送消耗信息。
|
|
|
+ pass
|
|
|
+
|
|
|
else:
|
|
|
logger.info(f"App Store服务器通知decoded_payload.rawNotificationType 未处理")
|
|
|
return HttpResponse(status=500)
|