一、四个子接口全览
二、货币种类列表(/list)
获取系统支持的所有币种代码。用于初始化币种选择器或下拉菜单。
接口地址:https://market.aliyun.com/detail/cmapi00065831 import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class ExchangeRateListAPI { public static void main(String[] args) { String host = "https://market.aliyun.com/detail/cmapi00065831"; String path = "/list"; String appcode = "你的AppCode"; try { String url = host + path; URL obj = new URL(url); HttpURLConnection connection = (HttpURLConnection) obj.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", "APPCODE " + appcode); int responseCode = connection.getResponseCode(); System.out.println("Response Code: " + responseCode); BufferedReader in = new BufferedReader( new InputStreamReader(connection.getInputStream())); String inputLine; StringBuilder response = new StringBuilder(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.println(response.toString()); } catch (Exception e) { e.printStackTrace(); } } }返回的data.list是一个数组,每个元素包含currency(货币代码)和name(中文名称),以及可选的logo字段。
三、实时汇率查询换算(/index)
传入源币种、目标币种和金额,直接返回换算结果。
String querys = "from=CNY&to=USD&money=1"; String url = host + "/index?" + querys; // ... 发起 GET 请求返回示例:
{ "code": 1, "msg": "操作成功", "data": { "from": "CNY", "from_name": "人民币", "to": "USD", "to_name": "美元", "exchange": "0.147839", "updatetime": "2026-06-12 22:50:23", "money": "0.147839" } }四、单个货币汇率列表(/single)
一次请求获取某币种对所有其他货币的汇率。适合做汇率速览卡片。
String querys = "from=CNY"; String url = host + "/single?" + querys;返回的data.list是一个对象,key 为货币代码,value 包含name和rate。
五、银行汇率查询(/bank)
查询银行的实时外汇牌价。传入bank_code参数。
String querys = "bank_code=ICBC"; // 工商银行 String url = host + "/bank?" + querys;四个价格字段:
| 字段 | 说明 |
|---|---|
| hui_in | 汇买价——银行买入外汇 |
| hui_out | 汇卖价——银行卖出外汇 |
| chao_in | 钞币买入价 |
| chao_out | 钞币卖出价 |
跨境结算时实际换汇成本用的是 hui_out。
六、典型应用场景
跨境电商平台:使用币种列表初始化选择器,配合实时汇率换算自动将商品价格转换为用户所在国货币。
金融资讯应用:通过单货币多汇率查询一次获取人民币兑多种货币汇率。
财务与会计系统:自动完成多币种账务换算,支持历史汇率回溯。
银行与外汇服务平台:获取工行、中行等十大银行的实时外汇牌价。
七、总结
汇率查询 API 的四个子接口覆盖了从币种枚举到银行牌价的完整场景。在实际项目中,通常组合使用:用 /list 初始化,用 /index 做换算,用 /single 做展示,用 /bank 做结算参考。