生肖查询
请求Header:
| 名称 | 值 | |
|---|---|---|
| Content-Type | application/x-www-form-urlencoded |
请求参数说明:
| 名称 | 必填 | 类型 | 说明 | |
|---|---|---|---|---|
| keyword | 是 | string | 查询日期或生肖名称:如1900~2079 或 鼠、牛 | |
| key | 是 | string | 在个人中心->我的数据,接口名称上方查看 |
请求代码示例:
curl -k -i "https://apis.juhe.cn/fapig/zodiac/query?key=key&keyword=xxx"
<?php
/**
* 1577-生肖查询 - 代码参考(根据实际业务情况修改)
*/
// 基本参数配置
$apiUrl = "https://apis.juhe.cn/fapig/zodiac/query"; // 接口请求URL
$method = "GET"; // 接口请求方式
$headers = ["Content-Type: application/x-www-form-urlencoded"]; // 接口请求header
$apiKey = "您申请的调用APIkey"; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
$requestParams = [
'key' => $apiKey,
'keyword'=> 'xxx',
];
$requestParamsStr = http_build_query($requestParams);
// 发起接口网络请求
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $apiUrl . '?' . $requestParamsStr);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if (1 == strpos("$" . $apiUrl, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$response = curl_exec($curl);
$httpInfo = curl_getinfo($curl);
curl_close($curl);
// 解析响应结果
$responseResult = json_decode($response, true);
if ($responseResult) {
// 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
var_dump($responseResult);
} else {
// 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
// var_dump($httpInfo);
var_dump("请求异常");
}
import requests
# 1577-生肖查询 - 代码参考(根据实际业务情况修改)
# 基本参数配置
apiUrl = 'https://apis.juhe.cn/fapig/zodiac/query' # 接口请求URL
apiKey = '您申请的调用APIkey' # 在个人中心->我的数据,接口名称上方查看
# 接口请求入参配置
requestParams = {
'key': apiKey,
'keyword': 'xxx',
}
# 发起接口网络请求
response = requests.get(apiUrl, params=requestParams)
# 解析响应结果
if response.status_code == 200:
responseResult = response.json()
# 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
print(responseResult)
else:
# 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
print('请求异常')
package main
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)
func main() {
// 基本参数配置
apiUrl := "https://apis.juhe.cn/fapig/zodiac/query"
apiKey := "您申请的调用APIkey"
// 接口请求入参配置
requestParams := url.Values{}
requestParams.Set("key", apiKey)
requestParams.Set("keyword", "xxx")
// 发起接口网络请求
resp, err := http.Get(apiUrl + "?" + requestParams.Encode())
if err != nil {
fmt.Println("网络请求异常:", err)
return
}
defer resp.Body.Close()
var responseResult map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&responseResult)
if err != nil {
fmt.Println("解析响应结果异常:", err)
return
}
fmt.Println(responseResult)
}
using System;
using System.Net;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
namespace Common_API_Test.Test_Demo
{
class Csharp_get
{
static void Main(string[] args)
{
string url = "https://apis.juhe.cn/fapig/zodiac/query";
string apiKey = "您申请的调用APIkey";
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("key", apiKey);
data.Add( "keyword", "xxx");
using (WebClient client = new WebClient())
{
string fullUrl = url + "?" + string.Join("&", data.Select(x => x.Key + "=" + x.Value));
try
{
string responseContent = client.DownloadString(fullUrl);
dynamic responseData = JsonConvert.DeserializeObject(responseContent);
if (responseData != null)
{
Console.WriteLine("Return Code: " + responseData["error_code"]);
Console.WriteLine("Return Message: " + responseData["reason"]);
}
else
{
Console.WriteLine("json解析异常!");
}
}
catch (Exception)
{
Console.WriteLine("请检查其它错误");
}
}
}
}
}
const axios = require('axios'); // npm install axios
// 基本参数配置
const apiUrl = 'https://apis.juhe.cn/fapig/zodiac/query'; // 接口请求URL
const apiKey = '您申请的调用APIkey'; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
const requestParams = {
key: apiKey,
keyword: 'xxx',
};
// 发起接口网络请求
axios.get(apiUrl, {params: requestParams})
.then(response => {
// 解析响应结果
if (response.status === 200) {
const responseResult = response.data;
// 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
console.log(responseResult);
} else {
// 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
console.log('请求异常');
}
})
.catch(error => {
// 网络请求失败,可以根据实际情况进行处理
console.log('网络请求失败:', error);
});
package cn.juhe.test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class JavaGet {
public static void main(String[] args) throws Exception {
String apiKey = "你申请的key";
String apiUrl = "https://apis.juhe.cn/fapig/zodiac/query";
HashMap<String, String> map = new HashMap<>();
map.put("key", apiKey);
map.put("keyword", "xxx");
URL url = new URL(String.format("%s?%s", apiUrl, params(map)));
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response);
}
public static String params(Map<String, String> map) {
return map.entrySet().stream()
.map(entry -> {
try {
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
} catch (Exception e) {
e.printStackTrace();
return entry.getKey() + "=" + entry.getValue();
}
})
.collect(Collectors.joining("&"));
}
}
// 基本参数配置
NSString *apiUrl = @"https://apis.juhe.cn/fapig/zodiac/query"; // 接口请求URL
NSString *apiKey = @"您申请的调用APIkey"; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
NSDictionary *requestParams = @{
@"key": apiKey,
@"keyword": @"xxx",
};
// 发起接口网络请求
NSURLComponents *components = [NSURLComponents componentsWithString:apiUrl];
NSMutableArray *queryItems = [NSMutableArray array];
[requestParams enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
[queryItems addObject:[NSURLQueryItem queryItemWithName:key value:value]];
}];
components.queryItems = queryItems;
NSURL *url = components.URL;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
// 网络请求异常处理
NSLog(@"请求异常");
} else {
NSError *jsonError;
NSDictionary *responseResult = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
if (!jsonError) {
// 网络请求成功处理
// NSLog(@"%@", [responseResult objectForKey:@"error_code"]);
NSLog(@"%@", responseResult);
} else {
// 解析结果异常处理
NSLog(@"解析结果异常");
}
}
}];
[task resume];
返回参数说明:
| 名称 | 类型 | 说明 | |
|---|---|---|---|
| error_code | int | 返回码 | |
| reason | string | 返回说明 | |
| result | string | 返回结果集 | |
| name | string | 生肖名称 | |
| years | string | 生肖年份 | |
| fw | string | 吉祥方位 | |
| sc | string | 吉忌颜色 | |
| sz | string | 吉凶数字 | |
| xyh | string | 幸运花 | |
| ys | string | 总体运势 | |
| sy | string | 事业 | |
| aq | string | 爱情 | |
| xg | string | 性格 | |
| yd | string | 优点 | |
| qd | string | 缺点 | |
| bx | string | 基本表现 | |
| yd | string | 优点 | |
| qd | string | 缺点 | |
| currentAge | - | 出生年份今年年龄 | |
| y | string | 出生年份 | |
| s | string | 实岁 | |
| x | string | 虚岁 |
JSON返回示例:JSON在线格式化工具 >
{
"reason": "SUCCES",
"result": {
"name": "丑牛",
"years": "1901,1913,1925,1937,1949,1961,1973,1985,1997,2009,2021,2033,2045,2057,2069",
"fw": "东南、东北方",
"sc": "吉:蓝、红、紫色;忌:白、绿色",
"sz": "吉:一、九;凶:三、四",
"xyh": "郁金香、万年青、桃花",
"ys": "丑年生人,性诚实,富有忍耐心,对事多固执,乏其交际,女人多信他人甜言以致失败,后悔不入及,应该谨慎之,此人沉默寡言,不被人重用,但内心温和,作事勤勉,活动独立,热心坚实,性向钱财等,早离乡白手成家,少年有福,中年交来多少苦劳与精神的麻烦与苦恼,晚景天禀赐福的荣幸,有婚姻上的麻烦等。",
"sy": "事业发展得心应手,个人的努力和勤奋也大有可为。需要提防的是当心有小人的嫉妒和从中作梗,学会应变求存来克服可能出现的不利因素。",
"aq": "感情丰富而爱憎分明,宜中庸求得平衡。爱情生活中时有风波曲折,特别是女性寄情于外面世界的娱乐,造成家庭中的意见,须克服,情侣间要排除猜疑。<br>大吉婚配:鼠(子)、蛇(已)、鸡(酉)<br>忌婚配:龙(辰)、狗(戌)、羊(午)",
"xg": "肖牛者最大的优点就是责任感强、脚踏实地, 凡事都经过深思熟虑才作决定。其性格正直倔强, 也是个尊重传统的保守主义者。然而,肖牛的人往往比较呆板, 也不会圆滑处理事物,一旦发脾气就将事情搞得不可收拾。",
"yd": "做事谨慎小心,脚踏实地行动缓慢,有稳扎稳打的习性。不轻易受他人或环境的影响,依照自已意念和能力做事。在采取行动之前,早有一番深思熟虑,而且有始有终拥有坚强的信念和强壮的体力。有牛脾气,明辨是非按部就班,事业心强最具耐力。内心有强烈的自我表现欲,故不适合作默默无闻的工作,天生优秀领导人物。女性持家有方,是传统的贤内助,非常重视子女教育。虽然婚姻方面不太协调,却能以旺盛的精力投入事业中成为有成就的企业家。有耐性肯上进,所以能达成自已所设定的目标。温厚老实是终生天性,对国家有强烈的热爱,有理想有抱负,重视工作与家庭,是尊重传统的保守者。",
"qd": "女性较缺乏娇柔,如果能意识到自己的不足,改变一下拘谨冷漠的态度积极表现自已则在感情上亦能称心如意。因任劳任怨加上个性固执不听劝告,时常忘了准特进餐,而有肠问题。如顽石般不知变通且毫无情趣。口才木讷不善交际应酬。为人不太相信别人多执己见,沈默寡言。喜欢我行我素,固执己见,不善沟通。",
"currentAge": [
{
"y": 1901,
"s": 120,
"x": 121
},
{
"y": 1913,
"s": 108,
"x": 109
},
{
"y": 1925,
"s": 96,
"x": 97
},
{
"y": 1937,
"s": 84,
"x": 85
},
{
"y": 1949,
"s": 72,
"x": 73
},
{
"y": 1961,
"s": 60,
"x": 61
},
{
"y": 1973,
"s": 48,
"x": 49
},
{
"y": 1985,
"s": 36,
"x": 37
},
{
"y": 1997,
"s": 24,
"x": 25
},
{
"y": 2009,
"s": 12,
"x": 13
},
{
"y": 2021,
"s": 0,
"x": 1
}
]
},
"error_code": 0
}
服务级错误码参照(error_code):
| 错误码 | 说明 |
|---|
系统级错误码参照:
| 错误码 | 说明 | 旧版本(resultcode) | |
|---|---|---|---|
| 10001 | 错误的请求KEY | 101 | |
| 10002 | 该KEY无请求权限 | 102 | |
| 10003 | KEY过期 | 103 | |
| 10004 | 错误的OPENID | 104 | |
| 10005 | 应用未审核超时,请提交认证 | 105 | |
| 10007 | 未知的请求源 | 107 | |
| 10008 | 被禁止的IP | 108 | |
| 10009 | 被禁止的KEY | 109 | |
| 10011 | 当前IP请求超过限制 | 111 | |
| 10012 | 请求超过次数限制 | 112 | |
| 10013 | 测试KEY超过请求限制 | 113 | |
| 10014 | 系统内部异常(调用充值类业务时,请务必联系客服或通过订单查询接口检测订单,避免造成损失) | 114 | |
| 10020 | 接口维护 | 120 | |
| 10021 | 接口停用 | 121 |
错误码格式说明(示例:200201):
| 2 | 002 | 01 | |
|---|---|---|---|
| 服务级错误(1为系统级错误) | 服务模块代码(即数据ID) | 具体错误代码 |
接口文档下载
苏公网安备 32059002001776号