黄金价格行情接口
每10分钟自动更新黄金价格,包含国内黄金价格,纽约期货黄金价格,伦敦现货黄金价格

接口地址: https://58.linkpc.net/api/huangjin

返回格式: JSON

请求方式: GET

请求示例: https://58.linkpc.net/api/huangjin

请求参数说明:

名称 必填 类型 说明

返回参数说明:

名称 类型 说明

返回示例:

{
"code": 200,
"msg": "成功",
"data": {
"ShanghaiGoldExchange": {
"price": "0.00",
"change": "0.00",
"changePercentage": "0.00%",
"highest": "0.00",
"lowest": "0.00",
"open": "0.00",
"previousSettlement": "0.00",
"updateTime": null,
"date": null,
"market": "上海黄金交易所 人民币\/克"
},
"NewYorkCommodityExchange": {
"price": "0.00",
"change": "0.00",
"changePercentage": "0.00%",
"highest": "0.00",
"lowest": "0.00",
"open": "0.00",
"previousSettlement": "0.00",
"updateTime": null,
"date": null,
"market": "美国纽约商品交易所 美元\/盎司"
},
"LondonSpotGoldMarket": {
"price": "0.00",
"change": "0.00",
"changePercentage": "0.00%",
"highest": "0.00",
"lowest": "0.00",
"open": "0.00",
"previousSettlement": "0.00",
"updateTime": null,
"date": null,
"market": "英国伦敦黄金交易市场 美元\/盎司"
}
}
}

错误码格式说明:

名称 类型 说明

代码示例:

                            <?php
header('Content-type: application/json; charset=utf-8');
date_default_timezone_set('PRC');
$url = 'https://58.linkpc.net/api/huangjin';
$type = isset($_GET['type']) ? $_GET['type'] : '';
if ($type == 'json' || $type == 'JSON') {
$result = file_get_contents($url . '?type=json');
echo htmlspecialchars($result);
} else {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);

if (strpos($contentType, 'image') !== false) {
header('Content-Type: ' . $contentType);
echo $response;
} elseif (strpos($contentType, 'text') !== false) {
header('Content-Type: ' . $contentType);
echo $response;
} elseif (strpos($contentType, 'application/json') !== false) {
header('Content-Type: application/json');
echo $response;
} else {
header('Content-Type: text/html');
echo $response;
}
}
?>