【发布时间】:2018-04-18 18:08:04
【问题描述】:
代码是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));
【问题讨论】:
-
如果没有原始 HTML,通常不关闭 PHP 标记。其实it's in the Zend style guide not to do so.
-
PHP 关闭它自己的最后一个块。没必要。如果您想添加另一个块(php 或 html 等),这只是必要的
标签: php