Hyperf 开箱即用的多语言、多币种、多时区、国际支付、全球物流PHP标准化组件
·
以下是基于 Hyperf 框架构建全球化应用的最佳)PHP 标准化组件方案:
---dle-faddling… (1m 26s · ↓ 313 tokens)
多语言 (i18n) ──────────────────────────────
composer require hyperf/translation symfony/translation symfony/intl
- hyperf/translation — Hyperf 原生翻译组件,开箱即用
- symfony/intl — ICU 标准,日期/数字/货币本地化格式
- wilbur-yu/hyperf-translatable — 模型多语言字段 Trait
---
多币种
composer require moltin/currency symfony/intl
- moltin/currency — 多币种定价 + 汇率存储
- symfony/intl — 货币符号、格式化(NumberFormatter)
- 汇率数据源推荐对接 Open Exchange Rates 或 Fixer.io
---
多时区
PHP 原生方案即可,无需额外库:
// 存储统一用 UTC,展示时按用户时区转换
$dt = new DateTimeImmutable('now', new DateTimeZone('UTC'));
$display = $dt->setTimezone(new DateTimeZone($userTimezone));
配合 symfony/intl 的 IntlDateFormatter 做本地化格式输出。
---
国际支付
composer require stripe/stripe-php adyen/php-api-library thephpleague/omnipay
# 国内支付(支付宝/微信/银联)
composer require yansongda/hyperf-pay
┌───────────────────────┬─────────────────────────────────────────┐
│ 包 │ 适用场景 │
├───────────────────────┼─────────────────────────────────────────┤
│ stripe/stripe-php │ 全球主流,支持 135+ 币种 │
├───────────────────────┼─────────────────────────────────────────┤
│ adyen/php-api-library │ 企业级,全球本地支付方式 │
├───────────────────────┼─────────────────────────────────────────┤
│ thephpleague/omnipay │ 多网关统一接口抽象层 │
├───────────────────────┼─────────────────────────────────────────┤
│ yansongda/hyperf-pay │ 支付宝、微信支付、银联,Hyperf 原生适配 │
└───────────────────────┴─────────────────────────────────────────┘
---
全球物流
composer require easypost/easypost-php
- easypost/easypost-php — 官方 SDK,接入 100+ 承运商(UPS、FedEx、DHL、USPS 等)
- 在 Hyperf 中建议通过协程 HTTP 客户端封装异步调用,避免阻塞
---
Hyperf 集成注意事项
1. 协程兼容 — 支付/物流 SDK 的 HTTP 请求需替换为 hyperf/guzzle 协程客户端
2. 上下文隔离 — 多时区/多语言的用户上下文用 Hyperf\Context\Context 存储,避免协程间污染
3. 配置中心 — 汇率、语言包等动态配置推荐接入 hyperf/config-center
// 协程上下文存储用户语言/时区
use Hyperf\Context\Context;
Context::set('locale', $request->header('Accept-Language', 'en'));
Context::set('timezone', $user->timezone ?? 'UTC');
这套组合覆盖了全球化应用的核心需求,且均有 Composer 包可直接安装。
更多推荐




所有评论(0)