用于应用内购买的 php 脚本
我正在为 iPhone/iPad 开发一个应用程序,它使用应用程序内购买功能。在服务器端,我加载一个 php 脚本来进行收据验证。这是脚本的内容:
<?php
$receipt = json_encode(array("receipt-data" => $_GET["receipt"]));
// NOTE: use "buy" vs "sandbox" in production.
$url = "https://sandbox.itunes.apple.com/verifyReceipt";
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_HEADER, 0);
curl_setopt($curl_handle, CURLOPT_POST, true);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $receipt);
$response_json = curl_exec($curl_handle);
$response = json_decode($response_json);
curl_close($curl_handle);
print $response->{'status'};
?>
我的问题是响应变量始终为空,我无法收到任何响应。另外 response_json
是空的,我不明白哪个是问题。我认为是服务器端的东西,但我不是 php 专家,服务器不在我的直接控制之下。任何人都可以建议我一种解决问题的方法或测试可能的方法吗?
谢谢
i'm doing an application for iPhone/iPad which uses the in-app purchase functionality. On the server side i load a php script for the receipt verification. Here is the content of the script:
<?php
$receipt = json_encode(array("receipt-data" => $_GET["receipt"]));
// NOTE: use "buy" vs "sandbox" in production.
$url = "https://sandbox.itunes.apple.com/verifyReceipt";
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_HEADER, 0);
curl_setopt($curl_handle, CURLOPT_POST, true);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $receipt);
$response_json = curl_exec($curl_handle);
$response = json_decode($response_json);
curl_close($curl_handle);
print $response->{'status'};
?>
My problem is that the response variable is always empty, i can't receive any response. Also the response_json
is empty and i can't understand which is the problem. I think is something server side, but i'm not an expert of php and the server is not under my direct control. Can anyone suggest me a way to resolve the problem or to test which coulod be?
Thank's
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
curl_exec()
失败,它将返回布尔值FALSE。您盲目地将响应提供给 json_decode 并假设您会得到一些东西。解码 boolean false 会得到一个空的 var。相反,试试这个:If
curl_exec()
fails, it will return a boolean FALSE. You blindly feed the response to json_decode and assume you'll get something out. Decoding boolean false gives you an empty var. Instead, try this: