承接 teracrafts/huefy-sdk-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

teracrafts/huefy-sdk-php

Composer 安装命令:

composer require teracrafts/huefy-sdk-php

包简介

Huefy - PHP SDK

README 文档

README

Official PHP SDK for Huefy — transactional email delivery made simple.

Installation

composer require teracrafts/huefy-sdk

To use a custom PSR-18 HTTP client instead of the bundled Guzzle adapter:

composer require teracrafts/huefy-sdk psr/http-client your-psr18-client

Requirements

  • PHP 8.1+
  • guzzlehttp/guzzle (installed automatically, or bring your own PSR-18 client)

Quick Start

use Teracrafts\Huefy\HuefyEmailClient;
use Teracrafts\Huefy\Models\SendEmailRequest;
use Teracrafts\Huefy\Models\SendEmailRecipient;

$client = new HuefyEmailClient([
    'apiKey' => 'sdk_your_api_key',
]);

$response = $client->sendEmail(new SendEmailRequest(
    templateKey: 'welcome-email',
    data: ['firstName' => 'Alice', 'trialDays' => 14],
    recipient: new SendEmailRecipient(
        email: 'alice@example.com',
        type: 'cc',
        data: ['locale' => 'en'],
    ),
));

echo 'Email ID: ' . $response->data->emailId . PHP_EOL;

Key Features

  • PSR-18 compatible — swap in any PSR-18 HTTP client
  • PSR-3 logger — plug in any PSR-3 logger (Monolog, etc.)
  • PHP 8.1 enumsEmailProvider is a native enum
  • Named arguments — all constructors support PHP 8 named argument syntax
  • Retry with exponential backoff — configurable attempts, base delay, ceiling, and jitter
  • Circuit breaker — opens after 5 consecutive failures, probes after 30 s
  • HMAC-SHA256 signing — optional request signing for additional integrity verification
  • Key rotation — primary + secondary API key with seamless failover
  • Rate limit callbacksonRateLimitUpdate fires whenever rate-limit headers change
  • PII detection — warns when template variables contain sensitive field patterns

Configuration Reference

Parameter Default Description
apiKey Required. Must have prefix sdk_, srv_, or cli_
baseUrl https://api.huefy.dev/api/v1/sdk Override the API base URL
timeout 30.0 Request timeout in seconds
retryConfig->maxAttempts 3 Total attempts including the first
retryConfig->baseDelay 0.5 Exponential backoff base delay (seconds)
retryConfig->maxDelay 10.0 Maximum backoff delay (seconds)
retryConfig->jitter 0.2 Random jitter factor (0–1)
circuitBreakerConfig->failureThreshold 5 Consecutive failures before circuit opens
circuitBreakerConfig->resetTimeout 30.0 Seconds before half-open probe
logger null PSR-3 logger instance
secondaryApiKey null Backup key used during key rotation
enableRequestSigning false Enable HMAC-SHA256 request signing
onRateLimitUpdate null Callable fired on rate-limit header changes

Bulk Email

use Teracrafts\Huefy\Models\BulkRecipient;
use Teracrafts\Huefy\Models\SendBulkEmailsRequest;

$bulk = $client->sendBulkEmails(new SendBulkEmailsRequest(
    templateKey: 'promo',
    recipients: [
        new BulkRecipient(email: 'bob@example.com'),
        new BulkRecipient(email: 'carol@example.com'),
    ]
));

echo "Sent: {$bulk->data->successCount}, Failed: {$bulk->data->failureCount}" . PHP_EOL;

Error Handling

use Teracrafts\Huefy\Errors\ErrorCode;
use Teracrafts\Huefy\Errors\HuefyException;

try {
    $response = $client->sendEmail($request);
    echo 'Delivered: ' . $response->data->emailId . PHP_EOL;
} catch (HuefyException $e) {
    if ($e->getErrorCode() === ErrorCode::AUTHENTICATION_ERROR) {
        echo 'Invalid API key' . PHP_EOL;
    } elseif ($e->getErrorCode() === ErrorCode::RATE_LIMIT_ERROR) {
        echo 'Rate limited' . PHP_EOL;
    } elseif ($e->getErrorCode() === ErrorCode::CIRCUIT_BREAKER_OPEN) {
        echo 'Circuit open — service unavailable, backing off' . PHP_EOL;
    } else {
        echo "Huefy error [{$e->getErrorCode()}]: {$e->getMessage()}" . PHP_EOL;
    }
}

Error Code Reference

Exception Code Meaning
HuefyInitException 1001 Client failed to initialise
HuefyAuthException 1102 API key rejected
HuefyNetworkException 1201 Upstream request failed
HuefyCircuitOpenException 1301 Circuit breaker tripped
HuefyRateLimitException 2003 Rate limit exceeded
HuefyTemplateMissingException 2005 Template key not found

Health Check

$health = $client->healthCheck();
if (($health['data']['status'] ?? null) !== 'healthy') {
    error_log('Huefy degraded: ' . ($health['data']['status'] ?? 'unknown'));
}

Local Development

The PHP SDK does not resolve HUEFY_MODE automatically. To match the local Caddy setup, set baseUrl to https://api.huefy.on/api/v1/sdk. To bypass Caddy and hit the raw app port directly, use http://localhost:8080/api/v1/sdk instead:

$client = new HuefyEmailClient([
    'apiKey' => 'sdk_local_key',
    'baseUrl' => 'https://api.huefy.on/api/v1/sdk',
]);

Namespace Compatibility

The canonical PHP namespace is Teracrafts\Huefy\.... Existing Huefy\... references remain supported through the bundled compatibility aliases.

Developer Guide

Full documentation, advanced patterns, and provider configuration are in the PHP Developer Guide.

License

MIT

teracrafts/huefy-sdk-php 适用场景与选型建议

teracrafts/huefy-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「template」 「email」 「sdk」 「transactional」 「huefy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 teracrafts/huefy-sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 teracrafts/huefy-sdk-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 teracrafts/huefy-sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-04