为什么在livecoin上的PhP样本不包含?>托架?

时间:2017-11-06 14:34:53

标签: php

代码为https://www.livecoin.net/api/examples#vb

我试图在netbean添加结束括号,我收到了一个警告不必要的结束括号。我错过了什么?

<?php

$url = "https://api.livecoin.net/exchange/buylimit";
$apiKey = "gJx7Wa7qXkPtmTAaK3ADCtr6m5rCYYMy";
$secretKey = "8eLps29wsXszNyEhOl9w8dxsOsM2lTzg";

$params = array(
    'currencyPair'=> 'BTC/USD',
    'price'=> 60,
    'quantity'=>1
);

ksort($params);
$postFields = http_build_query($params, '', '&');
$signature = strtoupper(hash_hmac('sha256', $postFields, $secretKey));

$headers = array(
    "Api-Key: $apiKey",
    "Sign: $signature"
);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($statusCode!=200) {
    //dump info:
    echo "Status code: $statusCode, response: $response";
    //throw new Exception('Can not execute the query!');
}

var_dump(json_decode($response));

1 个答案:

答案 0 :(得分:0)

在该特定文件中只编写PHP代码时不需要PHP ?>关闭,在这种情况下关闭PHP只会浪费性能。