2016-10-18 6 views
0

Webhookをセットアップして、サーバー上のPHPページに通知を送信しました。私のサーバーへの通知要求は、このようなものです:PHP JSON POSTデータを取得する

POST /message/receive HTTP/1.1 
Host: http://www.yoururl.com/zipwhip/api/receive 
Content-Length: 581 
Content-Type: application/json; charset=UTF-8 

{ "body":"Thanks for texting, this is an auto reply!", 
    "bodySize":42, 
    "visible":true, 
    "hasAttachment":false, 
    "dateRead":null, 
    "bcc":null, 
    "finalDestination":"4257772300", 
    "messageType":"MO", 
    "deleted":false, 
"statusCode":4, 
"id":634151298329219072, "scheduledDate":null, "fingerprint":"132131532", "messageTransport":9, "contactId":3382213402, "address":"ptn:/4257772222", 
"read" "dateCreated":"2015-08-19T16:53:45-07:00", "dateDeleted":null, 
    "dateDelivered":null, 
    "cc":null, 
    "finalSource":"4257772222", 
} "dev 

私は私が働くことができる文字列にJSONデータを変換するには、以下のものを使用して試してみたが、私はこれまで何を得ていないよ:

私が読んだ
$inputJSON = file_get_contents('php://input'); 
$input= json_decode($inputJSON, TRUE); 

すべてが、これは動作しなくてはならないことを示す - 私がテストした以下と、これは実際に働いている:

$webhookContent = ""; 

    $webhook = fopen('php://input' , 'rb'); 
    while (!feof($webhook)) { 
     $webhookContent .= fread($webhook, 4096); 
    } 
    fclose($webhook); 

私は理解しようとしている理由のfile_get_contents(「PHP://入力」);私が読んできたすべての関数が私が使用すべき関数であり、なぜfopen( 'php:// input'、 'rb')であるのかが分かっていればうまくいきません。代わりに動作しますか?私はのvar_dump($ inputJSON)を行う場合

私が取得:

$inputJSON = file_get_contents('php://input'); 
$input= json_decode($inputJSON); 

私は思う:

string(527) "{ "body":"Thanks for texting, this is an auto reply!", 
    "bodySize":42, 
    "visible":true, 
    "hasAttachment":false, 
    "dateRead":null, 
    "bcc":null, 
    "finalDestination":"4257772300", 
    "messageType":"MO", 
    "deleted":false, 
"statusCode":4, 
"id":634151298329219072, "scheduledDate":null, "fingerprint":"132131532", "messageTransport":9, "contactId":3382213402, "address":"ptn:/4257772222", 
"read" "dateCreated":"2015-08-19T16:53:45-07:00", "dateDeleted":null, 
    "dateDelivered":null, 
    "cc":null, 
    "finalSource":"4257772222", 
}" 

のvar_dump($入力)がNULL

+0

それで 'var_dump($ inputJSON)'はあなたに何を与えていますか? – jeroen

+2

あなたのJSONは私には見えません。 – simon

+0

@jeroen var_dump($ inputJSON)の結果を含めるように質問を編集しました – user982124

答えて

0

返し今私のために働いている、次の私の問題は以下を使用していました:

$input= json_decode($inputJSON, TRUE); 

の代わりに:

$input= json_decode($inputJSON); 
関連する問題