用于应用内购买的 php 脚本

发布于 2024-10-03 16:58:45 字数 870 浏览 2 评论 0原文

我正在为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉溺在你眼里的海 2024-10-10 16:58:45

如果curl_exec()失败,它将返回布尔值FALSE。您盲目地将响应提供给 json_decode 并假设您会得到一些东西。解码 boolean false 会得到一个空的 var。相反,试试这个:

...
$response_json = curl_exec($curl_handle);
if ($response_json === FALSE) {
    die(curl_error($curl_handle));
}
$response = json_decode($response_json);
...

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:

...
$response_json = curl_exec($curl_handle);
if ($response_json === FALSE) {
    die(curl_error($curl_handle));
}
$response = json_decode($response_json);
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文