hsmail/hsmail-sdk
Composer 安装命令:
composer require hsmail/hsmail-sdk
包简介
Official PHP SDK for the HS Mail API — manage orders, read mailboxes, check accounts and generate 2FA codes.
README 文档
README
Official PHP SDK for the HS Mail API — manage orders, read mailboxes, check live accounts, and generate 2FA codes with a clean, typed interface.
Requirements
- PHP 8.0 or higher
- Composer
Installation
composer require hsmail/hsmail-sdk
Quick Start
<?php require_once 'vendor/autoload.php'; use HsMail\HsMailClient; $client = new HsMailClient('YOUR_API_KEY'); // Check API is reachable $status = $client->ping(); echo "Your IP: " . $status['ip']; // Get your profile $profile = $client->getProfile(); echo "Balance: " . $profile['balance'] . " BDT"; // List all products $products = $client->products()->list(); // Place an order $order = $client->orders()->create('product-uuid', 1); echo "Order ID: " . $order['orderId'];
Authentication
Get your API key from your HS Mail Dashboard.
Pass it to the constructor:
$client = new HsMailClient('hs_live_xxxxxxxxxxxxxxxxxxx');
The SDK automatically sends it as a Bearer token:
Authorization: Bearer hs_live_xxxxxxxxxxxxxxxxxxx
API Reference
Profile & Status
// Ping the API $ping = $client->ping(); // { status, message, ip, timestamp } // Get your profile $profile = $client->getProfile(); // { id, name, email, balance, rankLevel, ... }
Products
// List all products (organised by category) $categories = $client->products()->list(); foreach ($categories as $cat) { foreach ($cat['products'] as $p) { echo $p['name'] . ' — ' . $p['price'] . ' BDT'; } } // Get a single product by UUID $product = $client->products()->get('product-uuid');
Orders
// Create an order $order = $client->orders()->create('product-uuid', 1); // Returns: { orderId, productName, status, isService, totalCost, items[] } // Get order details $details = $client->orders()->get('ORDER_ID'); // Get messages for a service order $chat = $client->orders()->messages('ORDER_ID'); // Send a message on a service order $client->orders()->sendMessage('ORDER_ID', 'Please process ASAP'); // Reopen an order under warranty $client->orders()->reopen('ORDER_ID');
Order Statuses: PENDING · PROCESSING · COMPLETED · DELIVERED · REFUNDED
Mailbox
Outlook / Hotmail
// Read inbox messages $inbox = $client->mailbox()->readOutlook( 'user@hotmail.com', 'REFRESH_TOKEN', 'CLIENT_ID', 'graph' // 'graph' or 'oauth2' ); // Refresh OAuth token $tokens = $client->mailbox()->refreshOutlookToken('CLIENT_ID', 'REFRESH_TOKEN'); echo $tokens['accessToken']; // Check if account is live $check = $client->mailbox()->checkOutlook('user@hotmail.com', 'REFRESH_TOKEN', 'CLIENT_ID'); echo $check['accountStatus']; // 'Live' or 'Die'
Gmail
// Read Gmail (requires GMAIL subscription) $gmail = $client->mailbox()->readGmail('user@gmail.com', 'ORDER_ID'); // Check Gmail account status (requires GMAIL subscription) $status = $client->mailbox()->checkGmail('user@gmail.com'); echo $status['accountStatus']; // 'LIVE' or 'DEAD'
Facebook & Instagram
// Bulk Facebook live check (requires FB subscription) $results = $client->mailbox()->checkFacebookBulk([ 'email1@gmail.com:password1', 'email2@gmail.com:password2', ]); echo "Live: " . $results['liveCount']; // Single Facebook check $fb = $client->mailbox()->checkFacebook('FACEBOOK_USER_ID'); // Instagram check $ig = $client->mailbox()->checkInstagram('username'); echo $ig['accountStatus']; // 'LIVE' or 'DEAD'
Hotmail Creator
$result = $client->mailbox()->createHotmailOrder( ['user1@hotmail.com', 'user2@hotmail.com'], 'USER_ONLY' // or 'USER_PASS' ); echo "Order ID: " . $result['orderId'];
Tools
// Generate a TOTP 2FA code $result = $client->tools()->generate2fa('JBSWY3DPEHPK3PXP'); echo "Code: " . $result['code'] . " (expires in " . $result['timeRemaining'] . "s)";
Error Handling
All errors throw typed exceptions inheriting from HsMailException:
| Exception | Trigger |
|---|---|
AuthenticationException |
Invalid/missing API key, banned/suspended account |
RateLimitException |
>100 requests/minute |
NotFoundException |
Resource doesn't exist |
InsufficientBalanceException |
Not enough BDT balance |
ValidationException |
Invalid input, out of stock, closed order |
HsMailException |
Any other API error |
use HsMail\Exceptions\{HsMailException, InsufficientBalanceException, RateLimitException}; try { $order = $client->orders()->create('product-uuid', 5); } catch (InsufficientBalanceException $e) { echo "Need more balance! Top up at https://hsmail.shop"; } catch (RateLimitException $e) { sleep(60); // Wait and retry } catch (HsMailException $e) { echo "[{$e->getErrorCode()}] {$e->getMessage()} (HTTP {$e->getHttpStatus()})"; // Full response data: print_r($e->getResponseData()); }
Rate Limits
- 100 requests per minute per API key
- On
RateLimitException, wait ~60 seconds and retry
Publishing to Packagist
- Push this SDK to a public GitHub repository
- Log in to packagist.org and click Submit
- Enter your GitHub repository URL
- Enable auto-update via a GitHub webhook (Settings → Webhooks →
https://packagist.org/api/github?username=YOUR_USERNAME)
License
MIT © HS Mail Team
hsmail/hsmail-sdk 适用场景与选型建议
hsmail/hsmail-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sdk」 「gmail」 「mailbox」 「outlook」 「hotmail」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hsmail/hsmail-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hsmail/hsmail-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hsmail/hsmail-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Magento2 email providers integration (smtp, mandrill, amazon ses)
A PSR-7 compatible library for making CRUD API endpoints
Magento2 email providers integration (smtp, mandrill, amazon ses)
Gmail API Wrapper for Symfony
Send email with Gmail using this driver plugin.
Google Calendar API package for Laravel based on dacastro4/laravel-gmail
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-21