function get_lunar_date() { $current_date = new DateTime('now', new DateTimeZone('Asia/Shanghai')); $year = $current_date->format('Y'); $month = $current_date->format('n'); $day = $current_date->format('j'); $hour = $current_date->format('G'); $minute = $current_date->format('i'); $url = 'http://cn2.e-123.cn:8081/api/lunar?' . time(); $data = json_encode([ 'year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'minute' => $minute ]); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'Content-Type: application/json', ]); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $response = curl_exec($ch); if ($response === false) { $error = curl_error($ch); curl_close($ch); return '

cURL 错误: ' . $error . '

'; } curl_close($ch); $result = json_decode($response, true); if ($result) { $gregorian_date = date('Y-m-d', strtotime($result['日期'])); $lunar_info = $result['农历']; $start_pos = mb_strpos($lunar_info, '年') + 1; $lunar_date = mb_substr($lunar_info, $start_pos); return $gregorian_date . "\t" . $lunar_date; } else { return '

无法获取农历信息。

'; } } function get_jieqi_info() { $current_date = new DateTime(); $year = $current_date->format('Y'); $month = $current_date->format('n'); $day = $current_date->format('j'); $hour = $current_date->format('G'); $minute = $current_date->format('i'); $url = 'http://cn2.e-123.cn:8081/api/lunar'; $data = json_encode([ 'year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'minute' => $minute ]); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'Content-Type: application/json', ]); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $response = curl_exec($ch); if ($response === false) { $error = curl_error($ch); curl_close($ch); return '

cURL 错误: ' . $error . '

'; } curl_close($ch); $result = json_decode($response, true); if ($result) { // 获取节气信息 $current_jieqi = $result['今日节气']; $next_jieqi = isset($result['下一节气']) ? $result['下一节气'][0] : '无'; // 存储节气信息 return '当日节气: ' . $current_jieqi . ' | 下一个节气: ' . $next_jieqi; } else { return '

无法获取农历信息。

'; } }