アプリ内購入の領収書検証のトラブルシューティング: 「無効なステータス」応答を処理する方法?

Linda Hamilton
リリース: 2024-10-17 20:13:03
オリジナル
223 人が閲覧しました

Troubleshooting In-App Purchase Receipt Validation: How to Handle

アプリ内購入の領収書の確認

アプリ内購入の検証は、ユーザーが正当な購入を行ったことを確認し、ユーザーにアクセスを許可するために重要です。プレミアムコンテンツまたは機能。ドキュメントが入手可能であるにもかかわらず、効果的なレシート検証を実装するのは難しい場合があります。

1 つのアプローチとして、レシート データを PHP サーバーに送信し、PHP サーバーがそれを検証のために Apple App Store に転送することが含まれます。応答が成功すると購入の正当性が確認され、サーバー上でのトランザクションの記録を続行できるようになります。

ただし、領収書の検証中に「無効なステータス」応答が発生した場合は、入力ミスがないか確認することが重要です。あなたのコード。次のサンプル コードは、解決策を提供します。

- (BOOL)verifyReceipt:(SKPaymentTransaction *)transaction {
    NSString *jsonObjectString = [self encode:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length];      
    NSString *completeString = [NSString stringWithFormat:@"http://url-for-your-php?receipt=%@", jsonObjectString];               
    NSURL *urlForValidation = [NSURL URLWithString:completeString];       
    NSMutableURLRequest *validationRequest = [[NSMutableURLRequest alloc] initWithURL:urlForValidation];              
    [validationRequest setHTTPMethod:@"GET"];         
    NSData *responseData = [NSURLConnection sendSynchronousRequest:validationRequest returningResponse:nil error:nil];  
    [validationRequest release];
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding: NSUTF8StringEncoding];
    NSInteger response = [responseString integerValue];
    [responseString release];
    return (response == 0);
}

- (NSString *)encode:(const uint8_t *)input length:(NSInteger)length {
    static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

    NSMutableData *data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
    uint8_t *output = (uint8_t *)data.mutableBytes;

    for (NSInteger i = 0; i < length; i += 3) {
        NSInteger value = 0;
        for (NSInteger j = i; j < (i + 3); j++) {
            value <<= 8;

            if (j < length) {
                value |= (0xFF & input[j]);
            }
        }

        NSInteger index = (i / 3) * 4;
        output[index + 0] =                    table[(value >> 18) & 0x3F];
        output[index + 1] =                    table[(value >> 12) & 0x3F];
        output[index + 2] = (i + 1) < length ? table[(value >> 6)  & 0x3F] : '=';
        output[index + 3] = (i + 2) < length ? table[(value >> 0)  & 0x3F] : '=';
    }

    return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
}
ログイン後にコピー

さらに、次の PHP コードをサーバーで使用して、レシートの検証を処理し、トランザクションを記録できます。

$receipt = json_encode(array("receipt-data" => $_GET["receipt"]));
// NOTE: use "buy" vs "sandbox" in production.
$url = "https://sandbox.itunes.apple.com/verifyReceipt";
$response_json = call-your-http-post-here($url, $receipt);
$response = json_decode($response_json);

// Save the data here!

echo $response->status;
ログイン後にコピー

必ず置き換えてください。好みの HTTP 投稿メカニズムを使用して「call-your-http-post-here」を実行します。このコードを実装し、その正確性を確保することで、レシートの購入を効果的に検証し、アプリ内トランザクションを自信を持って管理できます。

以上がアプリ内購入の領収書検証のトラブルシューティング: 「無効なステータス」応答を処理する方法?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ソース:php
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
著者別の最新記事
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!