调用示例
1. GET请求示例
https://ping.4759.cn/api/exchange.php?apikey=key_123456&from=USD&to=CNY&amount=1
2. POST请求示例(curl)
curl -X POST https://ping.4759.cn/api/exchange.php \
-d "apikey=key_123456&from=美元&to=人民币&amount=1"
3. PHP调用示例
<?php
// +----------------------------------------------------------------------
// | 实时汇率兑换接口 PHP调用示例
// | 复制即可使用,需替换为自己的API Key
// +----------------------------------------------------------------------
$apikey = '你的API授权码';
$from = '美元';
$to = '人民币';
$amount = '1';
$apiUrl = 'https://ping.4759.cn/api/exchange.php?apikey='.urlencode($apikey).
'&from='.urlencode($from).'&to='.urlencode($to).'&amount='.urlencode($amount);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $apiUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FOLLOWLOCATION => true
]);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if ($result['code'] == 200) {
echo "源货币: " . $result['data']['from'] . "\n";
echo "目标货币: " . $result['data']['to'] . "\n";
echo "实时汇率: " . $result['data']['rate'] . "\n";
echo "兑换结果: " . $result['data']['result'] . "\n";
} else {
echo "错误: " . $result['msg'];
}
?>
4. Python调用示例
import requests
apikey = '你的API授权码'
from = 'USD'
to = 'CNY'
amount = 1
api_url = f'https://ping.4759.cn/api/exchange.php?apikey={apikey}&from={from}&to={to}&amount={amount}'
try:
response = requests.get(api_url, timeout=10)
result = response.json()
print(result)
except Exception as e:
print("请求失败",e)
5. 成功返回JSON示例
{
"code": 200,
"msg": "success",
"data": {
"from": "USD",
"to": "CNY",
"amount": 1,
"rate": 7.1956,
"result": 7.1956,
"update_time": "2026-07-22 11:22:33"
},
"usage": {
"today_used": 8,
"today_remaining": 992,
"hourly_remaining": "无统计"
}
}