当前位置: 首页 > news >正文

货币汇率换算免费API接口(每日更新汇率)

接口概述

货币汇率换算API是由接口盒子免费API提供的一项免费服务接口,能够实现全球多种货币之间的汇率换算功能。该接口每日更新汇率数据,为开发者提供便捷的货币换算解决方案。

接口特点

  • 免费使用:基础功能完全免费

  • 每日更新:汇率数据每日自动更新

  • 多币种支持:支持全球170多种货币代码

  • 简单易用:请求参数简洁明了,返回数据格式规范

  • 无调用上限:每日调用次数无限制

重要说明

需要注意的是,该接口每日只更新一次汇率数据,对于金额较大的换算可能存在一定误差,适合一般参考用途。如需更实时的汇率数据,可联系官方定制接口。

接口基本信息

请求地址https://cn.apihz.cn/api/jinrong/huilv.php

请求方式:支持GET和POST两种方式

请求参数说明

参数名

类型

是否必填

说明

id

整数

用户中心的数字ID

key

字符串

用户中心通讯秘钥

from

字符串

待换算货币代码(如:USD),为空时返回货币代码大全

to

字符串

欲换算货币代码(如:CNY),为空时返回货币代码大全

money

数字

待换算金额

返回参数说明

参数名

说明

code

状态码(200成功,400错误)

msg

信息提示

uptime

货币汇率更新时间

money

待换算金额

from

待换算货币代码

to

欲换算货币代码

result

换算后的金额

rate

汇率

调用示例

1. 直接调用示例(使用公共ID和KEY)

复制

https://cn.apihz.cn/api/jinrong/huilv.php?id=88888888&key=88888888&from=USD&to=CNY&money=10

2. 成功返回示例

json

json

复制

{ "code": 200, "uptime": "2025-12-20 08:00:01", "money": "1", "from": "USD", "to": "CNY", "result": 7.0511, "rate": 7.0511 }

3. 错误返回示例

json

json

复制

{ "code": 400, "msg": "通讯秘钥错误。" }

4. 获取货币代码大全返回示例

json

json

复制

