(iphone)inAppPurchase verifyReceipt使用MKStoreKit

问题描述:

我正在测试与MKStoreKit的应用程序购买。(iphone)inAppPurchase verifyReceipt使用MKStoreKit

我收到回复的状态21002,并想知道为什么。
我是否需要设置证书或与Apple服务器交谈的内容?

下面是MKStoreKit使用

<?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; 
} 

?> 

MKStore套件与发送receiptdata服务器

的错误,您应该Base64编码receiptData不asciiStringEncoding PHP代码。

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

请检查Verify Purchase

+0

重要:非零状态这里只代码回收有关自动再生订阅信息时适用。测试其他类型产品的响应时不要使用这些状态码。 我没有测试自动更新订阅。该文档在对易耗品进行测试时没有提供有关错误代码的信息。 – eugene 2011-05-23 07:45:33

+0

此文档的链接已更改。这是更新的:https://developer.apple.com/library/mac/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html – 2013-12-09 00:10:51