} //某货币对其他所有货币的汇率 public function allcurrencies($from){ $from = strtolower($from); if(empty($_ENV['_config']['lecms_parseurl'])) { return $this->cfg['weburl'].'index.php?huilv-allcurrencies-from-'.$from.$_ENV['_config']['url_suffix']; }else{ return $this->cfg['weburl'].'exchange-rates/'.$from.'/allcurrencies'.$_ENV['_config']['url_suffix']; } } //---------------------------URL函数段end--------------------------------- //获取某个货币的pic public function get_currency_pic($currency){ $currency = strtolower($currency); return $this->cfg['tpl'].'currency/'.$currency.'.svg'; } //获取某个货币的金额符号 public function get_currency_symbol($currency){ $currency = strtoupper($currency); if(!isset($GLOBALS['currency_symbol'])){ $GLOBALS['currency_symbol'] = include_once PLUGIN_PATH.'le_huilv_morelang/config/currency_code.php'; } return isset($GLOBALS['currency_symbol'][$currency]['currency_fuhao']) ? $GLOBALS['currency_symbol'][$currency]['currency_fuhao'] : ''; } //获取汇率兑换详情 public function currency_converter($from, $to, $more = false, $money = 1){ $data = $this->getHuilv($from); if($data['err']){ return false; } $to = strtoupper($to); $d = $data['data']; if(isset($d['rates'][$to])){ if($more){ return $d; }else{ $huilv = $d['rates'][$to]['rate']; return $this->shuzifmt($money*$huilv); } }else{ return false; } } //汇率数据格式化 public function rate_fmt($rate, $money = 1) { if(!$rate){ return ''; } if(strpos($rate, 'E') !== false){ $floatNumber = floatval($rate); $rate_fmt = sprintf('%.10f', $floatNumber); }else{ $rate_fmt = $rate; } $money != 1 && $rate_fmt = $rate_fmt*$money; //0.0000780000这种格式去掉后面的0000,并且去掉,符号 $rate_fmt = str_replace(',', '', rtrim(rtrim(number_format($rate_fmt, 10), '0'), '.')); return $rate_fmt; } //汇率小数保留,这个有问题,比如1越南盾 0.000039 美元 public function shuzifmt($shuzi){ return number_format($shuzi, 4,'.',''); } //从缓存或者API里面获取汇率数据 public function getHuilv($currency = 'USD', $new = false){ //汇率缓存文件夹 $cache_base_dir = ROOT_PATH . 'huilv_cache'; if (!is_dir($cache_base_dir)) { mkdir($cache_base_dir, 0755, true); } $currency = strtoupper($currency); //$apiname = isset($this->cfg['le_huilv_morelang']['apiname']) ? $this->cfg['le_huilv_morelang']['apiname'] : 'exchangerate-api'; $api = isset($this->cfg['le_huilv_morelang']['api']) ? $this->cfg['le_huilv_morelang']['api'] : ''; $api2 = isset($this->cfg['le_huilv_morelang']['api2']) ? $this->cfg['le_huilv_morelang']['api2'] : ''; //主API if(!$api){ return false; } $apiarr = explode('->',$api); if(!isset($apiarr[1])){ return false; } $apiname = $apiarr[0]; $apikey = $apiarr[1]; $api_arr[$apiname] = $apikey; //次API $api2_status = 0; if($api2){ $api2arr = explode('->',$api2); if(isset($api2arr[1])){ $api_arr[$api2arr[0]] = $api2arr[1]; $api2_status = 1; } }else{ $api2arr = array(); } //这些货币,只能使用exchangerate_api if(in_array($currency, $this->_openexchangerates_api_no) && $api2_status && $api2arr[0] == 'exchangerate_api'){ return $this->exchangerate_api($cache_base_dir, $currency, $new, $api2arr[1]); } //循环调用API foreach($api_arr as $apiname=>$apikey){ $r = $this->$apiname($cache_base_dir, $currency, $new, $apikey); if(!$r['err']){ return $r; }else{ if(DEBUG){ print_r($r);exit; } } } return false; /** switch ($apiname){ case 'exchangerate-api': return $this->exchangerate_api($cache_base_dir, $currency, $new); case 'openexchangerates-api': return $this->openexchangerates_api($cache_base_dir, $currency, $new); } return false; */ } public function exchangerate_api($cache_base_dir, $currency, $new = false, $apikey = ''){ $cache_base_dir .= '/exchangerate_api'; if (!is_dir($cache_base_dir)) { mkdir($cache_base_dir, 0755, true); } //汇率缓存文件 $cache_file_path = $cache_base_dir . '/' . $currency . '.json'; //缓存时间(秒) $cachetime = isset($this->cfg['le_huilv_morelang']['cachetime']) ? $this->cfg['le_huilv_morelang']['cachetime'] : 24; $life = $cachetime*3600; //优先从缓存文件里面读取? if (!$new && file_exists($cache_file_path)) { $cacheTime = filemtime($cache_file_path); if ($_ENV['_time'] - $cacheTime < $life) { $huilvdata = json_decode(file_get_contents($cache_file_path), true); //下次更新时间已经到了,直接拉新的API数据 if(isset($huilvdata['time_next_update_unix']) && $huilvdata['time_next_update_unix'] < $_ENV['_time']){ unset($huilvdata); } }else{ unlink($cache_file_path); } } //从API获取 if (!isset($huilvdata)) { if(!$apikey){ return array('err'=>1,'msg'=>'请先配置APIKEY'); } $currency = strtoupper($currency); $apiurl = "https://v6.exchangerate-api.com/v6/{$apikey}/latest/{$currency}"; $response = $this->curl_html($apiurl); if ($response !== false) { $arr = json_decode($response, true); if (isset($arr['result']) && $arr['result'] === 'success') { $rates = array(); foreach ($arr['conversion_rates'] as $k=>$v){ $rates[strtoupper($k)] = array( 'rate'=>$v, 'updatetime'=>date('Y-m-d H:i:s',$arr['time_last_update_unix']) ); } $huilvdata['base_code'] = $arr['base_code']; $huilvdata['time_next_update_unix'] = $arr['time_next_update_unix'];//下次更新时间 $huilvdata['rates'] = $rates; //写入缓存文件 FW($cache_file_path, json_encode($huilvdata)); }else{ return array('err'=>1, 'msg'=>'exchangerate-api请求未成功,请检查API密钥。'); } }else{ return array('err'=>1, 'msg'=>'无法获取汇率数据,请检查exchangerate-api网络连接。'); } } return array('err'=>0, 'msg'=>'OK', 'data'=>$huilvdata); } public function openexchangerates_api($cache_base_dir, $currency, $new = false, $apikey = ''){ $cache_base_dir .= '/openexchangerates_api'; if (!is_dir($cache_base_dir)) { mkdir($cache_base_dir, 0755, true); } //汇率缓存文件 $cache_file_path = $cache_base_dir . '/' . $currency . '.json'; //缓存时间(秒) $cachetime = isset($this->cfg['le_huilv_morelang']['cachetime']) ? $this->cfg['le_huilv_morelang']['cachetime'] : 24; $life = $cachetime*3600; //优先从缓存文件里面读取? if (!$new && file_exists($cache_file_path)) { $cacheTime = filemtime($cache_file_path); if ($_ENV['_time'] - $cacheTime < $life) { $huilvdata = json_decode(file_get_contents($cache_file_path), true); }else{ unlink($cache_file_path); } } //从API获取 if (!isset($huilvdata)) { if(!$apikey){ return array('err'=>1,'msg'=>'请先配置APIKEY'); } $currency = strtoupper($currency); $apiurl = "https://openexchangerates.org/api/latest.json?app_id={$apikey}&base={$currency}"; $response = $this->curl_html($apiurl); if ($response !== false) { $arr = json_decode($response, true); if (isset($arr['rates']) && $arr['rates']) { $rates = array(); foreach ($arr['rates'] as $k=>$v){ $rates[strtoupper($k)] = array( 'rate'=>$v, 'updatetime'=>date('Y-m-d H:i:s',$arr['timestamp']) ); } $huilvdata['base_code'] = $arr['base']; //$huilvdata['time_next_update_unix'] = $arr['time_next_update_unix'];//下次更新时间 $huilvdata['rates'] = $rates; //写入缓存文件 FW($cache_file_path, json_encode($huilvdata)); }else{ return array('err'=>1, 'msg'=>'openexchangerates.org请求未成功,请检查API密钥。'); } }else{ return array('err'=>1, 'msg'=>'无法获取汇率数据,请检查openexchangerates.org网络连接。'); } } return array('err'=>0, 'msg'=>'OK', 'data'=>$huilvdata); } //CURL获取html public function curl_html($url, $method = 'GET'){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); $ssl = preg_match('/^https:\/\//i',$url) ? TRUE : FALSE; if($ssl){ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 不从证书中检查SSL加密算法是否存在 } // 设置连接超时时间,如果5秒内无法连接则返回 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // 设置请求超时时间,如果10秒内无法完成则返回 curl_setopt($ch, CURLOPT_TIMEOUT, 10); $result = curl_exec($ch); curl_close($ch); return $result; } //汇率换算记录写入日志 public function write_currency_converter_log($message, $limit = 100) { $cache_base_dir = ROOT_PATH . 'huilv_cache'; if (!is_dir($cache_base_dir)) { mkdir($cache_base_dir, 0755, true); } $logFile = $cache_base_dir."/history.log"; $maxLines = $limit; $fp = fopen($logFile, 'c+'); // 读写模式,不截断文件 if (flock($fp, LOCK_EX)) { // 获取独占锁 $lines = []; while (!feof($fp)) { $line = fgets($fp); if ($line !== false && trim($line) !== '') { $lines[] = trim($line); } } $lines[] = $message; $lines = array_slice($lines, -$maxLines); ftruncate($fp, 0); // 清空文件 rewind($fp); // 回到文件开头 fwrite($fp, implode(PHP_EOL, $lines) . PHP_EOL); flock($fp, LOCK_UN); // 释放锁 } fclose($fp); } } Lecms 3.0.3 错误

错误信息

错误位置

基本信息

程序流程

SQL

$_GET

$_POST

$_COOKIE

包含文件

其他信息