农历查询
其他 官方文档
根据日期获取农历、黄历、禁忌、星期、生肖、当月的节气、是否闰月、是不是大月相关信息
基本说明:
接口地址:https://www.sojson.com/open/api/lunar/json.shtml
返回格式:json
请求方式:get
请求示例:https://www.sojson.com/open/api/lunar/json.shtml?date=2019-10-4
请求参数说明:
名称 类型 必填 说明
date string 选填 要查询的日期
返回参数说明:
名称 类型 说明
- - -
JSON返回示例:
{
	"status": 200,
	"message": "success",
	"data": {
		"year": 2019,
		"month": 10,
		"day": 4,
		"lunarYear": 2019,
		"lunarMonth": 9,
		"lunarDay": 6,
		"cnyear": "贰零壹玖 ",
		"cnmonth": "九",
		"cnday": "初六",
		"hyear": "己亥",
		"cyclicalYear": "己亥",
		"cyclicalMonth": "癸酉",
		"cyclicalDay": "甲戌",
		"suit": "祭祀,沐浴,赴任,出行,馀事勿取",
		"taboo": "诸事不宜",
		"animal": "猪",
		"week": "Friday",
		"festivalList": [],
		"jieqi": {
			"9": "寒露",
			"24": "霜降"
		},
		"maxDayInMonth": 29,
		"leap": false,
		"lunarYearString": "己亥",
		"bigMonth": false
	}
}
服务级错误码参照
错误码 说明
500 参数错误
完整教学代码示例
<?php
/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2019/10/4 21:10
 */
//----------------------------------
// 农历查询 调用类
//----------------------------------
class freeApi{
    private $apiUrl;

    public function __construct(){
        $this->apiUrl = 'https://www.sojson.com/open/api/lunar/json.shtml?date=2019-10-4';
    }
    /**
     * 获取结果
     * @return array
     */
    public function getResult(){
        return $this->freeApiCurl($this->apiUrl);
    }
    /**
     * 请求接口返回内容
     * @param  string $url [请求的URL地址]
     * @param  string $params [请求的参数]
     * @param  int $ipost [是否采用POST形式]
     * @return  string
     */
    public function freeApiCurl($url,$params=false,$ispost=0){
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
        curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
        curl_setopt( $ch, CURLOPT_USERAGENT , 'free-api' );
        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
        curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
        if( $ispost )
        {
            curl_setopt( $ch , CURLOPT_POST , true );
            curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
            curl_setopt( $ch , CURLOPT_URL , $url );
        }
        else
        {
            if($params){
                curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
            }else{
                curl_setopt( $ch , CURLOPT_URL , $url);
            }
        }
        $response = curl_exec( $ch );
        if ($response === FALSE) {
            return false;
        }
        curl_close( $ch );
        return $response;
    }
}