You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS订阅收据在App Store分发环境中无法正常工作求助

问题:.NET MAUI应用TestFlight版本无法触发AWS Lambda函数

首次发帖,若有不当之处恳请谅解,如有需要调整的地方请告知。

我使用.NET MAUI(JetBrains Rider IDE)开发了一款iOS和Android跨平台应用,在App Store创建了两个订阅产品并集成到应用中。该应用在连接本地iPhone的Debug构建下测试正常,但在TestFlight和正式分发版本中出现问题:从AWS CloudWatch日志中可见,AWS Lambda函数未被调用。

我确认TestFlight环境可正常访问AWS服务,因为订阅校验前的AWS Cognito认证调用成功。目前无法确定Lambda函数未触发是由于目标端拦截还是调用方式有误。

.NET MAUI中调用Lambda的代码

var payload = JsonConvert.SerializeObject(new { receipt = receiptData });
Debug.WriteLine($"Payload length: {payload.Length}");
Debug.WriteLine($"Payload (first 100 chars): {payload.Substring(0, Math.Min(100, payload.Length))}");
//Debug.WriteLine($"Payload: {payload}");
var request = new InvokeRequest
{
    FunctionName = "[MY_LAMBDA_FUNCTION_NAME]",
    Payload = payload
};

Debug.WriteLine("Invoking Lambda function...");
var response = await client.InvokeAsync(request);
Debug.WriteLine($"Lambda function response received. StatusCode: {response.StatusCode}");

AWS Lambda函数代码(Python 3.12)

import json
import boto3
import requests
from datetime import datetime
import logging

# Environment variables for shared secret and other configuration
SHARED_SECRET = 'MY_SHARED_SECRET'  

# Configure logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)

def try_validation(url, payload):
    try:
        response = requests.post(url, json=payload, timeout=30)
        response.raise_for_status()
        logger.info(f"Request to {url} succeeded: {response.json()}")
        return response.json()
    except requests.exceptions.RequestException as e:
        logger.error(f"Request to {url} failed: {str(e)}")
        return {'status': 'RequestFailed', 'error': str(e)}

def validate_receipt_with_apple(receipt_data):
    payload = {
        'receipt-data': receipt_data,
        'password': SHARED_SECRET,
        'exclude-old-transactions': True
    }
    
    production_url = 'https://buy.itunes.apple.com/verifyReceipt'
    sandbox_url = 'https://sandbox.itunes.apple.com/verifyReceipt'
    
    # Try production first
    production_response = try_validation(production_url, payload)
    
    # If production returns 21007, try sandbox
    if production_response.get('status') == 21007:
        return try_validation(sandbox_url, payload)
    
    # For any other response, return the production response
    return production_response

def determine_subscription_status(receipt_info):
    current_time = int(datetime.now().timestamp() * 1000)  # Current time in milliseconds
    for purchase in receipt_info:
        expires_date_ms = int(purchase['expires_date_ms'])
        if expires_date_ms > current_time:
            return 'Active'
    return 'Expired'

def lambda_handler(event, context):
    logger.info(f"Received event: {json.dumps(event)}")
    try:
        receipt = event.get('receipt')
        if not receipt:
            response_body = {'isValid': False, 'message': 'Receipt data is required'}
            logger.info(f"Response: {json.dumps(response_body)}")
            return {
                'statusCode': 400,
                'body': json.dumps(response_body)
            }
        
        validation_response = validate_receipt_with_apple(receipt)
        
        if validation_response.get('status') == 0:
            latest_receipt_info = validation_response.get('latest_receipt_info', [])
            subscription_status = determine_subscription_status(latest_receipt_info)
            latest_expiration = latest_receipt_info[-1].get('expires_date') if latest_receipt_info else None
            
            response_body = {
                'isValid': True,
                'subscriptionStatus': subscription_status,
                'environment': 'Production' if validation_response.get('environment') != 'Sandbox' else 'Sandbox',
                'latestExpirationDate': latest_expiration
            }
        else:
            response_body = {
                'isValid': False,
                'message': 'Receipt validation failed',
                'status': validation_response.get('status')
            }
        
        logger.info(f"Response: {json.dumps(response_body)}")
        return {
            'statusCode': 200,
            'body': json.dumps(response_body)
        }
        
    except Exception as e:
        logger.error(f"Error in lambda_handler: {str(e)}")
        response_body = {'isValid': False, 'message': f'Server error during receipt validation: {str(e)}'}
        logger.info(f"Response: {json.dumps(response_body)}")
        return {
            'statusCode': 500,
            'body': json.dumps(response_body)
        }

内容的提问来源于stack exchange,提问作者James Korris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 17:19:55