astrologyapi/astrologyapi-php
Composer 安装命令:
composer require astrologyapi/astrologyapi-php
包简介
Official PHP SDK for AstrologyAPI.com — Vedic, Western, KP, Lal Kitab, Numerology, and more.
README 文档
README
Official PHP SDK for AstrologyAPI.com — providing programmatic access to Vedic, Western, KP, Lal Kitab, Numerology, Tarot, Chinese, and PDF report APIs.
Requirements
- PHP 8.1+
- Guzzle 7.x (
guzzlehttp/guzzle)
Installation
composer require astrologyapi/astrologyapi-php
Quick Start
<?php require 'vendor/autoload.php'; use AstrologyAPI\Client; use AstrologyAPI\Models\BirthData; // Initialize client — reads ASTROLOGYAPI_API_KEY $client = Client::fromEnv(); // Or provide your API key directly: // $client = new Client('your-api-key'); // Build birth data $birth = new BirthData( day: 15, month: 8, year: 1990, hour: 14, min: 30, lat: 28.6139, lon: 77.2090, tzone: 5.5, ); // Get birth details $details = $client->vedic()->getBirthDetails($birth); print_r($details);
Namespaces
The SDK is organized into 11 namespaces matching the API's logical boundaries:
| Namespace | Methods | Description |
|---|---|---|
$client->vedic() |
53 | Vedic astrology: birth details, planets, dashas, panchang, matchmaking, doshas |
$client->kp() |
6 | Krishnamurti Paddhati: planets, cusps, significators, horoscope |
$client->lalKitab() |
5 | Lal Kitab: horoscope, debts, remedies, houses, planets |
$client->western() |
28 | Western astrology: planets, aspects, solar return, personality reports, synastry |
$client->westernTransit() |
5 | Western transit positions and forecast reports |
$client->numerology() |
18 | Vedic numerology (BirthData) + Western numerology (NumeroData) |
$client->horoscopes() |
6 | Daily/next/previous/consolidated/monthly sun-sign predictions + nakshatra prediction |
$client->tarot() |
2 | Daily tarot card + detailed reading |
$client->chinese() |
1 | Chinese horoscope |
$client->pdf() |
8 | PDF report generation (Vedic + Western; returns binary string) |
$client->location() |
2 | Geo details and timezone lookup |
Usage Examples
Vedic Astrology
use AstrologyAPI\Models\BirthData; $birth = new BirthData(day: 15, month: 8, year: 1990, hour: 14, min: 30, lat: 28.6139, lon: 77.2090, tzone: 5.5); // Birth details $client->vedic()->getBirthDetails($birth); // Planets $client->vedic()->getPlanets($birth); // Current Vimshottari dasha $client->vedic()->getCurrentVdasha($birth); // Kundli chart (D1 by default) $client->vedic()->getChart('D1', $birth); // Panchang $client->vedic()->getBasicPanchang($birth);
Vedic Matchmaking
Male and female birth data are sent with m_ and f_ prefixes respectively.
$male = new BirthData(day: 10, month: 5, year: 1988, hour: 6, min: 0, lat: 28.61, lon: 77.20, tzone: 5.5); $female = new BirthData(day: 22, month: 11, year: 1990, hour: 9, min: 15, lat: 19.07, lon: 72.87, tzone: 5.5); $client->vedic()->getAshtakootPoints($male, $female); $client->vedic()->getMatchMakingReport($male, $female);
Western Astrology
$client->western()->getPlanets($birth); $client->western()->getPersonalityReport($birth); // Synastry — person1 fields get p_ prefix, person2 get s_ prefix $client->western()->getSynastry($person1, $person2); $client->western()->getCompositeChart($person1, $person2);
Numerology
Vedic numerology endpoints require full BirthData. Western numerology endpoints only need NumeroData (date + name).
use AstrologyAPI\Models\NumeroData; // Vedic numerology — needs full birth chart $client->numerology()->getTable($birth); $client->numerology()->getDailyPrediction($birth); // Western numerology — only needs date + name $numero = new NumeroData(day: 15, month: 8, year: 1990, name: 'John Doe'); $client->numerology()->getLifepathNumber($numero); $client->numerology()->getExpressionNumber($numero);
Horoscopes
$client->horoscopes()->getDaily('aries'); $client->horoscopes()->getMonthly('scorpio'); $client->horoscopes()->getDailyConsolidated('capricorn'); // Nakshatra prediction needs birth data $client->horoscopes()->getDailyNakshatraPrediction($birth);
PDF Reports
All PDF methods return a raw binary string containing the PDF. Write it to a file or stream it to the browser.
use AstrologyAPI\Models\PDFBranding; $branding = new PDFBranding( companyName: 'My Astrology App', logoUrl: 'https://example.com/logo.png', companyEmail: 'hello@example.com', ); // Vedic PDF reports $pdf = $client->pdf()->vedic->getBasicHoroscope($birth, $branding); file_put_contents('horoscope.pdf', $pdf); $pdf = $client->pdf()->vedic->getProfessionalHoroscope($birth, $branding, ['name' => 'John']); // Match making PDF $pdf = $client->pdf()->vedic->getMatchMaking($male, $female, $branding, [ 'name' => 'Rahul', 'partner_name' => 'Priya', ]); // Western PDF reports $pdf = $client->pdf()->western->getNatalChart($birth, $branding); $pdf = $client->pdf()->western->getSynastry($person1, $person2, $branding); // Stream directly to browser header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="report.pdf"'); echo $pdf;
Location
// Geo lookup (city name → coordinates + timezone) $client->location()->getGeoDetails('New Delhi', maxRows: 5); // Timezone lookup (birth moment + coordinates → timezone and DST info) $client->location()->getTimezone(new BirthData( day: 15, month: 8, year: 1990, hour: 14, min: 30, lat: 28.61, lon: 77.20, tzone: 5.5, ));
Error Handling
use AstrologyAPI\Errors\AuthenticationError; use AstrologyAPI\Errors\PlanRestrictedError; use AstrologyAPI\Errors\QuotaExceededError; use AstrologyAPI\Errors\RateLimitError; use AstrologyAPI\Errors\ValidationError; use AstrologyAPI\Errors\ServerError; use AstrologyAPI\Errors\AstrologyAPIException; try { $result = $client->vedic()->getBirthDetails($birth); } catch (AuthenticationError $e) { // 401 — Invalid or missing API key } catch (QuotaExceededError $e) { // 402 — API quota exhausted; upgrade your plan } catch (PlanRestrictedError $e) { // 403 — Endpoint not available on current plan } catch (RateLimitError $e) { // 429 — Too many requests; slow down } catch (ValidationError $e) { // 400/422 — Invalid request parameters } catch (ServerError $e) { // 5xx — API server error } catch (AstrologyAPIException $e) { // Any other API error echo $e->getHttpCode() . ': ' . $e->getMessage(); }
Authentication
The SDK uses token-based authentication via the x-astrologyapi-key header.
// Via environment variables: export ASTROLOGYAPI_API_KEY="ak-..." $client = Client::fromEnv(); // Or direct instantiation: $client = new Client('ak-your-token');
Configuration
$client = new Client('your-api-key', [ 'timeout' => 30.0, // request timeout in seconds (default: 30) 'retries' => 3, // automatic retries on transient errors (default: 3) ]);
Running Tests
composer install
composer test
Static Analysis
composer analyse
License
MIT
astrologyapi/astrologyapi-php 适用场景与选型建议
astrologyapi/astrologyapi-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 10, 最近一次更新时间为 2026 年 05 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「horoscope」 「astrology」 「kundli」 「panchang」 「vedic」 「numerology」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 astrologyapi/astrologyapi-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 astrologyapi/astrologyapi-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 astrologyapi/astrologyapi-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Zodiac Sign Calculator
A Bundle for displaying the zodiac for a Date
Custom horoscope module
Complete 100% 1:1 PHP FFI Wrapper for the Swiss Ephemeris C Library - Direct C function calls with zero abstraction for maximum astronomical precision
Drawing component for Jyotish Library
Authentic Vedic Panchanga calculation engine powered by the JPL Moshier Ephemeris FFI wrapper
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 39
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-12