How to query the old almanac in php
Query method: 1. Open the old almanac interface service and obtain the calling voucher request key of the interface; 2. Call the interface API to make a request, process the data and return the result; 3. Use "$response=juheHttpRequest($apiUrl , $paramsString,1);" Get the content returned by the interface; 4. Use "$result=json_decode($response,true);" to parse the returned content into an array; 5. Print the parsed content.
The operating environment of this tutorial: windows7 system, PHP8.1 version, DELL G3 computer
old PHP-based Almanac interface call example
Preliminary preparation
- ##Through
https://www.juhe.cn/ docs/api/id/65?s=cpphpcn
Self-service application for opening the interface
- Get the calling credential request key of the interface
- You You can see the calling credential request key of this interface in Personal Center ➡️ Data Center ➡️ My API Module
Interface Description
- Free to use, depending on the membership level, the number of calls per day is different. Please log in to the official website of the aggregated data to view it
- Provides old almanac query, almanac daily good and bad luck query
- For more detailed interface usage information, please log in to the official website of Aggregation Data. This article is a simple usage example for reference only
1. Old Almanac - Calendar interface:
Request parametersRequired | Type | Description | |
---|---|---|---|
is | String | in the personal center-> My data, view | |
above the interface name is | String | date, format 2020-11-20 |
<?php //请求的接口URL $apiUrl = 'http://v.juhe.cn/laohuangli/d'; //请求参数 $params = [ //聚合数据上申请的接口调用key 'key' => '聚合数据上申请的接口调用key', //要查询的日期 'date' => '要查询的日期' ]; //参数数组转换成字符串 $paramsString = http_build_query($params); //发起接口网络请求 $response = null; try { $response = juheHttpRequest($apiUrl, $paramsString, 1); } catch (Exception $e) { var_dump($e); //此处根据自己的需求进行具体的异常处理 } if (!$response) { echo '请求异常' . PHP_EOL; } //接收接口返回内容 $result = json_decode($response, true);//获取接口返回内容(json字符串),并解析成数组 if (!$result) { echo '请求异常' . PHP_EOL; } $errorCode = $result['error_code']; if ($errorCode == 0) { $data = $result['result']; } else { echo "请求异常:{$errorCode}_{$result['reason']}" . PHP_EOL; } //打印接口返回结果 var_dump($result); /** * 发起网络请求函数 * @param String $url 请求的URL * @param bool $params 请求的参数内容 * @param int $isPost 是否POST请求 * @return bool|string 返回内容 */ function juheHttpRequest($url, $params = false, $isPost = 0) { $httpInfo = []; $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_TIMEOUT, 12); 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); } } $reponse = curl_exec($ch); if ($reponse === FALSE) { // echo "cURL Error: ".curl_error($ch); return false; } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $httpInfo = array_merge($httpInfo, curl_getinfo($ch)); curl_close($ch); return $reponse; }
array(3) { ["reason"]=> string(9) "successed" ["result"]=> array(10) { ["id"]=> string(4) "3850" ["yangli"]=> string(10) "2020-11-20" ["yinli"]=> string(26) "庚子(鼠)年十月初六" ["wuxing"]=> string(19) "炉中火 定执位" ["chongsha"]=> string(20) "冲鸡(辛酉)煞西" ["baiji"]=> string(49) "丁不剃头头必生疮 卯不穿井水泉不香" ["jishen"]=> string(44) "阴德 民日 三合 时阴 五合 鸣犬对" ["yi"]=> string(145) "祭祀 祈福 订盟 纳采 裁衣 拆卸 修造 动土 起基 安床 移徙 入宅 安香 入殓 移柩 安葬 谢土 赴任 进人口 会亲友" ["xiongshen"]=> string(6) "元武" ["ji"]=> string(13) "作灶 治病" } ["error_code"]=> int(0) }
2. Old almanac - time interface:
Request parametersRequired | Type | Description | |
---|---|---|---|
is | String | View in Personal Center->My Data, above the interface name | |
is the | String | date, format 2020-11-20 |
<?php //请求的接口URL $apiUrl = 'http://v.juhe.cn/laohuangli/h'; //请求参数 $params = [ //聚合数据上申请的接口调用key 'key' => '聚合数据上申请的接口调用key', //要查询的日期 'date' => '要查询的日期' ]; //参数数组转换成字符串 $paramsString = http_build_query($params); //发起接口网络请求 $response = null; try { $response = juheHttpRequest($apiUrl, $paramsString, 1); } catch (Exception $e) { var_dump($e); //此处根据自己的需求进行具体的异常处理 } if (!$response) { echo '请求异常' . PHP_EOL; } //接收接口返回内容 $result = json_decode($response, true); if (!$result) { echo '请求异常' . PHP_EOL; } $errorCode = $result['error_code']; if ($errorCode == 0) { $data = $result['result']; } else { echo "请求异常:{$errorCode}_{$result['reason']}" . PHP_EOL; } //打印接口返回结果 var_dump($result); /** * 发起网络请求函数 * @param String $url 请求的URL * @param bool $params 请求的参数内容 * @param int $isPost 是否POST请求 * @return bool|string 返回内容 */ function juheHttpRequest($url, $params = false, $isPost = 0) { $httpInfo = []; $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_TIMEOUT, 12); 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); } } $reponse = curl_exec($ch); if ($reponse === FALSE) { // echo "cURL Error: ".curl_error($ch); return false; } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $httpInfo = array_merge($httpInfo, curl_getinfo($ch)); curl_close($ch); return $reponse; }
array(3) { ["reason"]=> string(9) "successed" ["result"]=> array(12) { [0]=> array(5) { ["yangli"]=> string(10) "2020-11-20" ["hours"]=> string(3) "1-3" ["des"]=> string(54) "冲猴 煞北 时冲丙申 路空 大退 青龙 国印" ["yi"]=> string(20) "赴任 出行 修造" ["ji"]=> string(80) " 见贵 求财 嫁娶 进人口 移徙 安葬 祭祀 祈福 求嗣 斋醮 订婚" } [1]=> array(5) { ["yangli"]=> string(10) "2020-11-20" ["hours"]=> string(3) "3-5" ["des"]=> string(54) "冲猪 煞东 时冲己亥 朱雀 帝旺 进禄 驿马" ["yi"]=> string(41) "祭祀 祈福 斋醮 开光 赴任 出行" ["ji"]=> string(63) " 订婚 嫁娶 安床 移徙 入宅 修造 安葬 求财 见贵" } [2]=> array(5) { ["yangli"]=> string(10) "2020-11-20" ["hours"]=> string(3) "5-7" ["des"]=> string(54) "冲狗 煞南 时冲戊戍 不遇 天刑 日害 武曲" ["yi"]=> string(34) "作灶 祭祀 祈福 斋醮 酬神" ["ji"]=> string(28) " 赴任 出行 修造 动土" } [3]=> array(5) { ["yangli"]=> string(10) "2020-11-20" ["hours"]=> string(3) "7-9" ["des"]=> string(47) "冲马 煞南 时冲甲午 日刑 地兵 司命" ["yi"]=> string(0) "" ["ji"]=> string(34) "作灶 祭祀 祈福 斋醮 酬神" } [4]=> array(5) { ["yangli"]=> string(10) "2020-11-20" ["hours"]=> string(4) "9-11" ["des"]=> string(54) "冲羊 煞东 时冲乙未 勾陈 唐符 武曲 水星" ["yi"]=> string(0) "" ["ji"]=> string(69) "修造 盖屋 移徙 作灶 安床 入宅 开市 求嗣 订婚 嫁娶" } [5]=> array(5) { ["yangli"]=> string(10) "2020-11-20" ["hours"]=> string(5) "11-13" ["des"]=> string(55) " 冲鼠 煞北 时冲庚子 地兵 喜神 日禄 金匮" ["yi"]=> string(69) "祈福 求嗣 订婚 嫁娶 出行 求财 开市 交易 安床 赴任" ["ji"]=> string(13) "修造 动土" } [6]=> array(5) { ["yangli"]=> string(10) "2020-11-20" ["hours"]=> string(5) "13-15" ["des"]=> string(55) " 冲牛 煞西 时冲辛丑 三合 天赦 天德 宝光" ["yi"]=> string(90) "祈福 求嗣 订婚 嫁娶 出行 求财 开市 交易 安床 修造 入宅 安葬 祭祀" ["ji"]=> string(1) "-" } [7]=> array(5) { ["yangli"]=> string(10) "2020-11-20" ["hours"]=> string(5) "15-17" ["des"]=> string(55) " 冲虎 煞南 时冲壬寅 六戊 白虎 太阳 功曹" ["yi"]=> string(41) "入宅 修造 安葬 祭祀 斋醮 酬神" ["ji"]=> string(59) "祈福 求嗣 白虎须用 麒麟符制 否则 诸事不宜" } [8]=> array(5) { ["yangli"]=> string(10) "2020-11-20" ["hours"]=> string(5) "17-19" ["des"]=> string(34) " 冲兔 煞东 时冲癸卯 日破" ["yi"]=> string(1) "-" ["ji"]=> string(25) "日时相冲 诸事不宜" } [9]=> array(5) { ["yangli"]=> string(10) "2020-11-20" ["hours"]=> string(5) "19-21" ["des"]=> string(55) " 冲龙 煞北 时冲甲辰 天牢 地兵 六合 右弼" ["yi"]=> string(62) "祈福 求嗣 订婚 嫁娶 求财 开市 交易 安床 见贵" ["ji"]=> string(34) "赴任 修造 移徙 出行 词讼" } [10]=> array(5) { ["yangli"]=> string(10) "2020-11-20" ["hours"]=> string(5) "21-23" ["des"]=> string(55) " 冲蛇 煞西 时冲乙已 元武 三合 贵人 左辅" ["yi"]=> string(69) "祈福 求嗣 订婚 嫁娶 求财 开市 交易 安床 祭祀 见贵" ["ji"]=> string(27) "赴任 出行 修造 动土" } [11]=> array(5) { ["yangli"]=> string(10) "2020-11-20" ["hours"]=> string(4) "23-1" ["des"]=> string(54) "冲鸡 煞西 时冲丁酉 路空 明堂 进贵 木星" ["yi"]=> string(97) "求嗣 嫁娶 移徙 入宅 开市 交易 修造 安葬 祈福 订婚 赴任 出行 见贵 求财" ["ji"]=> string(46) " 朱雀须用 凤凰符制 否则 诸事不宜" } } ["error_code"]=> int(0) }
PHP Video Tutorial"
The above is the detailed content of How to query the old almanac in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
