← 回观命

合作方接口 POST /v1/profile

接口版本 v1 · 本页更新于 2026-11-14

开放状态:这是按合作逐个开通的合作方接口,目前不提供自助申请或自助开通 API key。开放进度以站点实际开关为准:接口未对外开放时,除 OPTIONS 外的请求一律回 404。OPTIONS 请求由全站跨域处理直接回 204(无正文),这不表示接口已开放。合作意向请发邮件到 support@guan.life。

这个接口做什么

传入一个人的出生日期、时间、性别、时区(可选经度),返回八字命盘的结构化字段:四柱与十神、地支藏干、五行占比、日主强弱档位、格局、喜忌、大运,以及每个喜用五行对应的属性、行业和方位词条。

请求

POST $API_BASE/v1/profile
Authorization: Bearer $API_KEY
Idempotency-Key: $IDEMPOTENCY_KEY
Content-Type: application/json

{"calendar":"solar","date":"1985-11-03","time":"08:30","gender":"female","timeZone":"Asia/Shanghai","longitude":121.47}

$API_BASE、$API_KEY 都是占位符,开通时单独提供;$IDEMPOTENCY_KEY 由调用方自己生成(见下文「幂等」)。

字段规则
calendar只收 "solar"(公历)。v1 不收农历。
dateYYYY-MM-DD,1900–2100 之间的真实日期。1990-02-30 这类不存在的日期回 400,不会顺延到下个月。
time"HH:MM" 或 null。必须显式给出,缺这个键回 400。不知道出生时间就传 null,不要填 12:00。
gendermale 或 female。
timeZone必填,IANA 时区名,例如 Asia/Shanghai、Australia/Sydney。+08:00 这类纯偏移拒收,因为它不带夏令时历史。
longitude可选,-180 到 180。建议给。给了就按真太阳时排盘:先用 timeZone 把钟表时间换成绝对时刻,再加上经度差和均时差,不需要判断夏令时。不给就按当地钟表时间排,只扣除有名称的夏令时;遇到历史上无名的时区段(如东京 1948–1951)不扣,若看起来像夏令时会把 flags.dstUncertain 置为 true。两种方式都受下面「夏令时切换当天」的限制。

夏令时切换当天的限制:

鉴权

幂等(Idempotency-Key)

计费与额度

返回

200,Cache-Control: no-store。下例是上面那个请求的结果(计算日为 2026-11-10),大运和行业词条截短,… 处为省略:

{
  "v": "1",
  "chartId": "0123456789abcdef",
  "flags": {"hourKnown": true, "dstUncertain": false},
  "birth": {
    "calendar": "solar",
    "date": "1985-11-03",
    "time": "08:30",
    "timeZone": "Asia/Shanghai",
    "longitude": 121.47,
    "chartTime": {"date": "1985-11-03", "time": "08:52"},
    "trueSolarTime": {
      "date": "1985-11-03",
      "time": "08:52",
      "longitudeOffsetMin": 5.88,
      "eotMin": 16.46,
      "totalShiftMin": 22.34
    },
    "lunar": {"label": "一九八五年九月廿一"}
  },
  "bazi": {
    "year":  {"ganzhi": "乙丑", "gan": "乙", "zhi": "丑", "ganShishen": "正印",
              "hidden": [{"gan": "己", "shishen": "伤官"}, {"gan": "癸", "shishen": "正官"}, {"gan": "辛", "shishen": "正财"}]},
    "month": {"ganzhi": "丙戌", "gan": "丙", "zhi": "戌", "ganShishen": "比肩",
              "hidden": [{"gan": "戊", "shishen": "食神"}, {"gan": "辛", "shishen": "正财"}, {"gan": "丁", "shishen": "劫财"}]},
    "day":   {"ganzhi": "丙午", "gan": "丙", "zhi": "午", "ganShishen": "日主",
              "hidden": [{"gan": "丁", "shishen": "劫财"}, {"gan": "己", "shishen": "伤官"}]},
    "hour":  {"ganzhi": "壬辰", "gan": "壬", "zhi": "辰", "ganShishen": "七杀",
              "hidden": [{"gan": "戊", "shishen": "食神"}, {"gan": "乙", "shishen": "正印"}, {"gan": "癸", "shishen": "正官"}]}
  },
  "dayMaster": {"gan": "丙", "element": "火"},
  "wuxing": {"木": 9, "火": 22, "土": 45, "金": 14, "水": 10},
  "strength": "身弱",
  "pattern": "杂气食神格",
  "xiyong": {"favor": ["火", "木"], "avoid": ["金", "水"], "settled": true},
  "dayun": {
    "steps": [
      {"age": 3, "year": 1987, "date": "1987-04-28", "ganzhi": "丁亥"},
      {"age": 13, "year": 1997, "date": "1997-04-28", "ganzhi": "戊子"},
      …
    ],
    "next": {"age": 43, "year": 2027, "date": "2027-04-28", "ganzhi": "辛卯"}
  },
  "likes": [
    {
      "element": "火",
      "attributes": ["高热", "光亮", "传播性"],
      "industries": ["电力照明", "电器", "光学眼镜", …],
      "direction": {"north": "南", "south": "北"}
    },
    {
      "element": "木",
      "attributes": ["文教", "新生", "植物性"],
      "industries": ["木材家具", "室内装潢", "教育学校", …],
      "direction": {"north": "东", "south": "东"}
    }
  ]
}

