Node.js SDK for ApiWorks 星盘 API(astro.apiworks.com)。简化调用星盘、八字、紫微、星宿、运势、AI 报告等接口的代码开发。
- 星盘 (Chart):本命盘、天象盘、行运盘、比较盘、组合盘、三限/次限/法达/日弧等
- 星座 (Sign):我的星座、星座列表、星座配对
- 运势 (Scope):日/周/月/年运势
- 星象事件 (Event):行运星象事件
- 紫微斗数 (Ziwei):本命盘、排盘、含解读的排盘
- 星宿 (Naks):27 星宿关系
- 八字 (Bazi):命盘、流盘、合盘、总结
- 报告 (Report):桃花、周运、年运、合盘、财运等 AI 报告
npm install apiworks-astro-node-sdk或从源码安装(在项目目录下):
npm install
npm run build- Node.js >= 14
- axios >= 1.6
- zod >= 3.22
const { AstroCloudClient } = require('apiworks-astro-node-sdk');
// 创建客户端
const client = new AstroCloudClient({
app_id: 'your-app-id',
app_key: 'your-app-key'
});
// base_url 默认为 https://cloud.apiworks.com/open/astro,如需可传入 base_url 覆盖
// 本命盘
async function getNatalChart() {
try {
const resp = await client.chart_natal({
birth_dt: '1990-08-14 12:00:00',
tz: 8,
longitude: 116.4074,
latitude: 39.9042
});
if (resp.code === 0 && resp.data) {
console.log(resp.data.house, resp.data.planet);
}
} catch (error) {
console.error('Error:', error);
}
}
getNatalChart();import { AstroCloudClient, SinglePointQry, ApiResp, AstroDataVo } from 'apiworks-astro-node-sdk';
// 创建客户端
const client = new AstroCloudClient({
app_id: 'your-app-id',
app_key: 'your-app-key'
});
// 本命盘
async function getNatalChart() {
try {
const qry: SinglePointQry = {
birth_dt: '1990-08-14 12:00:00',
tz: 8,
longitude: 116.4074,
latitude: 39.9042
};
const resp: ApiResp<AstroDataVo> = await client.chart_natal(qry);
if (resp.code === 0 && resp.data) {
console.log(resp.data.house, resp.data.planet);
}
} catch (error) {
console.error('Error:', error);
}
}
getNatalChart();八字命盘:
import { AstroCloudClient, BaziNatalQry, ApiResp, BaziNatalVO } from 'apiworks-astro-node-sdk';
const client = new AstroCloudClient({ app_id: '...', app_key: '...' });
async function getBaziNatal() {
const qry: BaziNatalQry = {
birth_dt: '1990-08-14 12:00:00',
tz: 8,
gender: 'male'
};
const resp: ApiResp<BaziNatalVO> = await client.bazi_natal(qry);
if (resp.code === 0 && resp.data) {
console.log(resp.data.pillars, resp.data.flow_decadal);
}
}
getBaziNatal();紫微本命盘:
import { AstroCloudClient, ZiweiNatalQry, ApiResp, ZiweiNatalVo } from 'apiworks-astro-node-sdk';
const client = new AstroCloudClient({ app_id: '...', app_key: '...' });
async function getZiweiNatal() {
const qry: ZiweiNatalQry = {
birth_dt: '1999-10-17 21:00:00',
tz: 8,
gender: 'female'
};
const resp: ApiResp<ZiweiNatalVo> = await client.ziwei_natal(qry);
if (resp.code === 0 && resp.data) {
console.log(resp.data.natal.palaces, resp.data.patterns);
}
}
getZiweiNatal();星宿关系:
import { AstroCloudClient, NaksQry, NaksBirthInfo, ApiResp, NaksVo } from 'apiworks-astro-node-sdk';
const client = new AstroCloudClient({ app_id: '...', app_key: '...' });
async function getNaksRelations() {
const qry: NaksQry = {
birth_info: {
birth_dt: '1990-01-15 00:00:00',
tz: 8
},
others_birth_info: [
{
birth_dt: '1992-03-20 00:00:00',
tz: 8
}
]
};
const resp: ApiResp<NaksVo> = await client.naks_relations(qry);
if (resp.code === 0 && resp.data) {
console.log(resp.data.natal_naks_info, resp.data.others_natal_relation);
}
}
getNaksRelations();双点星盘(行运/比较盘):
import { AstroCloudClient, DoublePointQry, TimeAndLocation, ApiResp, AstroDataVo } from 'apiworks-astro-node-sdk';
const client = new AstroCloudClient({ app_id: '...', app_key: '...' });
async function getTransitChart() {
const qry: DoublePointQry = {
user_list: [
{
birth_dt: '1990-08-14 12:00:00',
tz: 8,
longitude: 116.4,
latitude: 39.9
},
{
birth_dt: '2025-02-26 12:00:00',
tz: 8,
longitude: 116.4,
latitude: 39.9
}
]
};
// 行运盘
const transitResp: ApiResp<AstroDataVo> = await client.chart_transit(qry);
// 比较盘
const comparisonResp: ApiResp<AstroDataVo> = await client.chart_comparison(qry);
if (transitResp.code === 0 && transitResp.data) {
console.log(transitResp.data.planet, transitResp.data.house);
}
}
getTransitChart();报告(桃花/合盘/周运等):
import { AstroCloudClient, RomanticCreateQry, TimeAndLocation, ApiResp, AstroReportVo } from 'apiworks-astro-node-sdk';
const client = new AstroCloudClient({ app_id: '...', app_key: '...' });
async function createRomanticReport() {
const qry: RomanticCreateQry = {
user_birth_point: {
birth_dt: '1990-01-01 13:14:15',
tz: 8,
longitude: 116.4,
latitude: 39.9
},
user_current_point: {
birth_dt: '2025-11-26 13:14:15',
tz: 8,
longitude: 116.4,
latitude: 39.9
},
user_id: 'user-123'
};
const resp: ApiResp<AstroReportVo> = await client.report_romantic(qry);
if (resp.code === 0 && resp.data && resp.data.serial_no) {
const serial_no = resp.data.serial_no; // 可用 report_get / report_get_html 拉取报告
console.log('Report serial number:', serial_no);
}
}
createRomanticReport();所有接口均返回 ApiResp<T> 类型,包含 code、msg、data、exe_time 字段,其中 data 为与接口对应的响应类型(如 BaziNatalVO、NaksVo、AstroDataVo 等):
const resp: ApiResp<BaziNatalVO> = await client.bazi_natal(qry);
if (resp.code === 0 && resp.data) {
const data: BaziNatalVO = resp.data; // 强类型,IDE 可补全
console.log(data.pillars);
}用真实接口调用一次本命盘,确认网络与凭证正常:
# 在项目根目录,先安装依赖
npm install
# 设置你的 app_id / app_key 后执行(不要提交到仓库)
export APIWORKS_APP_ID="你的app_id"
export APIWORKS_APP_KEY="你的app_key"
node scripts/verify_sdk.ts成功会打印 验证通过,SDK 可用。;若 code != 0 或报错,请检查凭证与网络。
apiworks-astro-node-sdk/
├── src/
│ ├── apiworks_astro_sdk/
│ │ ├── models/
│ │ │ ├── common.ts # ApiResp, TimeAndLocation
│ │ │ ├── requests.ts # 各类请求模型
│ │ │ ├── responses.ts # 各类响应模型
│ │ │ └── index.ts # 模型导出
│ │ ├── client.ts # AstroCloudClient
│ │ └── index.ts # 客户端导出
│ └── index.ts # 主导出
├── scripts/
│ └── verify_sdk.ts # SDK 验证脚本
├── package.json
├── tsconfig.json
└── README.md
MIT