首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >(iphone)使用MKStoreKit的inAppPurchase verifyReceipt

(iphone)使用MKStoreKit的inAppPurchase verifyReceipt
EN

Stack Overflow用户
提问于 2011-05-23 15:26:59
回答 2查看 3.8K关注 0票数 0

我正在使用MKStoreKit测试应用程序购买。

我收到响应的状态为21002,我想知道为什么。

我需要设置证书或其他东西才能与苹果服务器对话吗?

下面是MKStoreKit使用的php代码。

代码语言:javascript
复制
<?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;
}

?>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-23 17:00:35

MKStore工具包在向服务器发送receiptdata时出现错误

你应该编码receiptData而不是asciiStringEncoding。

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

票数 0
EN

Stack Overflow用户

发布于 2011-05-23 15:35:17

请查看Verify Purchase

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6094112

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档