参数名 | 参数说明 | 可选值 | 备注 | 必填项 |
---|---|---|---|---|
date | 需要查询的日期,为空则返回当天数据 | 格式可为20180101或2018-01-01或2018/01/01 | ||
cn_to_unicode | 汉字Unicode转码 |
1
0 |
本设置是对服务器返回数据时是否对中文汉字进行unicode转码,为增强兼容性,默认以unicode转码 | |
token | 密匙 | 请输入您的token密匙 | 是 | |
datatype | 返回的数据类型 |
json
xml |
json/xml 可选,默认为json格式 |
参数名 | 参数说明 | 备注 |
---|---|---|
ApiName | 接口代码 | |
ErrorCode | 返回0或1,0代表无错误,1代表错误,代码不为0时注意查看ErrorReason | |
ErrorReason | 请求失败原因,“no” 代表无错误,正常返回数据 |
参数名 | 参数说明 | 备注 | |||
---|---|---|---|---|---|
gongli | 您查询的公历日期 | 20180215 | |||
week | 星期 | 星期四 | |||
nongli | 对应的农历日期 | 丁酉年腊月三十(2017) | |||
xingzuo | 星座 | ||||
nianci | 年次 | 戊戍年甲寅月戊寅日 | |||
shengxiao | 生肖 | 鸡 | |||
do | 宜行 | 纳采|会亲友|竖柱|上梁|立券|入殓|移柩|安葬|启钻 | |||
nodo | 不宜行 | 祭祀|移徙|入宅|动土|破土 | |||
jieqi | 节气 | 立春后 | |||
runnian | 是否为闰年 | 公历,结果为: 是/否 | |||
runyue | 当年农历是否有闰月 | 如果当年有闰月,会返回具体闰几月,否认返回为空 | |||
festivals_nl | 农历节日 | 如:春节,元宵节,龙抬头,清明节,端午节,七夕节,中元节,中秋节,重阳节,冬至,腊八节,小年等 | |||
festivals_gl | 公历节日 | 如:元旦,情人节,妇女节,植树节,消费者日,愚人节,劳动节,护士节,儿童节,禁毒日,建党节,建党节,教师节,国庆节,万圣节,平安夜,圣诞节等,还有日期不固定的父亲节及母亲节 | |||
to_today | 距离今日 | 已过去19天 |
<?php
header('Content-Type:text/html;charset=utf-8');
date_default_timezone_set('PRC');
class apidemo
{
public $apipath='api.djapi.cn/wannianli/get';
public $params;
public function __construct($params){
$this->params=http_build_query($params);
return $this->get();
}
public function get($post_array)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->apipath);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
$post_array = array(
'date' => '20180215'
'cn_to_unicode' => '1'
'token' => 'XXXXXX'
'datatype' => 'json'
);
$result=new apidemo($post_array);
echo '数据返回如下:'.PHP_EOL;
var_dump($result);
//点睛数据:万年历查询,使用ASP.NET方式调用接口简单示例
using System;
using System.Collections.Generic;
using System.Net.Http;
namespace apidemo
{
public partial class djapi
{
public static string apipath = "http://api.djapi.cn";
public static string get(string date,string cn_to_unicode,string token,string datatype)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(apipath);
var content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("date", date), new KeyValuePair<string, string>("cn_to_unicode", cn_to_unicode), new KeyValuePair<string, string>("token", token), new KeyValuePair<string, string>("datatype", datatype) });
var result = client.PostAsync("/wannianli/get", content).Result;
string resultContent = result.Content.ReadAsStringAsync().Result;
return resultContent;
}
}
public class test{
public static string date = "20180215";
public static string cn_to_unicode = "1";
public static string token = "XXXXXX";
public static string datatype = "json";
static void Main(string[] args)
{
string res = djapi.get(citycode, cityname_ch, cityname_py, ip, jwd, cn_to_unicode, token, datatype);
Console.WriteLine(res);
Console.Read();
}
}
}
#点睛数据:万年历查询,使用Python方式调用接口简单示例
import http.client,urllib.parse
class apidemo:
apipath="api.djapi.cn"
apiuri="/wannianli/get";
def get(self,paramslist):
params = urllib.parse.urlencode(paramslist)
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn = http.client.HTTPConnection(self.apipath)
conn.request('POST', self.apiuri, params, headers)
response = conn.getresponse()
return response.read()
date = "20180215"
cn_to_unicode = "1"
token = "XXXXXX"
datatype = "json"
data = apidemo.get(apidemo,{"date" = date,"cn_to_unicode" = cn_to_unicode,"token" = token,"datatype" = datatype})
print(data)
/**
*点睛数据:万年历查询,使用JAVA方式调用接口简单示例
* @author 点睛数据
* djapi.cn
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class apidemo {
public static final String date = "20180215";
public static final String cn_to_unicode = "1";
public static final String token = "XXXXXX";
public static final String datatype = "json";
public static void main(String[] args) {
try {
URL url = new URL("http://api.djapi.cn/ipaddr/get");
HttpURLConnection connect = (HttpURLConnection)url.openConnection();
connect.addRequestProperty("encoding","UTF-8");
connect.setDoInput(true);
connect.setDoOutput(true);
connect.setRequestMethod("GET");//POST or GET
OutputStream output = connect.getOutputStream();
OutputStreamWriter outputstreamreader = new OutputStreamWriter(output);
BufferedWriter writer = new BufferedWriter(outputstreamreader);
// 发送 请求
String params="&date="+date+"&cn_to_unicode="+cn_to_unicode+"&token="+token+"datatype="+datatype;
writer.write(params);
// 强制清空缓冲区 输出数据
writer.flush();
// 设置好 输入流 -- 因为 只有发送数据之后才会有接收数据
InputStream inputstream = connect.getInputStream();
InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
BufferedReader bufferreader = new BufferedReader(inputstreamreader);
// 上述步骤将数据封装好之后 即可将数据读取出来了
String outputstring;
StringBuilder strbuilder = new StringBuilder();
while((outputstring=bufferreader.readLine())!= null){
strbuilder.append(outputstring);
}
writer.close();
bufferreader.close();
output.close();
outputstreamreader.close();
inputstream.close();
inputstreamreader.close();
System.out.println(strbuilder);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
//点睛数据:万年历查询,使用极简方式调用接口示例
//直接使用浏览器直接打开如下链接:
api.djapi.cn/wannianli/get?date=20180215&cn_to_unicode=1&token=XXXXXX&datatype=json
//结果直接在浏览器中输出