PHPackages                             allesx/cgb-payment-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. allesx/cgb-payment-sdk

ActiveLibrary[Payment Processing](/categories/payments)

allesx/cgb-payment-sdk
======================

广发银行(CGB)支付SDK - 支持RSA/SM2/SM4加密的支付网关

v1.0.1(4mo ago)128↓100%MITPHPPHP &gt;=8.1

Since Nov 22Pushed 1w agoCompare

[ Source](https://github.com/allesx/cgb-payment-sdk)[ Packagist](https://packagist.org/packages/allesx/cgb-payment-sdk)[ RSS](/packages/allesx-cgb-payment-sdk/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (5)Used By (0)

CGB Payment SDK (PHP)
=====================

[](#cgb-payment-sdk-php)

广发银行（CGB）银企直联支付 SDK。支持请求签名（RSA-SHA1/SHA256）、SM4 对称加解密、银行公钥加密密钥、响应验签与解密、操作员密码 SM2 信封生成（可选）。

安装
--

[](#安装)

Packagist（建议）：

```
composer require allesx/cgb-payment-sdk
```

Monorepo（本仓库内 path 依赖）：

```
composer update allesx/cgb-payment-sdk
```

快速开始
----

[](#快速开始)

```
use Allesx\CgbPayment\Client\CgbClient;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$config = [
    'app_id' => '907kbk2aogw2',
    'ent_cst_no' => '60000007905',
    'ent_user_id' => '100001',
    'ent_password' => '1q2w3e4r',
    'gateway_url' => 'https://ebank-yd03.test.cgbchina.com.cn:49081/deib/E1DEIB/E101/',
    'version' => '2.0.0',
    'private_key' => __DIR__ . '/data/cert/merchant.pfx',         // 或 PEM 字符串
    'private_key_pass' => 'your_password',
    'public_key' => __DIR__ . '/data/cert/bank.cer',              // 银行公钥证书
    'bank_psw_enc_pub' => 'SM2_PUBLIC_KEY_HEX',                   // 可选：操作员密码加密公钥
    'sign_algo' => 'SHA1',                                        // 或 SHA256
    'timeout' => 30,
    'mac_address' => '',                                          // 可选：固定上送
];

$logger = new Logger('cgb');
$logger->pushHandler(new StreamHandler(__DIR__ . '/cgb.log'));

$client = new CgbClient($config, $logger);

// 示例：交易码 0021（行内/行外付款）
$body = [
    'tradeTypeNo' => 'AC0ZA001',
    'entBizDt' => '20240718',
    'entBizId' => '202407180021091902001',
    'entCstNo' => '60000007905',
    'payerAcctNo' => '100001',
    'payerAcctName' => '测试公司',
    'remark' => '备注',
    'payeeAcctNo' => '1111222233334444',
    'payeeAcctName' => '收款公司',
    'payeeBkFlag' => 'T',
    'payeeBkNo' => '307100003019',
    'payeeBkName' => '平安银行股份有限公司北京分行',
    'amount' => '1707.50',
    'postscript' => '附言',
    'addWord' => '11',
    'acBkShowFlag' => '',
];

$res = $client->request('0021', $body);
var_dump($res['parsed'] ?? $res);
```

配置项
---

[](#配置项)

- app\_id: 平台分配的 appId
- ent\_cst\_no: 企业客户号
- ent\_user\_id: 企业操作员
- ent\_password: 操作员密码（生成密码信封）
- gateway\_url: 银行网关地址（以 E101/ 结尾）
- version: 协议版本（默认 2.0.0）
- private\_key: 商户私钥（PFX/PKCS12 文件路径或 PEM 字符串）
- private\_key\_pass: 私钥密码
- public\_key: 银行公钥证书（.cer 或 PEM）
- bank\_psw\_enc\_pub: 银行下发的“操作员密码加密公钥”（16进制 SM2 公钥），可选
- sign\_algo: SHA1 或 SHA256
- timeout: 请求超时秒数
- mac\_address: 覆盖上送 MAC（可选）

特性
--

[](#特性)

- 请求签名：与银行侧保持一致的「先哈希，再十六进制字符串签名」
- 对称加解密：默认 SM4-ECB，兼容多种响应密文格式尝试解密
- 密钥加密/解密：使用银行公钥加密对称密钥、商户私钥解密
- 响应验签：与请求签名一致的验签流程，支持 SHA1 回退
- 操作员密码信封：使用 SM2 公钥生成 DER-HEX 格式，前缀 20 个 '='

测试
--

[](#测试)

```
composer install
vendor/bin/phpunit -c packages/cgb-payment-sdk/phpunit.xml.dist
```

许可
--

[](#许可)

MIT

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance89

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

120d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/20893455fcae0521e82872aa48a60c26b697bc329921925f41419335c4763f84?d=identicon)[allesx](/maintainers/allesx)

---

Top Contributors

[![allesx](https://avatars.githubusercontent.com/u/1401166?v=4)](https://github.com/allesx "allesx (4 commits)")

---

Tags

sdkpaymentgatewayBankcgbchinese-bank

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/allesx-cgb-payment-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/allesx-cgb-payment-sdk/health.svg)](https://phpackages.com/packages/allesx-cgb-payment-sdk)
```

###  Alternatives

[shetabit/multipay

PHP Payment Gateway Integration Package

291345.8k3](/packages/shetabit-multipay)[omalizadeh/laravel-multi-payment

A driver-based laravel package for online payments via multiple gateways

491.1k](/packages/omalizadeh-laravel-multi-payment)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
