接口地址:http://web.juhe.cn:8080/finance/gold/shgold |
---|
返回格式:json |
请求方式:get |
请求示例:http://web.juhe.cn:8080/finance/gold/shgold?key=您申请的APPKEY |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
key | string | 必填 | 应用APPKEY,申请数据系统分配 扫码关注公众号 |
v | String | 选填 | JSON格式版本(0或1)默认为0,建议使用格式1 |
名称 | 类型 | 说明 |
---|---|---|
见JSON返回示例 | - | - |
{
"resultcode": "200",
"reason": "SUCCESSED!",
"result": [{
"1": {
"variety": "Ag(T+D)",
/*品种*/
"latestpri": "6585.00",
/*最新价*/
"openpri": "6712.00",
/*开盘价*/
"maxpri": "6721.00",
/*最高价*/
"minpri": "6581.00",
/*最低价*/
"limit": "-1.98%",
/*涨跌幅*/
"yespri": "6718.00",
/*昨收价*/
"totalvol": "1564524.0000",
/*总成交量*/
"time": "2012-12-19 15:29:59" /*更新时间*/
},
......
"2": {
"variety": "Au(T+D)",
"latestpri": "336.60",
"openpri": "341.00",
"maxpri": "341.40",
"minpri": "336.00",
"limit": "-1.52%",
"yespri": "341.81",
"totalvol": "22842.0000",
"time": "2012-12-19 15:29:30"
},
"7": {
"variety": "Au99.99",
"latestpri": "336.77",
"openpri": "342.00",
"maxpri": "342.00",
"minpri": "336.40",
"limit": "-1.53%",
"yespri": "342.00",
"totalvol": "6936.2000",
"time": "2012-12-19 15:29:53"
}
......
}]
}
错误码 | 说明 |
---|---|
202901 | 查询不到结果 |
202902 | 参数错误 |
10001 | 错误的请求KEY |
10002 | 该KEY无请求权限 |
10003 | KEY过期 |
10004 | 错误的OPENID |
10005 | 应用未审核超时,请提交认证 |
10007 | 未知的请求源 |
10008 | 被禁止的IP |
10009 | 被禁止的KEY |
10011 | 当前IP请求超过限制 |
10012 | 请求超过次数限制 |
10013 | 测试KEY超过请求限制 |
10014 | 系统内部异常(调用充值类业务时,请务必联系客服或通过订单查询接口检测订单,避免造成损失) |
10020 | 接口维护 |
10021 | 接口停用 |
<?php
/**
* Created by PhpStorm.
* User: FZS
* Time: 2019/3/15 17:50
*/
//----------------------------------
// 聚合 黄金数据 调用类
//----------------------------------
class freeApi{
private $apiKey = false; //聚合appkey
private $apiUrl = 'http://web.juhe.cn:8080/finance/gold/shgold';
public function __construct($apikey){
$this->apiKey = $apikey;
}
/**
* 将JSON内容转为数据,并返回
* @param string $content [内容]
* @return array
*/
public function returnArray($content){
return json_decode($content,true);
}
/**
* 获取 黄金数据 结果
* @return array
*/
public function getResult(){
$params = [
"key" => $this->apiKey,//应用APPKEY(应用详细页查询)
"v" => "",//JSON格式版本(0或1)默认为0
];
$params = http_build_query($params);
return $this->returnArray($this->freeApiCurl($this->apiUrl,$params,1));
}
/**
* 请求接口返回内容
* @param string $url [请求的URL地址]
* @param string $params [请求的参数]
* @param int $ipost [是否采用POST形式]
* @return string
*/
public function freeApiCurl($url,$params=false,$ispost=0){
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_USERAGENT , 'free-api' );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
if( $ispost )
{
curl_setopt( $ch , CURLOPT_POST , true );
curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
curl_setopt( $ch , CURLOPT_URL , $url );
}
else
{
if($params){
curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
}else{
curl_setopt( $ch , CURLOPT_URL , $url);
}
}
$response = curl_exec( $ch );
if ($response === FALSE) {
return false;
}
curl_close( $ch );
return $response;
}
}