You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.9 KiB
51 lines
1.9 KiB
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
function getZodiacSign($month, $day) {
|
|
$signs = [
|
|
['name' => "摩羯座", 'start' => [12, 22], 'end' => [1, 19]],
|
|
['name' => "水瓶座", 'start' => [1, 20], 'end' => [2, 18]],
|
|
['name' => "双鱼座", 'start' => [2, 19], 'end' => [3, 20]],
|
|
['name' => "白羊座", 'start' => [3, 21], 'end' => [4, 19]],
|
|
['name' => "金牛座", 'start' => [4, 20], 'end' => [5, 20]],
|
|
['name' => "双子座", 'start' => [5, 21], 'end' => [6, 20]],
|
|
['name' => "巨蟹座", 'start' => [6, 21], 'end' => [7, 22]],
|
|
['name' => "狮子座", 'start' => [7, 23], 'end' => [8, 22]],
|
|
['name' => "处女座", 'start' => [8, 23], 'end' => [9, 22]],
|
|
['name' => "天秤座", 'start' => [9, 23], 'end' => [10, 22]],
|
|
['name' => "天蝎座", 'start' => [10, 23], 'end' => [11, 21]],
|
|
['name' => "射手座", 'start' => [11, 22], 'end' => [12, 21]]
|
|
];
|
|
|
|
foreach ($signs as $sign) {
|
|
if (
|
|
($month == $sign['start'][0] && $day >= $sign['start'][1]) ||
|
|
($month == $sign['end'][0] && $day <= $sign['end'][1])
|
|
) {
|
|
return $sign['name'];
|
|
}
|
|
}
|
|
return "未知";
|
|
}
|
|
|
|
function getChineseZodiac($year) {
|
|
$animals = ["鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"];
|
|
return $animals[($year - 4) % 12];
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['birthdate'])) {
|
|
$birthdate = new DateTime($_POST['birthdate']);
|
|
$year = (int)$birthdate->format('Y');
|
|
$month = (int)$birthdate->format('n');
|
|
$day = (int)$birthdate->format('j');
|
|
|
|
$zodiac = getZodiacSign($month, $day);
|
|
$chineseZodiac = getChineseZodiac($year);
|
|
|
|
echo json_encode([
|
|
'zodiac' => $zodiac,
|
|
'chineseZodiac' => $chineseZodiac
|
|
]);
|
|
} else {
|
|
echo json_encode(['error' => '无效的请求']);
|
|
} |