农历查询
ALAPI 官方文档
根据输入的阳历日期查询相应的农历信息
基本说明:
接口地址:https://v2.alapi.cn/api/lunar
返回格式:json
请求方式:get/post
请求示例:https://v2.alapi.cn/api/lunar?token=token&date=yyyy-MM-dd-HH
请求参数说明:
名称 类型 必填 说明
token string 必填 请求token 扫码关注公众号
date string 选填 日期,默认当天
unix_time int 选填 10位时间戳的格式
返回参数说明:
名称 类型 说明
- - 见json
JSON返回示例:
{
	"code": 200,
	"msg": "success",
	"data": {
		"lunar_year": "2022",
		"lunar_month": "01",
		"lunar_day": "22",
		"lunar_hour": "13",
		"lunar_year_chinese": "二零二二",
		"lunar_month_chinese": "正月",
		"lunar_day_chinese": "廿二",
		"lunar_hour_chinese": "未时",
		"ganzhi_year": "壬寅",
		"ganzhi_month": "壬寅",
		"ganzhi_day": "丙午",
		"ganzhi_hour": "乙未",
		"wuxing_year": "水木",
		"wuxing_month": "水木",
		"wuxing_day": "火火",
		"wuxing_hour": "木土",
		"color_year": "黑",
		"color_month": "黑",
		"color_day": "红",
		"color_hour": "青",
		"animal": "虎",
		"term": null,
		"is_leap": false,
		"gregorian_year": "2022",
		"gregorian_month": "02",
		"gregorian_day": "22",
		"gregorian_hour": "13",
		"week_no": 2,
		"week_name": "星期二",
		"is_today": true,
		"constellation": "双鱼",
		"is_same_year": true
	},
	"time": 1645509579,
	"log_id": 354626638298177536
}
服务级错误码参照
错误码 说明
404 接口地址不存在
422 接口请求失败
400 接口请求失败
405 请求方法不被允许
100 token 错误
101 账号过期
102 接口请求次数超过限制
104 来源或者ip不在白名单
406 没有更多数据了
429 请求 QPS 超过限制
完整教学代码示例
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://v2.alapi.cn/api/lunar",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "token=用户中心获取token&date=2021-04-29-23&unix_time=1619710205",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/x-www-form-urlencoded",
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://v2.alapi.cn/api/lunar"

	payload := strings.NewReader("token=用户中心获取token&date=2021-04-29-23&unix_time=1619710205")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))
}