문제

누군가이 코드의 오류가 어디에 있는지 알려주시겠습니까? 그런 다음 Apple은 연관 배열에 여러 값이 포함 된 JSON 객체를 반환합니다.

'상태'값에 도달하고 싶지만 전화로 코드를 실행할 때마다 PHP 스크립트는 완전한 Apple의 반환 된 문자열을 보냅니다. Xcode 디버거에서 수신 된 문자열은 다음과 같습니다.

Debug] ... responseString : { "영수증": { "item_id": "328348691", "Original_Transaction_id": "10000000000081203", "bvrs": "1.0", "uppu즈즈": "Julia_01", "buyuest_date": "2009-10-05 23:47:00 etc/gmt", "수량": "1", "bid": "com.latin3g.chicasexy1", "Original_purchase_date": "2009-10-05 23:47 : 00 etc/gmt ","transaction_id ":"10000000000081203 "},"상태 ": 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'};


?>

마지막에 에코를 넣지 않더라도 스크립트는 여전히 완전한 문자열을 반환합니다 (나에게 홀수).

다른 질문에서 다시 고집하면 미리 감사 드리고 Apollogies

도움이 되었습니까?

해결책

설정해보십시오 RETURNTRANSFER 옵션 1이므로 요청 된 URL에서 출력을 문자열로 캡처 할 수 있습니다. 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);
...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top