0

我正在使用 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;
}

?>
4

2 回答 2

1

请检查验证购买

于 2011-05-23T07:35:16.623 回答
0

MKStore Kit 有一个向服务器发送收据数据的错误

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

使用以下链接的代码到 base64,我得到状态 0。 验证应用内购买的收据

于 2011-05-23T09:00:35.277 回答