示例里的 chartId 是占位值。

字段类型说明
v"1"接口版本。
chartIdstring16 位十六进制命盘指纹,由服务端带密钥计算,不能反推出生日。时辰未知的盘与任何具体时辰的盘指纹都不同。
flags.hourKnownboolean请求里 time 是否给了。
flags.dstUncertainboolean没给经度、出生时刻落在无名时区段且看起来像夏令时:未扣除,时辰处在临界时请补经度再算。时辰未知时恒为 false。
birth.calendar / date / time / timeZone原样回传请求;time 未知为 null。
birth.longitudenumber | null没给为 null。
birth.chartTime{date, time} | null排盘实际使用的时刻。给了经度 = 真太阳时;没给 = 当地钟表时间去掉夏令时。时辰未知为 null。
birth.trueSolarTimeobject | null真太阳时换算明细:date、time、longitudeOffsetMin、eotMin、totalShiftMin(单位分钟,取到 0.01)。只在给了经度且时辰已知时返回。
birth.lunar.labelstring农历日期标签,如「一九八五年九月廿一」。
bazi.year / month / day / hourobjectganzhi、gan、zhi、ganShishen(天干十神;日柱恒为 日主)、hidden(地支藏干,本气在前,每个带 shishen)。时辰未知时 hour 为 null。
dayMaster{gan, element}日主天干与五行。
wuxingobject | null五行占比,木 火 土 金 水 各一个 0–100 的整数,四舍五入后合计约 100。时辰未知为 null。
strengthstring | null强弱档位:身强 / 中和偏强 / 中和偏弱 / 身弱 / 极弱 / 从格 / 化气。时辰未知为 null。
patternstring | null子平主格名。判不出或时辰未知为 null。
xiyong{favor, avoid, settled} | null喜用五行与忌五行,与观命页面一致。settled = false 表示边界盘:喜忌随大运流年变化,只作倾向。时辰未知为 null。
dayun{steps, next} | null大运:每步 age(交运虚岁)、year、date(交运日,排不出为 null)、ganzhi。next 为今天及以后最近的一步,超出序列为 null。时辰未知为 null(起运岁依赖出生时刻)。
likes[]array每个喜用五行一条,顺序同 xiyong.favor:element、attributes、industries(取自行业五行表)、direction.north / direction.south(北半球木东、火南、土中、金西、水北;南半球火、水对调)。边界盘照样返回,请按 settled 降低语气。时辰未知为 []。不含颜色。

不返回:性格句、修养建议、说明句、颜色、强弱推算日志、完整命盘。

错误

除 500 外,错误正文统一为 {"error": {"code": "…", "message": "…"}},带 Cache-Control: no-store。500 是未预料的异常,正文为纯文本 Internal Server Error。

