cjhd/bapay
Composer 安装命令:
composer require cjhd/bapay
包简介
汇付天下斗拱支付平台 PHP SDK - Hyperf 3.0 版
README 文档
README
汇付天下斗拱支付平台 PHP SDK,专为 Hyperf 3.0 重构。
要求
- PHP >= 8.1
- Hyperf >= 3.0
- ext-openssl
- ext-json
安装
composer require cjhd/bapay
配置
发布配置文件:
php bin/hyperf.php vendor:publish cjhd/bapay
编辑 config/autoload/bapay.php:
return [
'debug' => env('BAPAY_DEBUG', false),
'prod_mode' => env('BAPAY_PROD_MODE', true),
'merchants' => [
'default' => [
'product_id' => env('BAPAY_PRODUCT_ID'),
'sys_id' => env('BAPAY_SYS_ID'),
'rsa_merch_private_key' => env('BAPAY_RSA_PRIVATE_KEY'),
'rsa_huifu_public_key' => env('BAPAY_RSA_HUIFU_PUBLIC_KEY'),
'huifu_id' => env('BAPAY_HUIFU_ID'),
'skill_source' => env('BAPAY_SKILL_SOURCE', ''),
],
],
];
用法
对象式(推荐)
use Bapay\Contract\BapayClientInterface;
use Bapay\Request\V2MerchantBusiOpenRequest;
class DemoService
{
public function __construct(private BapayClientInterface $client) {}
public function openMerchant(): array
{
$request = new V2MerchantBusiOpenRequest();
$request->setReqSeqId(date('YmdHis') . mt_rand());
$request->setReqDate(date('Ymd'));
$request->setHuifuId('6666000104778898');
$response = $this->client->send($request);
if ($response->isError()) {
throw new \RuntimeException($response->getErrorInfo());
}
return $response->getData();
}
}
多商户
$client = $container->get(BapayClientInterface::class);
$client->setMerchantKey('merchant2');
$request = new V2MerchantBusiOpenRequest();
$request->setReqSeqId(date('YmdHis') . mt_rand());
$request->setReqDate(date('Ymd'));
$response = $client->send($request);
文件上传
$request = new V2SupplementaryPictureRequest();
$request->setReqSeqId(date('YmdHis') . mt_rand());
$request->setReqDate(date('Ymd'));
$request->setHuifuId('6666000104778898');
$file = new \CURLFile('/path/to/file.jpg');
$response = $this->client->send($request, $file);
页面接口
$request = new V2TradeOnlinepaymentQuickpayFrontpayRequest();
// set fields...
$response = $this->client->send($request, null, true);
// $response->getRawData() 返回 HTML
验签工具
use Bapay\Signature\Signer;
$signer = new Signer();
$data = ['req_seq_id' => '...', 'trans_amt' => '1.00'];
// 加签
$sign = $signer->sign($data, $merchantPrivateKey);
// 验签
$ok = $signer->verify($responseSign, $data, $huifuPublicKey);
// Webhook 验签
$ok = $signer->verifyWebhook($sign, $data, $key);
测试
cd bapay/
composer install
vendor/bin/phpunit
架构
bapay/
├── src/
│ ├── BapayClient.php # 主客户端(Guzzle,可注入)
│ ├── BapayResponse.php # 统一响应对象
│ ├── MerchantConfig.php # 商户配置值对象
│ ├── Signature/Signer.php # RSA2 签名/验签
│ ├── Enums/FunctionCodeEnum # API 接口编码
│ ├── Request/ # 323 个 API 请求 DTO
│ └── ConfigProvider.php # Hyperf 服务提供者
├── publish/bapay.php # 可发布配置文件
├── config/bapay.php # 默认配置
└── tests/ # 74 个测试用例,~2300+ 断言
- 基于
hyperf/guzzle(无 curl) - 配置通过
hyperf/config管理 - 日志通过
hyperf/logger(PSR-3) - PSR-4 自动加载,无需手动
require_once
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-12