首页 万年历 万年历示例代码 万年历查询[Nodejs]

万年历查询示例代码Nodejs

作者: 阅读数:1163 上传时间:2025-04-02

万年历查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 1. 安装 axios(如果未安装)
// 在终端执行: npm install axios
 
const axios = require('axios');
 
// 2. 直接配置参数
const url = 'https://api.jisuapi.com/calendar/query';
const params = {
  appkey: 'your_appkey_here', // 替换成你的真实appkey
  islunar: 0,
  islunarmonth: 0
};
 
// 3. 立即发送请求
axios.get(url, { params })
  .then(response => {
    // 检查API业务状态码
    if (response.data.status !== 0) {
      console.error('API返回错误:', response.data.status+"-"+response.data.msg);
      return;
    }
     
    // 输出结果
    // 基本信息
    for (const [key, value] of Object.entries(response.data.result)) {
      if (typeof value !== 'object')
      {
        console.log(`${key}: ${value}`);
      }
    }
 
    // 黄历信息
    for (const [key_hl, value_hl] of Object.entries(response.data.result.huangli)) {
      console.log(`${key_hl}: ${value_hl}`);
    }
  })
  .catch(error => {
    // 统一错误处理
    console.error('请求失败!');
  });