PHPackages                             chenpkg/cmb - 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. chenpkg/cmb

ActiveLibrary[Payment Processing](/categories/payments)

chenpkg/cmb
===========

招商银行聚合支付 SDK

1.2.1(4y ago)420.0k↑156.7%2MITPHPPHP ^7.2.5 || ^8.0

Since Feb 4Pushed 4y ago1 watchersCompare

[ Source](https://github.com/chenpkg/cmb)[ Packagist](https://packagist.org/packages/chenpkg/cmb)[ RSS](/packages/chenpkg-cmb/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (5)Versions (18)Used By (0)

 cmb
=====

[](#-cmb-)

 招商银行聚合支付 SDK

Requirement
-----------

[](#requirement)

1. PHP &gt;= 7.2 | PHP &gt;= 8.0
2. shell\_exec 函数

由于 `sm2` 国密算法使用 `go` 实现，所以需要使用 `shell_exec` 调用命令行程序。`go` 源码 [点击这里](https://github.com/chenpkg/cmbsm2) 查看

Installing
----------

[](#installing)

```
$ composer require chenpkg/cmb -vvv
```

Usage
-----

[](#usage)

```
require './vendor/autoload.php';

use Cmb\Factory;
use Cmb\Payment\PolyPay\Client;

$config = [
    'appid'  => 'appid',
    'secret' => 'secret',
    // 商户 ID
    'mer_id' => 'mer_id',
    // 收银员 ID
    'user_id' => 'user_id',
    // 商户私钥
    'private_key' => '...',
    // 招行公钥
    'cmb_public_key' => '...',
    // 签名方法，默认使用 01(RSA2)
    'sign_method' => '01', // 01(RSA2) or 02(SM2)
    // sm2 签名程序目录，绝对路径，如果签名失败确认文件权限组、权限是否正确
    // 建议将 ./bin 目录下的 sm2 与 sm2.exe 拷贝出来，然后给予 755 权限。因为 composer update 该扩展包时，文件权限组可能会被修改
    'bin_path' => '/www/此处省略.../sm2',

    // 是否开启测试环境
    'test' => true,

    // 事件监听
    'events' => [
        // 将以下 Listener 类换成自己的 Listener 类即可
        'listen' => [
            // 请求前事件
            \Cmb\Kernel\Events\BeforeRequest::class => [
                // 支持两种监听方式
                // function ($event) { var_dump($event->base);die; }
                [new \Cmb\Kernel\Listeners\BeforeRequestListener(), 'handle']
            ],

            // 请求完成事件
            \Cmb\Kernel\Events\HttpResponseCreated::class => [
                [new \Cmb\Kernel\Listeners\HttpResponseCreatedListener(), 'handle']
            ]
        ]
    ]
];

// 扩展 api 接口, 添加宏方法
// 例如：添加银联云闪付api
Client::macro('cloudPay', function ($params) {
    // 如果需要同步验签
    return $this->requestVerify('mchorders/cloudpay', $params);
    // 不需要同步验签
    return $this->request('mchorders/cloudpay', $params);
});

$app = Factory::payment($config);

$orderId = date('YmdHis').random_int(1000, 9999);

$params = [
    'orderId'    => $orderId,
    'notifyUrl'  => 'https://localhost/payment/notify',
    'txnAmt'     => 0.1 * 100,
    'tradeScene' => 'OFFLINE',
];

// 调用自定义方法宏 api
$app->polypay->cloudPay($params);

// 二维码支付
$app->polypay->qrCode($params);

// 查询订单
$app->polypay->orderQuery($orderId);

// 订单退款
$app->polypay->refund($refundData);

// 查询退款订单
$app->polypay->refundQuery($refundOrderId);

// 关闭订单
$app->polypay->close($orderId);

// 订单二维码
$app->polypay->orderQrCode($params);

// 微信统一下单
$app->polypay->onlinePay($params);

// 支付宝服务窗支付
$app->polypay->aliServerPay($params);

// 支付宝二维码
$app->polypay->aliQrCode($params);

// 微信小程序支付
$app->polypay->miniAppOrder($params);

// 微信二维码支付
$app->polypay->wxQrCode($params);
```

消息通知
----

[](#消息通知)

```
$response = $app->handlePaidNotify(function ($message, $fail) {
    // data
    var_dump($message);

    // 你的逻辑

    return true;

    // 或者错误消息
    return $fail('Order not exists.');
});

$response->send(); // Laravel 里请使用：return $response;
```

License
-------

[](#license)

MIT

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 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 ~25 days

Recently: every ~37 days

Total

17

Last Release

1560d ago

Major Versions

0.0.2 → 1.0.02021-02-05

PHP version history (3 changes)0.0.1PHP ^7.3

1.0.0PHP ^7.3 || ^8.0

1.0.8PHP ^7.2.5 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b6f7b35a5aa35e5888dbf72ead3b664056957250b39d9bb71831a237406df9d0?d=identicon)[chen980523](/maintainers/chen980523)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/chenpkg-cmb/health.svg)

```
[![Health](https://phpackages.com/badges/chenpkg-cmb/health.svg)](https://phpackages.com/packages/chenpkg-cmb)
```

###  Alternatives

[symfony/http-kernel

Provides a structured process for converting a Request into a Response

8.1k853.6M8.3k](/packages/symfony-http-kernel)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M373](/packages/easycorp-easyadmin-bundle)[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k246.0M11.1k](/packages/symfony-framework-bundle)[symfony/security-bundle

Provides a tight integration of the Security component into the Symfony full-stack framework

2.5k181.3M2.2k](/packages/symfony-security-bundle)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19564.8M1.6k](/packages/drupal-core)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.8M712](/packages/sylius-sylius)

PHPackages © 2026

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