首页 开发文档 生理期计算

生理期计算

生理期推算工具。以末次月经首日为起点,按周期长度与行经天数推算未来多个周期的行经起止、排卵日(下次月经前 14 天,黄体期相对固定)、易孕期(排卵日前 5 天至排卵后 1 天)与安全期区间。安全期避孕失败率较高,结果仅供健康管理参考,不能作为避孕依据。

请求信息
请求地址 https://cx4.cn/openApi/life/period 复制
请求方式 GET / POST
接口标识 life_period
鉴权方式 必须
四种方式任选其一:Header「X-Api-Key」/ Header「Authorization: Bearer 你的key」/ URL 参数「?key=你的key」/ POST 参数「key」
请求参数
参数名 类型 必填 说明 示例
last_period string 是 末次月经第一天,格式 Y-m-d(也可用 date 传) 2026-09-01
cycle int 否 月经周期天数,20-45 28
period_days int 否 行经持续天数,2-10 5
months int 否 向前推算多少个周期,1-12 3
返回参数

下表字段位于返回结构的 data 内;外层 code / message 为全平台统一格式,不在此重复列出。

参数名 类型 说明 示例
ok bool 是否成功 true
cycle int 周期天数 28
period_days int 行经天数 5
next_period string 下次月经开始日 2026-09-29
ovulation string 排卵日 2026-09-15
fertile array 易孕期起止 ["2026-09-11","2026-09-16"]
safe array 安全期区间 ["2026-09-17","2026-09-28"]
list array 未来 N 个周期的明细 []
note string 医学免责说明 ...
返回示例

成功

{
    "code": 200,
    "message": "操作成功",
    "data": {
        "ok": true,
        "cycle": 28,
        "period_days": 5,
        "next_period": "2026-09-01",
        "ovulation": "2026-09-15",
        "fertile": [
            "2026-09-10",
            "2026-09-19"
        ],
        "safe": [
            "2026-09-06",
            "2026-09-09"
        ],
        "list": [
            {
                "index": 1,
                "period_start": "2026-09-01",
                "period_end": "2026-09-05",
                "ovulation_day": "2026-09-15",
                "fertile_start": "2026-09-10",
                "fertile_end": "2026-09-19",
                "safe_start": "2026-09-06",
                "safe_end": "2026-09-09"
            },
            {
                "index": 2,
                "period_start": "2026-09-29",
                "period_end": "2026-10-03",
                "ovulation_day": "2026-10-13",
                "fertile_start": "2026-10-08",
                "fertile_end": "2026-10-17",
                "safe_start": "2026-10-04",
                "safe_end": "2026-10-07"
            },
            {
                "index": 3,
                "period_start": "2026-10-27",
                "period_end": "2026-10-31",
                "ovulation_day": "2026-11-10",
                "fertile_start": "2026-11-05",
                "fertile_end": "2026-11-14",
                "safe_start": "2026-11-01",
                "safe_end": "2026-11-04"
            }
        ],
        "note": "基于日历法的估算,周期不规律者误差较大;安全期避孕失败率约 20%,不建议单独作为避孕手段"
    }
}

失败

{
    "code": 400,
    "message": "日期格式不正确,请使用 Y-m-d",
    "data": null
}
平台通用状态码
状态码 说明
200调用成功
400缺少必填参数或参数格式有误
401密钥缺失或无效
402余额不足,请充值后重试
403未开通该接口,请在本页开通后调用
404接口不存在或已下架
429触发限流,请稍后重试
500接口调用失败(已扣款的会自动退款)
调用示例

cURL 复制

curl -X POST "https://cx4.cn/openApi/life/period" -H "X-Api-Key: 你的SecretKey" -d "last_period=2026-09-01&cycle=28&period_days=5&months=3"

JavaScript 复制

fetch('https://cx4.cn/openApi/life/period', {
  method: 'POST',
  headers: {
    'X-Api-Key': '你的SecretKey',
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: 'last_period=2026-09-01&cycle=28&period_days=5&months=3'
})
.then(res => res.json())
.then(data => console.log(data));

PHP 复制

post('https://cx4.cn/openApi/life/period', [
    'headers' => ['X-Api-Key' => '你的SecretKey'],
    'form_params' => ['last_period' => '2026-09-01', 'cycle' => '28', 'period_days' => '5', 'months' => '3'],
]);
echo $response->getBody();

Java 复制

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://cx4.cn/openApi/life/period"))
    .header("X-Api-Key", "你的SecretKey")
    .header("Content-Type", "application/x-www-form-urlencoded")
    .POST(HttpRequest.BodyPublishers.ofString("last_period=2026-09-01&cycle=28&period_days=5&months=3"))
    .build();
HttpResponse response = client.send(
        request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

Python 复制

import requests

res = requests.post('https://cx4.cn/openApi/life/period',
    headers={'X-Api-Key': '你的SecretKey'},
    data={'last_period': '2026-09-01', 'cycle': '28', 'period_days': '5', 'months': '3'})
print(res.json())
在线测试 (使用你的密钥真实调用,计费与正常调用一致)

登录后可在线测试: 立即登录

计费说明

¥0.0010

每次调用


每日免费额度:100 次

累计调用:3 次


快速上手

1. 注册并完成邮箱验证:立即注册

2. 登录后复制 Secret Key:去登录

3. 点击右侧「开通接口」按钮

4. 用下方「在线测试」一键体验,或复制下方示例代码直接调用