gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 23:40:42 26 4
gpt4 key购买 nike

有人可以帮助将此 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}

最佳答案

为什么在 urlfetch 代码中而不是在 curl 中对 $post_data 进行 json_decode?

关于php - 将 php curl 转换为用于 iTunes InApp verifyReceipt 的 GAE urlfetch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22775207/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com