Coinbase.com

如何檢索包含 JSON 的 POST 數據

  • February 9, 2013

我以前從未使用過 JSON,並且正在嘗試從 coinbase 檢索發佈到我的網站的值。但我不知道該怎麼做。

關於 IPN 和回調的資訊可以在這裡找到:https ://coinbase.com/docs/merchant_tools/callbacks

更具體地說,到目前為止我的理解是我可以使用 json_decode($jsonData); 將 JSON 數據轉換為 PHP 數據。但是如何設置變數 $jsonData?

這是應該發送的響應:

{"order":{"id":null,"created_at":null,"status":"new","total_btc":
{"cents":100000000,"currency_iso":"BTC"},"total_native":
{"cents":2263,"currency_iso":"USD"},"custom":"123456789","button":
{"type":"buy_now","name":"Test Item","description":null,"id":null},"transaction":
{"hash":"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b","confirmations":0}}}
$data = json_decode(file_get_contents('php://input'), TRUE);
$text = print_r($data,true);
file_put_contents('coinbase.txt', $text);

這實際上將以下資訊發送到文本文件:

Array
(
   [order] => Array
       (
           [id] => 
           [created_at] => 
           [status] => new
           [total_btc] => Array
               (
                   [cents] => 100000000
                   [currency_iso] => BTC
               )

           [total_native] => Array
               (
                   [cents] => 2270
                   [currency_iso] => USD
               )

           [custom] => 123456789
           [button] => Array
               (
                   [type] => buy_now
                   [name] => Test Item
                   [description] => 
                   [id] => 
               )

           [transaction] => Array
               (
                   [hash] => 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
                   [confirmations] => 0
               )

       )

)

引用自:https://bitcoin.stackexchange.com/questions/7502