调用示例
1. GET请求示例
http://ping.4759.cn/api/exchange.php?apikey=key_123456&from=USD&to=CNY&amount=1
2. POST请求示例(curl)
curl -X POST http://ping.4759.cn/api/exchange.php \
-d "apikey=key_123456&from=USD&to=CNY&amount=1"
3. PHP调用示例
<?php
// +----------------------------------------------------------------------
// | 实时汇率兑换接口 PHP调用示例
// | 复制即可使用,需替换为自己的API Key
// +----------------------------------------------------------------------
$apikey = 'key_123456';
$from = 'USD';
$to = 'CNY';
$amount = '1';
$apiUrl = 'http://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
]);
$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 = 'key_123456'
from = 'USD'
to = 'CNY'
amount = 1
api_url = f'http://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:
print("请求失败")
5. 返回结果示例
{
"code": 200,
"msg": "success",
"data": {
"from": "USD",
"to": "CNY",
"amount": "1",
"rate": "7.1956",
"result": "7.1956",
"update_time": "2025-12-20 11:22:33"
},
"usage": {
"today_used": 8,
"today_remaining": 992,
"hourly_remaining": 42
}
}