# 斗拱 **Repository Path**: dqidian/bapay ## Basic Information - **Project Name**: 斗拱 - **Description**: 汇付天下斗拱支付平台 PHP SDK - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-12 - **Last Updated**: 2026-06-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Bapay - 斗拱支付 PHP SDK (Hyperf 3.0 版) 汇付天下斗拱支付平台 PHP SDK,专为 Hyperf 3.0 重构。 ## 要求 - PHP >= 8.1 - Hyperf >= 3.0 - ext-openssl - ext-json ## 安装 ```bash composer require cjhd/bapay ``` ## 配置 发布配置文件: ```bash php bin/hyperf.php vendor:publish cjhd/bapay ``` 编辑 `config/autoload/bapay.php`: ```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', ''), ], ], ]; ``` ## 用法 ### 对象式(推荐) ```php 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(); } } ``` ### 多商户 ```php $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); ``` ### 文件上传 ```php $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); ``` ### 页面接口 ```php $request = new V2TradeOnlinepaymentQuickpayFrontpayRequest(); // set fields... $response = $this->client->send($request, null, true); // $response->getRawData() 返回 HTML ``` ### 验签工具 ```php 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); ``` ## 测试 ```bash 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`