【问题标题】:(iphone) inAppPurchase verifyReceipt using MKStoreKit(iphone) inAppPurchase verifyReceipt using MKStoreKit
【发布时间】:2011-08-30 22:46:19
【问题描述】:

我正在使用 MKStoreKit 进行应用购买测试。

我收到响应的状态 21002,不知道为什么。
我是否需要设置证书或其他东西才能与苹果服务器通信?

下面是MKStoreKit使用的php代码

<?php

$devmode = TRUE; // change this to FALSE after testing in sandbox                                                                                                                                                                                                             

$receiptdata = $_POST['receiptdata'];
$udid = $_POST['udid'];

if($devmode)
 {
     $appleURL = "https://sandbox.itunes.apple.com/verifyReceipt";
 }   
 else
 {
     $appleURL = "https://buy.itunes.apple.com/verifyReceipt";
 }

$receipt = json_encode(array("receipt-data" => $receiptdata));
$response_json = do_post_request($appleURL, $receipt);
$response = json_decode($response_json);

file_put_contents('php://stderr', print_r($response->{'status'}, true));
file_put_contents('php://stderr', print_r($udid, true));

if($response->{'status'} == 0)
 {
     file_put_contents('php://stderr', print_r("yes", true));
     error_log('udid: %s', $udid);
     error_log('quantity: %d', $response->{'receipt'}->quantity);
     echo ('YES');
 }   
 else
 {
     echo ('NO');
 }

function do_post_request($url, $data, $optional_headers = null)
{
    $params = array('http' => array(
            'method' => 'POST',
            'content' => $data
                                    ));
    if ($optional_headers !== null) {
        $params['http']['header'] = $optional_headers;
    }
    $ctx = stream_context_create($params);
    $fp = @fopen($url, 'rb', false, $ctx);
    if (!$fp) {
        throw new Exception("Problem with $url, $php_errormsg");
    }
    $response = @stream_get_contents($fp);
    if ($response === false) {
        throw new Exception("Problem reading data from $url, $php_errormsg");
    }
    return $response;
}

?>

【问题讨论】:

    标签: iphone in-app-purchase receipt


    【解决方案1】:

    请查看Verify Purchase

    【讨论】:

    • 重要提示:此处的非零状态代码仅在恢复有关自动更新订阅的信息时适用。在测试其他类型产品的响应时,请勿使用这些状态代码。我没有测试自动续订订阅。在针对消耗品进行测试时,该文档没有提及错误代码..
    • 此文档的链接已更改。这是更新的:developer.apple.com/library/mac/releasenotes/General/…
    【解决方案2】:

    MKStore Kit 在向服务器发送receiptdata 时存在错误

    你应该 base64 编码receiptData 而不是asciiStringEncoding。

    使用以下链接的代码到 base64,我得到状态 0。 Verify receipt for in App purchase

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-12
      相关资源
      最近更新 更多