使用汇率查询API帮你实时查询汇率,促进货币交流

汇率查询API以较低的成本获取较高的收益。提供实时汇率换算,外汇报价,货币汇率以及币种之间的汇率转换。广泛用于国际结算、银行汇率查询应用、开展跨国贸易、投资等参考场景。数据来源于公开的信息发布平台。

接口介绍

汇率查询API提供以下三个子接口:

1. 实时汇率查询换算

用于获取不同货币之间的实时汇率,并且可以根据输入金额进行换算。

2. 货币列表

获取系统支持查询汇率的所有货币信息列表,方便开发者了解可操作的货币种类。

3. 单货币列表

查询指定单一货币的详细信息,包括货币代码、名称、汇率等。

代码示例

1. 接口地址

汇率查询API的接口地址为:
https://api.tanshuapi.com/api/exchange/v1/index2

2.请求参数说明
名称 必填 类型 说明
key string 个人中心查看
from string 转换汇率前的货币代码
to string 转换汇率成的货币代码
money string 换算金额
3. 返回参数说明
参数名 类型 说明
code int 状态码,1表示成功
msg string 消息
from string 源货币代码
from_name string 源货币名称
to string 目标货币代码
to_name string 目标货币名称
exchange float 汇率
money float 换算后的金额
updatetime string 汇率更新时间
4. JSON返回示例
{
    "code": 1,
    "msg": "操作成功",
    "data": {
        "from": "CNY",
        "from_name": "人民币",
        "to": "EUR",
        "to_name": "欧元",
        "exchange": "0.120490",
        "money": "0.120490",
        "updatetime": "2025-04-17 15:16:15"
    }
}
5.Java代码示例
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.json.JSONObject;

public class ExchangeRateAPIExample {
    public static void main(String[] args) {
        String apiUrl = "https://api.example.com/exchange/v1/rate";
        String apiKey = "your_api_key_here";
        String fromCurrency = "CNY";
        String toCurrency = "EUR";
        double amount = 1.0;

        try {
            String urlStr = apiUrl + "?key=" + apiKey + "&from=" + fromCurrency + "&to=" + toCurrency + "&amount=" + amount;
            URL url = new URL(urlStr);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "application/json");

            int responseCode = conn.getResponseCode();
            System.out.println("响应码: " + responseCode);

            if (responseCode == HttpURLConnection.HTTP_OK) {
                BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                String inputLine;
                StringBuffer response = new StringBuffer();

                while ((inputLine = in.readLine()) != null) {
                    response.append(inputLine);
                }
                in.close();

                System.out.println("响应结果: " + response.toString());

                JSONObject jsonResponse = new JSONObject(response.toString());
                int code = jsonResponse.getInt("code");
                String msg = jsonResponse.getString("msg");
                JSONObject data = jsonResponse.getJSONObject("data");

                System.out.println("状态码: " + code);
                System.out.println("消息: " + msg);
                System.out.println("源货币代码: " + data.getString("from"));
                System.out.println("源货币名称: " + data.getString("from_name"));
                System.out.println("目标货币代码: " + data.getString("to"));
                System.out.println("目标货币名称: " + data.getString("to_name"));
                System.out.println("汇率: " + data.getString("exchange"));
                System.out.println("换算金额: " + data.getString("money"));
                System.out.println("更新时间: " + data.getString("updatetime"));
            } else {
                System.out.println("请求失败");
            }

            conn.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

你可能感兴趣的:(金融科技,人工智能,大数据,前端)