); }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

包含文件

其他信息