八字精批API是根据个人出生信息(包括姓名、性别、出生年、月、日和时)进行命理分析的重要工具。在中国传统文化中,八字命理被广泛应用于个人命运、性格分析以及未来发展的预测。便捷工具https://wzapi.com/bzjp/
接口地址: https://wzapi.com/api/bzjp
返回格式: JSON
请求方式: GET
请求示例: https://wzapi.com/api/bzjp?xing=王&ming=小虎&sex=女&year=2024&month=12&day=13&hour=9
| 名称 | 必填 | 类型 | 说明 |
|---|---|---|---|
| 是 | string | 姓氏 | |
| ming | 是 | string | 名字 |
| sex | 是 | string | 性别(男/女) |
| year | 是 | integer | 出生年份 |
| month | 是 | integer | 出生月份 |
| day | 是 | integer | 出生日期 |
| hour | 是 | integer | 出生时辰(0-23小时) |
| 名称 | 类型 | 说明 |
|---|
{
"errcode": 0,
"errmsg": "ok",
"wuxingdafen": {
"same": [
"土"
],
"diff": [
"木",
"水",
"火"
],
"strength_same": "12.5",
"strength_diff": "3.3",
"strength_all": {
"金": "0.0",
"木": "1.4",
"水": "1.4",
"火": "1.4",
"土": "9.8"
},
"glad_use_god": [
"土"
],
"chazhi": 9.2,
"abschazhi": 9.2,
"ruo": "八字偏强,土过旺",
"xishen": "金",
"shiye": "适合从事金融投资、银行保险、珠宝首饰、机械制造、法律咨询、金属加工、汽车销售、电子产品等行业。方位宜选择西方或西北方发展。",
"sanhe": {
"sanhe": [
"猪",
"兔",
"羊"
],
"sanhetu": [
"zhu",
"tu",
"yang"
]
},
"count": {
"金": 0,
"木": 1,
"水": 1,
"火": 1,
"土": 5
},
"wang": "土旺",
"que": "金缺",
"advice": "金气过旺,宜以火克金,水泄金,或从事与火、水相关的行业。性格上要注意不要过于刚硬,多培养温和的一面。",
"nature": "金主义,性格坚毅果断,有正义感,做事有原则,但有时过于刚硬。金旺之人适合从事需要决断力的工作,如法官、军人、金融分析师等。。五行分布:木占13%,水占13%,火占13%,土占63%",
"relationship": "木生火,1个木生1个火;火生土,1个火生5个土;水生木,1个水生1个木;木克土,1个木克5个土;土克水,5个土克1个水;水克火,1个水克1个火",
"career": "适合从事金融投资、银行保险、珠宝首饰、机械制造、法律咨询、金属加工、汽车销售、电子产品等行业。方位宜选择西方或西北方发展。",
"countstr": "木1个,水1个,火1个,土5个"
},
"ra": {
"xing": "王",
"ming": "镓琦",
"year": "2002",
"month": "11",
"days": "26",
"hour": "9",
"zonghe": {
"siji": "秋",
"xingming": {
"xing": "王",
"ming": "镓琦"
},
"sex": "男",
"shengxiao": "马",
"nianling": 23,
"nongli": {
"nlnian": "二〇〇二",
"nlyue": "秋",
"nlri": "二十六",
"shichen": "辰"
},
"bazi": [
"壬",
"午",
"甲",
"戌",
"己",
"丑",
"戊",
"辰"
],
"wuxing": [
"水",
"木",
"土",
"土"
]
},
"info": {
"jmsh": {
"金": 0,
"木": 1,
"水": 1,
"火": 1,
"土": 5
},
"wharr": {
"wang": "土旺",
"que": "金缺"
},
"tywh": {
"wh": "金",
"tnwh": "土",
"ynwh": "木水火",
"skzhyj": "五行生克制化宜忌:金气过旺,宜以火克金,水泄金,或从事与火、水相关的行业。性格上要注意不要过于刚硬,多培养温和的一面。",
"whzx": "五行之性:金主义,性格坚毅果断,有正义感,做事有原则,但有时过于刚硬。金旺之人适合从事需要决断力的工作,如法官、军人、金融分析师等。。五行分布:木占13%,水占13%,火占13%,土占63%",
"szwh": "四柱五行生克:木生火,1个木生1个火;火生土,1个火生5个土;水生木,1个水生1个木;木克土,1个木克5个土;土克水,5个土克1个水;水克火,1个水克1个火",
"hyhw": "宜从事行业与方位:适合从事金融投资、银行保险、珠宝首饰、机械制造、法律咨询、金属加工、汽车销售、电子产品等行业。方位宜选择西方或西北方发展。"
},
"nayin": [
{
"id": 1,
"jiazi": "壬午",
"layin": "杨柳木"
}
],
"sxgx": {
"sxgx": "热情奔放,自由不羁,有冒险精神",
"id": 7,
"sx": "马"
}
},
"countstr": "木1个,水1个,火1个,土5个",
"sex": "男",
"rgxx": {
"id": 1,
"rgz": "己丑",
"rgxx": "日干心性综合分析:己土日主,性格温和包容,有耐心,善于协调,但有时过于迁就。己土如田园之土,肥沃而滋养万物,性格仁慈而富有爱心。",
"rgcz": "日干层次:己土层次:中等层次,具有包容和耐心,适合从事服务、医疗等需要爱心的工作。",
"rgzfx": "日干综合分析:己土日主综合分析:己土为阴土,代表田园之土,性格温和包容,有耐心。在事业上适合从事服务、医疗、农业等行业。在感情上比较包容,但有时过于迁就。在健康方面要注意脾胃和免疫系统的保养。",
"xgfx": "性格分析:性格特点:温和包容,有耐心,善于协调,但有时过于迁就。适合从事需要爱心的工作,如服务、医疗等。",
"aqfx": "爱情分析:爱情运势:己土日主在感情上比较包容,但有时过于迁就。适合与有主见的伴侣相处,感情和谐但需要学会坚持。",
"syfx": "事业分析:事业发展:己土日主适合从事服务、医疗、农业等行业。具有包容和耐心,事业发展较为和谐,但需要注意主动性。",
"cyfx": "财运分析:财运状况:己土日主财运较为和谐,适合通过服务和医疗获得收入。投资方面适合选择健康类或服务类项目。",
"jkfx": "健康分析:健康状况:己土日主需要注意脾胃和免疫系统的保养。平时应多进行温和运动,保持心情平和,避免过度迁就。"
},
"sjrs": false,
"qtbj": {
"id": 1,
"tg": "己",
"dz": "丑",
"content": "穷通宝鉴分析:穷通宝鉴:己丑组合分析"
}
},
"sxth": {
"id": 1,
"ri": "己丑",
"shi": "戊辰",
"tf1": "三命通会分析1:三命通会:己丑组合特点",
"tf2": "三命通会分析2:三命通会:己丑运势分析"
},
"ml": {
"yml": {
"id": "11",
"siceng": "秋月",
"mingmi": "月日时农历命理分析:十一月出生:性格温和,有直觉力,适合从事医疗心理行业。运势较为温和,但要注意决断力。"
},
"rml": {
"id": "26",
"siceng": "二十六日",
"mingmi": "日命理分析:26日出生:性格特点根据具体日期而定,运势较为平稳,但要注意个人修养。"
},
"sml": {
"id": 5,
"siceng": "辰时",
"mingmi": "时辰命理分析:辰时出生:性格复杂,有协调能力,适合从事需要协调能力的工作。运势较为平稳,但要注意平衡。"
}
}
}
请求参数设置:
| 参数名称 | 参数值 |
|---|---|
{
"errcode": 0,
"errmsg": "ok",
"wuxingdafen": {
"same": [
"土"
],
"diff": [
"木",
"水",
"火"
],
"strength_same": "12.5",
"strength_diff": "3.3",
"strength_all": {
"金": "0.0",
"木": "1.4",
"水": "1.4",
"火": "1.4",
"土": "9.8"
},
"glad_use_god": [
"土"
],
"chazhi": 9.2,
"abschazhi": 9.2,
"ruo": "八字偏强,土过旺",
"xishen": "金",
"shiye": "适合从事金融投资、银行保险、珠宝首饰、机械制造、法律咨询、金属加工、汽车销售、电子产品等行业。方位宜选择西方或西北方发展。",
"sanhe": {
"sanhe": [
"猪",
"兔",
"羊"
],
"sanhetu": [
"zhu",
"tu",
"yang"
]
},
"count": {
"金": 0,
"木": 1,
"水": 1,
"火": 1,
"土": 5
},
"wang": "土旺",
"que": "金缺",
"advice": "金气过旺,宜以火克金,水泄金,或从事与火、水相关的行业。性格上要注意不要过于刚硬,多培养温和的一面。",
"nature": "金主义,性格坚毅果断,有正义感,做事有原则,但有时过于刚硬。金旺之人适合从事需要决断力的工作,如法官、军人、金融分析师等。。五行分布:木占13%,水占13%,火占13%,土占63%",
"relationship": "木生火,1个木生1个火;火生土,1个火生5个土;水生木,1个水生1个木;木克土,1个木克5个土;土克水,5个土克1个水;水克火,1个水克1个火",
"career": "适合从事金融投资、银行保险、珠宝首饰、机械制造、法律咨询、金属加工、汽车销售、电子产品等行业。方位宜选择西方或西北方发展。",
"countstr": "木1个,水1个,火1个,土5个"
},
"ra": {
"xing": "王",
"ming": "镓琦",
"year": "2002",
"month": "11",
"days": "26",
"hour": "9",
"zonghe": {
"siji": "秋",
"xingming": {
"xing": "王",
"ming": "镓琦"
},
"sex": "男",
"shengxiao": "马",
"nianling": 23,
"nongli": {
"nlnian": "二〇〇二",
"nlyue": "秋",
"nlri": "二十六",
"shichen": "辰"
},
"bazi": [
"壬",
"午",
"甲",
"戌",
"己",
"丑",
"戊",
"辰"
],
"wuxing": [
"水",
"木",
"土",
"土"
]
},
"info": {
"jmsh": {
"金": 0,
"木": 1,
"水": 1,
"火": 1,
"土": 5
},
"wharr": {
"wang": "土旺",
"que": "金缺"
},
"tywh": {
"wh": "金",
"tnwh": "土",
"ynwh": "木水火",
"skzhyj": "五行生克制化宜忌:金气过旺,宜以火克金,水泄金,或从事与火、水相关的行业。性格上要注意不要过于刚硬,多培养温和的一面。",
"whzx": "五行之性:金主义,性格坚毅果断,有正义感,做事有原则,但有时过于刚硬。金旺之人适合从事需要决断力的工作,如法官、军人、金融分析师等。。五行分布:木占13%,水占13%,火占13%,土占63%",
"szwh": "四柱五行生克:木生火,1个木生1个火;火生土,1个火生5个土;水生木,1个水生1个木;木克土,1个木克5个土;土克水,5个土克1个水;水克火,1个水克1个火",
"hyhw": "宜从事行业与方位:适合从事金融投资、银行保险、珠宝首饰、机械制造、法律咨询、金属加工、汽车销售、电子产品等行业。方位宜选择西方或西北方发展。"
},
"nayin": [
{
"id": 1,
"jiazi": "壬午",
"layin": "杨柳木"
}
],
"sxgx": {
"sxgx": "热情奔放,自由不羁,有冒险精神",
"id": 7,
"sx": "马"
}
},
"countstr": "木1个,水1个,火1个,土5个",
"sex": "男",
"rgxx": {
"id": 1,
"rgz": "己丑",
"rgxx": "日干心性综合分析:己土日主,性格温和包容,有耐心,善于协调,但有时过于迁就。己土如田园之土,肥沃而滋养万物,性格仁慈而富有爱心。",
"rgcz": "日干层次:己土层次:中等层次,具有包容和耐心,适合从事服务、医疗等需要爱心的工作。",
"rgzfx": "日干综合分析:己土日主综合分析:己土为阴土,代表田园之土,性格温和包容,有耐心。在事业上适合从事服务、医疗、农业等行业。在感情上比较包容,但有时过于迁就。在健康方面要注意脾胃和免疫系统的保养。",
"xgfx": "性格分析:性格特点:温和包容,有耐心,善于协调,但有时过于迁就。适合从事需要爱心的工作,如服务、医疗等。",
"aqfx": "爱情分析:爱情运势:己土日主在感情上比较包容,但有时过于迁就。适合与有主见的伴侣相处,感情和谐但需要学会坚持。",
"syfx": "事业分析:事业发展:己土日主适合从事服务、医疗、农业等行业。具有包容和耐心,事业发展较为和谐,但需要注意主动性。",
"cyfx": "财运分析:财运状况:己土日主财运较为和谐,适合通过服务和医疗获得收入。投资方面适合选择健康类或服务类项目。",
"jkfx": "健康分析:健康状况:己土日主需要注意脾胃和免疫系统的保养。平时应多进行温和运动,保持心情平和,避免过度迁就。"
},
"sjrs": false,
"qtbj": {
"id": 1,
"tg": "己",
"dz": "丑",
"content": "穷通宝鉴分析:穷通宝鉴:己丑组合分析"
}
},
"sxth": {
"id": 1,
"ri": "己丑",
"shi": "戊辰",
"tf1": "三命通会分析1:三命通会:己丑组合特点",
"tf2": "三命通会分析2:三命通会:己丑运势分析"
},
"ml": {
"yml": {
"id": "11",
"siceng": "秋月",
"mingmi": "月日时农历命理分析:十一月出生:性格温和,有直觉力,适合从事医疗心理行业。运势较为温和,但要注意决断力。"
},
"rml": {
"id": "26",
"siceng": "二十六日",
"mingmi": "日命理分析:26日出生:性格特点根据具体日期而定,运势较为平稳,但要注意个人修养。"
},
"sml": {
"id": 5,
"siceng": "辰时",
"mingmi": "时辰命理分析:辰时出生:性格复杂,有协调能力,适合从事需要协调能力的工作。运势较为平稳,但要注意平衡。"
}
}
}
| 名称 | 类型 | 说明 |
|---|
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>八字精批 - 万站API | 专业命理分析平台</title>
<meta name="description" content="八字精批API,专业命理分析,提供详细的五行分析、性格分析、事业运势等全方位命理服务。">
<meta name="keywords" content="八字精批,命理分析,五行分析,生辰八字,算命">
<!-- Stylesheets -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui@2.8.18/dist/css/layui.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<style>
/* Critical CSS - Above the fold styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #f0f2f5;
color: #333;
min-height: 100vh;
position: relative;
overflow-x: hidden;
/* 性能优化 */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
}
body::before {
content: '';
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background:
radial-gradient(circle at 20% 80%, rgba(255, 193, 7, 0.1) 0%, transparent 50%),
radial-gradient(circle at 80% 20%, rgba(220, 53, 69, 0.1) 0%, transparent 50%),
radial-gradient(circle at 40% 40%, rgba(25, 135, 84, 0.1) 0%, transparent 50%);
z-index: -1;
}
.main-container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
}
.glass-container {
background: rgba(255, 255, 255, 0.25);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.18);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
width: 100%;
max-width: 600px;
padding: 40px;
position: relative;
overflow: hidden;
/* 性能优化 */
will-change: transform;
transform: translateZ(0);
contain: layout style paint;
}
.glass-container::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
transition: left 0.5s;
}
.glass-container:hover::before {
left: 100%;
}
.header {
text-align: center;
margin-bottom: 30px;
}
.title {
font-size: 28px;
font-weight: 600;
color: #2c3e50;
margin-bottom: 8px;
letter-spacing: -0.5px;
}
.subtitle {
color: #7f8c8d;
font-size: 14px;
font-weight: 400;
}
.form-container {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
padding: 30px;
margin: 20px 0;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
color: #2c3e50;
font-size: 14px;
font-weight: 500;
margin-bottom: 8px;
}
.form-group input,
.form-group select {
width: 100%;
height: 38px;
padding: 0 10px;
border: 1px solid #e6e6e6;
background-color: #fff;
border-radius: 2px;
color: #333;
font-size: 14px;
transition: border-color 0.2s ease;
}
.form-group input:focus,
.form-group select:focus {
outline: none;
border-color: #1E9FFF;
}
.form-row {
display: flex;
gap: 15px;
}
.form-row .form-group {
flex: 1;
}
.submit-btn {
width: 100%;
height: 40px;
background-color: #1E9FFF;
border: none;
color: white;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
position: relative;
border-radius: 2px;
display: flex;
align-items: center;
justify-content: center;
}
.submit-btn:hover {
background-color: #009688;
}
.submit-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.result-area {
margin-top: 30px;
padding: 25px;
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 12px;
display: none;
}
.result-area.show {
display: block;
animation: fadeInUp 0.5s ease-out;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.result-header {
text-align: center;
margin-bottom: 25px;
padding-bottom: 15px;
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
.result-title {
font-size: 20px;
font-weight: 600;
color: #2c3e50;
margin-bottom: 8px;
}
.result-subtitle {
color: #7f8c8d;
font-size: 14px;
}
.result-section {
margin-bottom: 25px;
padding: 20px;
background: rgba(255, 255, 255, 0.1);
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.15);
}
.section-title {
font-size: 16px;
font-weight: 600;
color: #2c3e50;
margin-bottom: 15px;
display: flex;
align-items: center;
}
.section-title i {
margin-right: 8px;
color: #667eea;
}
.wuxing-grid {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 10px;
margin-bottom: 15px;
}
.wuxing-item {
text-align: center;
padding: 15px 10px;
background: rgba(255, 255, 255, 0.1);
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.wuxing-item.wang {
background: rgba(220, 53, 69, 0.2);
border-color: rgba(220, 53, 69, 0.4);
}
.wuxing-item.que {
background: rgba(108, 117, 125, 0.2);
border-color: rgba(108, 117, 125, 0.4);
}
.wuxing-name {
font-size: 18px;
font-weight: 600;
margin-bottom: 5px;
}
.wuxing-count {
font-size: 14px;
color: #7f8c8d;
}
.analysis-text {
color: #2c3e50;
line-height: 1.6;
font-size: 14px;
}
.bazi-display {
display: flex;
justify-content: center;
gap: 15px;
margin-bottom: 20px;
}
.bazi-item {
text-align: center;
padding: 15px;
background: rgba(255, 255, 255, 0.1);
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.2);
min-width: 60px;
}
.bazi-label {
font-size: 12px;
color: #7f8c8d;
margin-bottom: 5px;
}
.bazi-value {
font-size: 18px;
font-weight: 600;
color: #2c3e50;
}
.loading {
text-align: center;
padding: 40px;
}
.loading i {
font-size: 32px;
color: #667eea;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.error-message {
background: rgba(220, 53, 69, 0.1);
border: 1px solid rgba(220, 53, 69, 0.3);
color: #dc3545;
padding: 15px;
border-radius: 8px;
text-align: center;
}
.success-message {
background: rgba(25, 135, 84, 0.1);
border: 1px solid rgba(25, 135, 84, 0.3);
color: #198754;
padding: 15px;
border-radius: 8px;
text-align: center;
}
/* 响应式设计 */
@media (max-width: 768px) {
.main-container {
padding: 10px;
}
.glass-container {
padding: 20px;
max-width: 100%;
}
.form-row {
flex-direction: column;
gap: 0;
}
.wuxing-grid {
grid-template-columns: repeat(3, 1fr);
}
.bazi-display {
flex-wrap: wrap;
gap: 10px;
}
.bazi-item {
min-width: 50px;
padding: 10px;
}
}
@media (max-width: 480px) {
.title {
font-size: 24px;
}
.wuxing-grid {
grid-template-columns: repeat(2, 1fr);
}
}
</style>
</head>
<body>
<div class="main-container">
<div class="glass-container">
<div class="header">
<h1 class="title">
<i class="fas fa-yin-yang" style="color: #667eea; margin-right: 10px;"></i>
八字精批
</h1>
<p class="subtitle">专业命理分析 · 深度解读人生</p>
</div>
<div class="form-container">
<form id="baziForm">
<div class="form-row">
<div class="form-group">
<label for="xing">姓氏</label>
<input type="text" id="xing" name="xing" placeholder="请输入姓氏" required>
</div>
<div class="form-group">
<label for="ming">名字</label>
<input type="text" id="ming" name="ming" placeholder="请输入名字" required>
</div>
</div>
<div class="form-group">
<label for="sex">性别</label>
<select id="sex" name="sex" required>
<option value="">请选择性别</option>
<option value="男">男</option>
<option value="女">女</option>
</select>
</div>
<div class="form-row">
<div class="form-group">
<label for="year">出生年份</label>
<input type="number" id="year" name="year" placeholder="如:1990" min="1900" max="2100" required>
</div>
<div class="form-group">
<label for="month">出生月份</label>
<input type="number" id="month" name="month" placeholder="如:12" min="1" max="12" required>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="day">出生日期</label>
<input type="number" id="day" name="day" placeholder="如:13" min="1" max="31" required>
</div>
<div class="form-group">
<label for="hour">出生时辰</label>
<select id="hour" name="hour" required>
<option value="">请选择时辰</option>
<option value="0">子时 (23:00-01:00)</option>
<option value="1">丑时 (01:00-03:00)</option>
<option value="2">寅时 (03:00-05:00)</option>
<option value="3">卯时 (05:00-07:00)</option>
<option value="4">辰时 (07:00-09:00)</option>
<option value="5">巳时 (09:00-11:00)</option>
<option value="6">午时 (11:00-13:00)</option>
<option value="7">未时 (13:00-15:00)</option>
<option value="8">申时 (15:00-17:00)</option>
<option value="9">酉时 (17:00-19:00)</option>
<option value="10">戌时 (19:00-21:00)</option>
<option value="11">亥时 (21:00-23:00)</option>
</select>
</div>
</div>
<button type="submit" class="submit-btn">
<i class="fas fa-search" style="margin-right: 8px;"></i>
开始分析
</button>
</form>
</div>
<div class="result-area" id="resultArea">
<div class="loading" id="loading">
<i class="fas fa-spinner"></i>
<p style="margin-top: 15px; color: #7f8c8d;">正在分析您的八字...</p>
</div>
<div class="result-content" id="resultContent" style="display: none;">
<!-- 结果内容将在这里动态生成 -->
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/layui@2.8.18/dist/layui.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('baziForm');
const resultArea = document.getElementById('resultArea');
const loading = document.getElementById('loading');
const resultContent = document.getElementById('resultContent');
form.addEventListener('submit', async function(e) {
e.preventDefault();
const formData = new FormData(form);
const params = new URLSearchParams();
for (let [key, value] of formData.entries()) {
params.append(key, value);
}
// 显示结果区域和加载状态
resultArea.classList.add('show');
loading.style.display = 'block';
resultContent.style.display = 'none';
try {
// 添加请求超时和错误处理
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10秒超时
const response = await fetch(`https://wzapi.com/api/bzjp?${params.toString()}`, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
signal: controller.signal
});
clearTimeout(timeoutId);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log('API Response:', data); // 调试日志
if (data.errcode === 0) {
displayResult(data);
} else {
showError(data.errmsg || '分析失败,请重试');
}
} catch (error) {
console.error('Error:', error);
if (error.name === 'AbortError') {
showError('请求超时,请重试');
} else if (error.message.includes('Failed to fetch')) {
showError('网络连接失败,请检查网络后重试');
} else {
showError('请求失败:' + error.message);
}
}
});
function displayResult(data) {
loading.style.display = 'none';
resultContent.style.display = 'block';
// 调试:输出完整数据结构
console.log('Complete API Response:', data);
console.log('ra object:', data.ra);
console.log('rgxx object:', data.ra?.rgxx || data.rgxx);
const wuxing = data.wuxingdafen;
const ra = data.ra;
const rgxx = data.ra.rgxx || data.rgxx; // 兼容两种数据结构
let html = `
<div class="result-header">
<h2 class="result-title">${ra?.xing || ''}${ra?.ming || ''} 的八字分析</h2>
<p class="result-subtitle">${ra?.zonghe?.shengxiao || ''}年${ra?.zonghe?.nongli?.nlyue || ''}月${ra?.zonghe?.nongli?.nlri || ''}日${ra?.zonghe?.nongli?.shichen || ''}时</p>
</div>
<div class="result-section">
<h3 class="section-title">
<i class="fas fa-calendar-alt"></i>
八字信息
</h3>
<div class="bazi-display">
<div class="bazi-item">
<div class="bazi-label">年柱</div>
<div class="bazi-value">${ra?.zonghe?.bazi?.[0] || ''}${ra?.zonghe?.bazi?.[1] || ''}</div>
</div>
<div class="bazi-item">
<div class="bazi-label">月柱</div>
<div class="bazi-value">${ra?.zonghe?.bazi?.[2] || ''}${ra?.zonghe?.bazi?.[3] || ''}</div>
</div>
<div class="bazi-item">
<div class="bazi-label">日柱</div>
<div class="bazi-value">${ra?.zonghe?.bazi?.[4] || ''}${ra?.zonghe?.bazi?.[5] || ''}</div>
</div>
<div class="bazi-item">
<div class="bazi-label">时柱</div>
<div class="bazi-value">${ra?.zonghe?.bazi?.[6] || ''}${ra?.zonghe?.bazi?.[7] || ''}</div>
</div>
</div>
</div>
<div class="result-section">
<h3 class="section-title">
<i class="fas fa-yin-yang"></i>
五行分析
</h3>
<div class="wuxing-grid">
<div class="wuxing-item ${wuxing?.count?.金 === 0 ? 'que' : ''}">
<div class="wuxing-name" style="color: #FFD700;">金</div>
<div class="wuxing-count">${wuxing?.count?.金 || 0}个</div>
</div>
<div class="wuxing-item ${wuxing?.count?.木 > 2 ? 'wang' : ''}">
<div class="wuxing-name" style="color: #228B22;">木</div>
<div class="wuxing-count">${wuxing?.count?.木 || 0}个</div>
</div>
<div class="wuxing-item ${wuxing?.count?.水 > 2 ? 'wang' : ''}">
<div class="wuxing-name" style="color: #4169E1;">水</div>
<div class="wuxing-count">${wuxing?.count?.水 || 0}个</div>
</div>
<div class="wuxing-item ${wuxing?.count?.火 > 2 ? 'wang' : ''}">
<div class="wuxing-name" style="color: #FF4500;">火</div>
<div class="wuxing-count">${wuxing?.count?.火 || 0}个</div>
</div>
<div class="wuxing-item ${wuxing?.count?.土 > 2 ? 'wang' : ''}">
<div class="wuxing-name" style="color: #8B4513;">土</div>
<div class="wuxing-count">${wuxing?.count?.土 || 0}个</div>
</div>
</div>
<div class="analysis-text">
<p><strong>五行状况:</strong>${wuxing?.ruo || '数据暂不可用'}</p>
<p><strong>喜用神:</strong>${wuxing?.xishen || '数据暂不可用'}</p>
<p><strong>建议:</strong>${wuxing?.advice || '数据暂不可用'}</p>
</div>
</div>
<div class="result-section">
<h3 class="section-title">
<i class="fas fa-user"></i>
性格分析
</h3>
<div class="analysis-text">
<p>${rgxx?.xgfx || '性格分析数据暂不可用'}</p>
</div>
</div>
<div class="result-section">
<h3 class="section-title">
<i class="fas fa-briefcase"></i>
事业分析
</h3>
<div class="analysis-text">
<p>${rgxx?.syfx || '事业分析数据暂不可用'}</p>
<p><strong>职业建议:</strong>${wuxing?.shiye || '职业建议数据暂不可用'}</p>
</div>
</div>
<div class="result-section">
<h3 class="section-title">
<i class="fas fa-heart"></i>
感情分析
</h3>
<div class="analysis-text">
<p>${rgxx?.aqfx || '感情分析数据暂不可用'}</p>
</div>
</div>
<div class="result-section">
<h3 class="section-title">
<i class="fas fa-coins"></i>
财运分析
</h3>
<div class="analysis-text">
<p>${rgxx?.cyfx || '财运分析数据暂不可用'}</p>
</div>
</div>
<div class="result-section">
<h3 class="section-title">
<i class="fas fa-heartbeat"></i>
健康分析
</h3>
<div class="analysis-text">
<p>${rgxx?.jkfx || '健康分析数据暂不可用'}</p>
</div>
</div>
`;
resultContent.innerHTML = html;
}
function showError(message) {
loading.style.display = 'none';
resultContent.style.display = 'block';
resultContent.innerHTML = `
<div class="error-message">
<i class="fas fa-exclamation-triangle" style="margin-right: 8px;"></i>
${message}
</div>
`;
}
});
</script>
</body>
</html>