1

誰かがこのコードのどこにエラーがあるのか​​教えてもらえますか? モバイル iPhone アプリケーションを使用して、Apple に情報を送信する php スクリプトを呼び出します。Apple は、連想配列に複数の値を含む JSON オブジェクトを返します。

「ステータス」値に到達したいのですが、電話でコードを実行するたびに、php スクリプトが完全な Apple の返された文字列を送信します。XCode デバッガーでは、受信した文字列は次のようになります。

[DEBUG]... responseString : {"receipt":{"item_id":"328348691", "original_transaction_id":"1000000000081203", "bvrs":"1.0", "product_id":"julia_01", "purchase_date": "2009-10-05 23:47:00 Etc/GMT", "quantity":"1", "bid":"com.latin3g.chicasexy1", "original_purchase_date":"2009-10-05 23:47: 00 Etc/GMT", "transaction_id":"1000000000081203"}, "ステータス":0}

しかし、文字列で気にするのは「ステータス」値だけです。私はすでにドキュメントの中を見てきましたが、解決策が見つかりません。私はphpが初めてですが、これは長すぎます。ここでスクリプト:

<?php
//The script takes arguments from phone's GET call
$receipt = json_encode(array("receipt-data" => $_GET["receipt"]));

//Apple's url
$url = "https://sandbox.itunes.apple.com/verifyReceipt";

//USe cURL to create a post request
//initialize cURL
$ch = curl_init();

// set the target url
curl_setopt($ch, CURLOPT_URL,$url);

// howmany parameter to post
curl_setopt($ch, CURLOPT_POST, 1);

// the receipt as parameter
curl_setopt($ch, CURLOPT_POSTFIELDS,$receipt);

$result = curl_exec ($ch);
//Here the code "breaks" and return the complete string (i've tested that)
//and apparently doesn't get to the json_decode function (i think something's wrong there, so code breaks here)
curl_close ($ch);

$response = json_decode($result);   

echo $response->{'status'};


?>

最後にエコーを付けなくても、スクリプトは完全な文字列を返します (私には奇妙です)。

事前に感謝し、別の質問から再度主張する場合はお詫び申し上げます

4

1 に答える 1

2

RETURNTRANSFER要求された URL からの出力を文字列としてキャプチャできるように、オプションを 1 に設定してみてください。cURL のデフォルトの動作は、結果をブラウザに直接出力することのようです。

...
$ch = curl_init();

// set the target url
curl_setopt($ch, CURLOPT_URL,$url);

// howmany parameter to post
curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // <---- Add this


// the receipt as parameter
curl_setopt($ch, CURLOPT_POSTFIELDS,$receipt);
...
于 2009-10-06T00:14:55.333 に答える