将php curl转换为iTunes InApp verifyReceipt的GAE urlfetch

时间:2014-04-01 01:29:54

标签: php google-app-engine itunesconnect libcurl urlfetch

有人可以帮助将这个PHP Curl转换为UrlFetch吗?这用于Apple iTunes verifyReceipt

if (getiTunesProductionLevel($app_id)=="sandbox" || $sandbox_override == TRUE) {
    $endpoint = 'https://sandbox.itunes.apple.com/verifyReceipt';
}
else {
    $endpoint = 'https://buy.itunes.apple.com/verifyReceipt';
}

$postData = json_encode(array(
    'receipt-data' => $receipt,
    'password' => $sharedSecret));

$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$response = curl_exec($ch);
$errno = curl_errno($ch);
$errmsg = curl_error($ch);
curl_close($ch);

这是我能得到的最好的。但还不够好。

logMessage(LogType::Info,"XXX URLFetch 0");
    $postData = json_encode(array(
    'receipt-data' => $receipt,
    'password' => $sharedSecret));
$post_data = json_decode($postData);
logMessage(LogType::Info,"XXX URLFetch 1");
$data = http_build_query($post_data);
logMessage(LogType::Info,"XXX URLFetch 2");

$context = [
  'http' => [
    'method' => 'post',
    'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
    'content' => $data
  ]
];

logMessage(LogType::Info,"XXX URLFetch 3");
$context = stream_context_create($context);
logMessage(LogType::Info,"XXX URLFetch 4");
$result = file_get_contents($endpoint, false, $context);
logMessage(LogType::Info,"XXX result:" . $result);
$response = $result;
$errno = 0;
logMessage(LogType::Info,"XXX response:");

能够发布但返回此响应     XXX结果:{“status”:21002}

2 个答案:

答案 0 :(得分:1)

为什么你的urlfetch代码中的json_decode $ post_data却没有卷曲?

答案 1 :(得分:0)

我遇到了这样的错误,结果发现'POST'在本地运行时必须是大写的。 在.appspot上,它使用小写的“post”但不在我的PC上本地。