Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP-Changelly API中使用CURL的JSON RPC 2.0 API调用_Php_Json_Api_Curl_Json Rpc - Fatal编程技术网

在PHP-Changelly API中使用CURL的JSON RPC 2.0 API调用

在PHP-Changelly API中使用CURL的JSON RPC 2.0 API调用,php,json,api,curl,json-rpc,Php,Json,Api,Curl,Json Rpc,我试图用下面的代码调用changelly API,但它返回“Unauthorized”作为响应 如果有人能帮助识别我在下面代码中犯的错误,我将不胜感激 $API_URL = 'https://api.changelly.com'; $API_KEY = 'XXXXX'; $API_SECRET = 'XXXXX'; $message = array(); $message['jsonrpc'] = '2.0'; $message['method'] = 'getMinAmount'; $mes

我试图用下面的代码调用changelly API,但它返回“Unauthorized”作为响应

如果有人能帮助识别我在下面代码中犯的错误,我将不胜感激

$API_URL = 'https://api.changelly.com';
$API_KEY = 'XXXXX';
$API_SECRET = 'XXXXX';

$message = array();
$message['jsonrpc'] = '2.0';
$message['method'] = 'getMinAmount';
$message['params'] = array('from' => 'BTC', 'to' => 'LTC');
$message['id'] ='12345';
$data = json_encode($message);
$sign = hash_hmac('SHA512', $data, $API_SECRET);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_URL);
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_GET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json",'Authorization:api-key: '.$API_KEY.':sign: '.$sign));

$final_result = curl_exec($ch); 
curl_close($ch);
echo '<pre>';
print_r($final_result);
$API\u URL='1https://api.changelly.com';
$API_KEY='XXXXX';
$API_SECRET='XXXXX';
$message=array();
$message['jsonrpc']='2.0';
$message['method']='getMinAmount';
$message['params']=array('from'=>'BTC','to'=>'LTC');
$message['id']='12345';
$data=json_encode($message);
$sign=hash_hmac('SHA512',$data,$API_SECRET);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$API_URL);
curl_setopt($ch,CURLOPT_头,false);
curl_setopt($ch,CURLOPT_GET,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HTTPHEADER,数组(“Accept:application/json”,“Authorization:api key:”.$api_key.':sign:”.$sign));
$final\u result=curl\u exec($ch);
卷曲关闭($ch);
回声';
打印(最终结果);
Changelly API指南位于


谢谢你的代码中有错误的标题集


请检查此示例:,希望能有所帮助。

在代码中,您的标题集错误


请检查此示例:,希望有帮助。

我认为您需要在HTTPHEADER中设置“内容类型”:“应用程序/json”,而不是“接受:应用程序/json”。不确定@罗摩克里希纳也没有帮助。这与JSON RPC 2.0有关,因此我怀疑它是否与符号变量有关。我认为您需要在HTTPHEADER中设置“Content type”:“application/JSON”,而不是“Accept:application/JSON”。不确定@罗摩克里希纳也没有帮助。这与JSON RPC 2.0有关,所以我怀疑它是否与符号变量有关