인앱 구매 영수증의 진위 여부를 확인하는 방법

Barbara Streisand
풀어 주다: 2024-10-17 20:09:30
원래의
625명이 탐색했습니다.

How to Verify In-App Purchase Receipts for Authenticity

Verifying In-App Purchase Receipts

In-app purchases allow users to acquire digital goods and services within mobile applications. Validating receipts is crucial to ensure the authenticity of these purchases. This article aims to address common challenges in receipt validation and provide a practical solution.

Understanding Receipt Validation

Receipt validation involves sending the purchase receipt to Apple's servers to verify its authenticity. The receipt holds crucial information, including the transaction details, product identifier, and purchase date. Apple responds with a validation status, indicating whether the receipt is valid or not.

Implementing Receipt Validation

The provided code demonstrates a method for receipt validation on the client side:

- (BOOL)verifyReceipt:(SKPaymentTransaction *)transaction {
    // Encode receipt data to base64 string
    NSString *jsonObjectString = [self encode:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length];
    // Construct URL for validation
    NSString *completeString = [NSString stringWithFormat:@"http://url-for-your-php?receipt=%@", jsonObjectString];
    NSURL *urlForValidation = [NSURL URLWithString:completeString];
    // Send HTTP GET request to server for validation
    NSMutableURLRequest *validationRequest = [[NSMutableURLRequest alloc] initWithURL:urlForValidation];
    [validationRequest setHTTPMethod:@"GET"];
    NSData *responseData = [NSURLConnection sendSynchronousRequest:validationRequest returningResponse:nil error:nil];
    [validationRequest release];
    // Extract response status
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding: NSUTF8StringEncoding];
    NSInteger response = [responseString integerValue];
    [responseString release];
    // Return validation status
    return (response == 0);
}
로그인 후 복사

Server-Side Implementation

On the server side, a simple PHP script can handle the request and forward it to Apple.

<code class="php">$receipt = json_encode(array("receipt-data" => $_GET["receipt"]));
$url = "https://sandbox.itunes.apple.com/verifyReceipt";
$response_json = call-your-http-post-here($url, $receipt);
$response = json_decode($response_json);

echo $response->status;</code>
로그인 후 복사

Conclusion

By implementing these methods, you can validate in-app purchase receipts on your iOS application and securely record transaction data on your server. This ensures that only legitimate purchases are processed, preventing fraudulent activities.

위 내용은 인앱 구매 영수증의 진위 여부를 확인하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:php
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
저자별 최신 기사
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!