{ "code": 200, "message": "货币大全", "data": [ { "code": "USD", "name": "美元" }, { "code": "AED", "name": "阿联酋迪拉姆" }, // ...更多货币代码 ] }

编程语言调用示例

PHP调用示例

php

php

复制

<?php /** * 货币汇率换算API调用示例(PHP版) */ class CurrencyConverter { private $apiUrl = "https://cn.apihz.cn/api/jinrong/huilv.php"; private $userId = "你的用户ID"; // 请替换为实际用户ID private $userKey = "你的用户KEY"; // 请替换为实际用户KEY /** * 执行货币换算 * @param string $from 源货币代码 * @param string $to 目标货币代码 * @param float $amount 换算金额 * @return array 返回结果数组 */ public function convertCurrency($from, $to, $amount) { // 构建请求参数 $params = array( 'id' => $this->userId, 'key' => $this->userKey, 'from' => $from, 'to' => $to, 'money' => $amount ); // 构建请求URL $url = $this->apiUrl . '?' . http_build_query($params); // 发送GET请求 $response = file_get_contents($url); // 解析JSON响应 $result = json_decode($response, true); return $result; } /** * 获取所有支持的货币代码 * @return array 货币代码列表 */ public function getCurrencyList() { // 构建请求参数(不指定from和to参数) $params = array( 'id' => $this->userId, 'key' => $this->userKey, 'money' => 1 ); // 构建请求URL $url = $this->apiUrl . '?' . http_build_query($params); // 发送GET请求 $response = file_get_contents($url); // 解析JSON响应 $result = json_decode($response, true); return $result; } } // 使用示例 $converter = new CurrencyConverter(); // 示例1: 货币换算 echo "=== 货币换算示例 ===\n"; $result = $converter->convertCurrency("USD", "CNY", 100); if ($result['code'] == 200) { echo "换算结果: {$result['money']} {$result['from']} = {$result['result']} {$result['to']}\n"; echo "汇率: 1 {$result['from']} = {$result['rate']} {$result['to']}\n"; echo "更新时间: {$result['uptime']}\n"; } else { echo "错误: {$result['msg']}\n"; } // 示例2: 获取货币列表 echo "\n=== 获取货币列表示例 ===\n"; $currencyList = $converter->getCurrencyList(); if ($currencyList['code'] == 200) { echo "支持的货币数量: " . count($currencyList['data']) . "\n"; // 显示前5种货币作为示例 for ($i = 0; $i < min(5, count($currencyList['data'])); $i++) { $currency = $currencyList['data'][$i]; echo "{$currency['code']}: {$currency['name']}\n"; } } else { echo "错误: {$currencyList['msg']}\n"; } ?>

Python调用示例

python

python

下载

复制

#!/usr/bin/env python3 """ 货币汇率换算API调用示例(Python版) """ import requests import json class CurrencyConverter: def __init__(self, user_id, user_key): self.api_url = "https://cn.apihz.cn/api/jinrong/huilv.php" self.user_id = user_id # 请替换为实际用户ID self.user_key = user_key # 请替换为实际用户KEY def convert_currency(self, from_currency, to_currency, amount): """ 执行货币换算 :param from_currency: 源货币代码 :param to_currency: 目标货币代码 :param amount: 换算金额 :return: 返回结果字典 """ # 构建请求参数 params = { 'id': self.user_id, 'key': self.user_key, 'from': from_currency, 'to': to_currency, 'money': amount } try: # 发送GET请求 response = requests.get(self.api_url, params=params) response.raise_for_status() # 检查请求是否成功 # 解析JSON响应 result = response.json() return result except requests.exceptions.RequestException as e: return {'code': 400, 'msg': f'请求失败: {str(e)}'} except json.JSONDecodeError as e: return {'code': 400, 'msg': f'JSON解析失败: {str(e)}'} def get_currency_list(self): """ 获取所有支持的货币代码 :return: 货币代码列表 """ # 构建请求参数(不指定from和to参数) params = { 'id': self.user_id, 'key': self.user_key, 'money': 1 } try: # 发送GET请求 response = requests.get(self.api_url, params=params) response.raise_for_status() # 检查请求是否成功 # 解析JSON响应 result = response.json() return result except requests.exceptions.RequestException as e: return {'code': 400, 'msg': f'请求失败: {str(e)}'} except json.JSONDecodeError as e: return {'code': 400, 'msg': f'JSON解析失败: {str(e)}'} def main(): # 使用示例 # 注意: 请将下面的用户ID和KEY替换为实际值 converter = CurrencyConverter("你的用户ID", "你的用户KEY") # 示例1: 货币换算 print("=== 货币换算示例 ===") result = converter.convert_currency("USD", "CNY", 100) if result.get('code') == 200: print(f"换算结果: {result['money']} {result['from']} = {result['result']} {result['to']}") print(f"汇率: 1 {result['from']} = {result['rate']} {result['to']}") print(f"更新时间: {result['uptime']}") else: print(f"错误: {result.get('msg', '未知错误')}") # 示例2: 获取货币列表 print("\n=== 获取货币列表示例 ===") currency_list = converter.get_currency_list() if currency_list.get('code') == 200: print(f"支持的货币数量: {len(currency_list['data'])}") # 显示前5种货币作为示例 for i in range(min(5, len(currency_list['data']))): currency = currency_list['data'][i] print(f"{currency['code']}: {currency['name']}") else: print(f"错误: {currency_list.get('msg', '未知错误')}") if __name__ == "__main__": main()

使用前准备

  1. 注册账号:访问接口盒子(apihz.cn)官网注册账号

  2. 获取ID和KEY:登录用户中心获取专属的用户ID和通讯秘钥

  3. 替换示例代码:将上述示例代码中的"你的用户ID"和"你的用户KEY"替换为实际值

注意事项

  1. 避免使用公共凭证:示例中的公共ID和KEY有调用频次限制,建议使用个人专属凭证

  2. 错误处理:在实际应用中应添加完善的错误处理机制

  3. 汇率时效性:由于汇率每日更新一次,对于时效性要求高的场景请谨慎使用

  4. 金额精度:金额越大误差可能越大,适合一般参考用途

应用场景

该API接口适用于以下场景:

  • 电商平台的多币种价格显示

  • 金融应用的汇率查询功能

  • 旅行应用的预算换算工具

  • 教育类应用的货币知识学习

  • 个人理财应用的汇率监控

总结

货币汇率换算API是一个功能完善、使用简单的免费接口,为开发者提供了便捷的货币换算解决方案。通过本文提供的详细说明和代码示例,开发者可以快速集成该功能到自己的应用中。

如需了解更多详情或遇到问题,可访问接口盒子官方网站查看最新文档或联系技术支持。

http://www.jsqmd.com/news/119948/

相关文章:

  • python:报错:ModuleNotFoundError: No module named langchain_community
  • 系统文件gdi32.dll缺失或损坏 免费下载修复方法
  • 我发现LLM多语言解析跨境病历 远程会诊误诊率直降40%
  • 拒绝品牌碰瓷!如何通过影刀RPA为品牌IP搭建一套高效的“内容合规治理”工作流?
  • 国产操作系统 KylinOS 学习心得:从基础操作到实战部署
  • Windows系统文件GdiPlus.dll丢失或损坏 下载修复方法
  • Spring AI Alibaba 【四】 - 指南
  • fontext.dll文件缺失或损坏问题 下载修复方法
  • 王者荣耀全阵容分析
  • 国际清爽版,比国内版好用太多了!
  • 三折叠手机有什么使用场景和优势?三星Galaxy Z TriFold的全能进化
  • Windows系统文件framedynos.dll损坏问题 下载修复方法
  • 控件的Invoke 方法、BeginInvoke 方法、InvokeAsync 方法
  • Windows系统文件fwbase.dll丢失损坏问题 下载修复
  • Elasticsearch IK分词插件安装指南
  • 发哥存储站点----防止发卡网链接失效----请务必收藏本链接----看到这个页面第一件事先进Q群:633403801(里面每天发稳定图,根据稳定图购买)
  • 研究生必备8款AI写论文神器:5分钟生成25000字问卷类论文,自动生成高信度数据
  • C#之Modbus-RTU通讯-读取输出(保持)寄存器-无符号短整数
  • cesium126,240311,Ce for Ue 加载天地图P3-加载天地图的各种底图和注记:
  • Async 注解原理分析
  • 通达信支撑线
  • RFSOC学习记录(四)MTS时序分析
  • LLM参数: Temperature 与 Top-p解析
  • LLM参数: Temperature 与 Top-p解析
  • PHP 8.5 新特性 闭包可以作为常量表达式了
  • Agent设计模式与工程化
  • 为 AI 智能体打造高效的上下文工程 -- Anthropic
  • 《深度测评:从 GPT-5.1 到 GPT-5.2,OpenAI 到底在 Pro 模型里藏了什么黑科技?》
  • nRF54LV10A 介绍
  • 做人