python - Verify an App Store receipt always staus code 21003 - Stack Overflow

admin2025-05-01  7

I'm trying to verify a receipt with the App Store server in the sandbox environment. I've checked all values are correct but keep receiving:

{
    "environment": "Sandbox", 
    "status": 21003
}

My code:

def verify_receipt(receipt_data: str, sandbox: bool = True) -> dict:
    """
    Verify an App Store receipt with Apple's verification service

    Args:
        receipt_data: The base64 encoded receipt data
        sandbox: Whether to use sandbox environment (default True)

    Returns:
        dict: The verification response from Apple
    """
    # URLs for verification
    SANDBOX_URL = ";
    PRODUCTION_URL = ";

    # Shared secret from App Store Connect
    SHARED_SECRET = "xxx......"

    # Prepare the verification URL
    verify_url = SANDBOX_URL if sandbox else PRODUCTION_URL

    # Prepare the request payload
    payload = {
        'receipt-data': receipt_data,
        'password': SHARED_SECRET,
        'exclude-old-transactions': True
    }
    response = requests.post(verify_url, json=payload)
    result = response.json()

转载请注明原文地址:http://www.anycun.com/QandA/1746106347a91758.html