状态code什么时候扣次
204(无正文)不是错误:OPTIONS 请求不论接口是否开放,都由全站跨域处理直接回 204,不鉴权否
404NOT_FOUND接口未开放(除 OPTIONS 外的任何方法)否
405METHOD_NOT_ALLOWED接口已开放,方法既不是 POST 也不是 OPTIONS否
401UNAUTHORIZED无 key、key 错误、key 已吊销或过期;鉴权时账户已停用否
429RATE_LIMITED超过每分钟限额(按合作方设定,默认每分钟 60 次);带 Retry-After: 60,等待后重试即可否
400INVALID_IDEMPOTENCY_KEYIdempotency-Key 格式不对否
400INVALID_JSON、INVALID_BODY、INVALID_CALENDAR、INVALID_DATE、INVALID_TIME、INVALID_GENDER、INVALID_TIMEZONE、INVALID_LONGITUDE、UNCOMPUTABLE请求体或字段不合规,或输入无法排盘否
402QUOTA_EXCEEDED额度用完(X-Quota-Remaining: 0);或账户在鉴权之后、扣次之前被停用,此时即使尚有余额也回 402(X-Quota-Remaining 为实际余额)。两种情况下,带此前已成功扣次的 Idempotency-Key 都先走重放或 409否
409IDEMPOTENCY_CONFLICT同一 Idempotency-Key 已用于不同请求否
503MISCONFIGURED服务端配置异常(在鉴权之前检查,不带 key 也是 503)否
503AUTH_UNAVAILABLE暂时无法校验 key;带 Retry-After: 5否
503COUNT_UNAVAILABLE结果算出来了,但扣次或记账失败;带 Retry-After: 5,不给结果通常否;见上文「计费与额度」,用同一 Idempotency-Key 重试确认

429 和 402 的区别:429 是这一分钟请求太快,等 Retry-After 秒后重试即可。402 靠重试解决不了:X-Quota-Remaining 为 0 是预付额度用完,需要先补额度;大于 0 是账户在鉴权之后被停用,需要联系我们。

调用示例

curl -sS -X POST "$API_BASE/v1/profile" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"calendar":"solar","date":"1985-11-03","time":"08:30","gender":"female","timeZone":"Asia/Shanghai","longitude":121.47}'

重试同一个请求时,请复用第一次生成的那个 Idempotency-Key,不要每次重新生成。

English summary

  • POST /v1/profile is a partner API, enabled per partner. API keys are not available for self-service sign-up. Availability follows the live switch on our side; while the endpoint is not open, every request except OPTIONS returns 404. OPTIONS always gets 204 (no body) from the site-wide CORS handler, which does not mean the endpoint is open. Once open, methods other than POST and OPTIONS return 405. Contact support@guan.life.
  • Input: solar birth date, explicit time ("HH:MM" or null), gender, IANA time zone, optional longitude (recommended). With longitude, the chart uses true solar time: the clock time is converted to an absolute instant via the IANA zone, then the longitude offset and the equation of time are added. Without longitude, it uses local clock time with only named daylight-saving time removed.
  • Limitation on DST transition days: in the repeated hour when DST ends, one clock time maps to two real instants (e.g. Australia/Sydney 2026-04-05 02:30). No request field can say which one, and longitude does not resolve it; the server always picks one of them, and which one depends on the zone. Clock times skipped when DST starts do not exist; the server does not reject them and maps them to one side of the jump.
  • Output: structured BaZi fields only — four pillars with Ten Gods and hidden stems, five-element percentages, strength class, pattern, favourable / unfavourable elements, luck pillars, and per-element attribute / industry / direction terms. No personality sentences, no advice text, and no likes[].colors.
  • Auth: Authorization: Bearer $API_KEY (scheme name case-insensitive). Server-to-server only; do not ship the key to a browser. A missing, wrong, revoked or expired key, or an account already suspended at authentication, returns 401 UNAUTHORIZED.
  • Idempotency: send an Idempotency-Key and reuse it on retries. Same key and same request replays the result without charging again (Idempotent-Replayed: true); same key with a different request returns 409.
  • Billing: prepaid quota. Each successful 200 uses one call; new partner accounts get a default trial quota of 200 calls. 402 QUOTA_EXCEEDED when the quota runs out (X-Quota-Remaining: 0), and also when the account is suspended after authentication but before the call is charged; in that case it is 402 even with quota remaining, and X-Quota-Remaining shows the real balance. At charge time the checks run in order: the key first (revoked or expired by then: 401), then the idempotency record (a request already charged under the same Idempotency-Key replays as 200 without a charge, even with zero quota or a suspended account; a different request with that key gets 409), and only then account status and balance (402). Retrying a request that got 402, or sending it under a new Idempotency-Key, does not help: add quota first, or contact us about the account status. Formal per-call pricing has not been set yet; there is no online purchase or top-up.
  • Other errors: 429 RATE_LIMITED means the per-minute limit was hit (set per partner, default 60 per minute); wait Retry-After: 60 seconds and retry, not charged. 503 COUNT_UNAVAILABLE means the result was computed but charging or recording failed, so no result is returned; the call may still have been charged, so retry with the same Idempotency-Key to confirm (a committed call replays without a second charge; a rolled-back call is charged once).
观命 · 道玄一 — guan.life