将iTunes curl转换为GAE urlfetch以验证iTunesReceipt [英] Convert php curl to GAE urlfetch for iTunes InApp verifyReceipt

查看:100
本文介绍了将iTunes curl转换为GAE urlfetch以验证iTunesReceipt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

$ b $ 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 \\\

'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代码中使用json_decode $ post_data而不是curl?


Can someone help to convert this PHP Curl to UrlFetch ? This is used for 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);

this is as good as I can get. But not good enough.

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:");

It is able to post but returns this response XXX result:{"status":21002}

解决方案

Why do you json_decode $post_data in your urlfetch code but not in curl?

这篇关于将iTunes curl转换为GAE urlfetch以验证iTunesReceipt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