IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    替代更换api.exchangerate.host的货币汇率接口

    YY.K发表于 2024-01-06 19:17:00
    love 0

    api.exchangerate.host 的API不能白嫖了, 找了个新的汇率接口api.vatcomply.com

    原有代码

    function exchange($from, $to)
    {
        try {
            $result = file_get_contents('https://api.exchangerate.host/latest?symbols=' . $to . '&base=' . $from);
            $result = json_decode($result, true);
            return $result['rates'][$to];
        } catch (Exception $e){
            echo "Exchange error: ".$e;
            return "Exchange error: ".$e;
        }
    
    }

    更新后

    function exchange($from, $to)
    {
        try {
            $result = file_get_contents('https://api.vatcomply.com/rates?base='. $from);
            $result = json_decode($result, true);
            return $result['rates'][$to];
        } catch (Exception $e){
            echo "Exchange error: ".$e;
            return "Exchange error: ".$e;
        }
    
    }


沪ICP备19023445号-2号
友情链接