PHPackages                             oephpopen/allinpay-syb - 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. oephpopen/allinpay-syb

ActiveLibrary[Payment Processing](/categories/payments)

oephpopen/allinpay-syb
======================

Allinpay SYB (通联收银宝) payment SDK. Supports unified pay / query / refund / cancel / close, H5 cashier (onepay) &amp; H5 unionorder with RSA (SHA1) / RSA2 (SHA256) / SM2 signing and SM4 sensitive-field encryption. Zero framework dependency, PHP 7.2+ compatible.

1.0(yesterday)02↑2900%MITPHPPHP &gt;=7.2

Since Aug 24Pushed yesterdayCompare

[ Source](https://github.com/oephp-open/allinpay)[ Packagist](https://packagist.org/packages/oephpopen/allinpay-syb)[ RSS](/packages/oephpopen-allinpay-syb/feed)WikiDiscussions main Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (0)

oephpopen/allinpay-syb
======================

[](#oephpopenallinpay-syb)

通联收银宝（Allinpay SYB）聚合收单 SDK — PHP 7.2+，零框架依赖，可独立发布 Composer。

支持接口：**统一支付**（微信/支付宝/云闪付/数字人民币 扫码、JS、APP、微信小程序）、**统一查询**、**统一退款**、**统一撤销**、**统一交易关单**、**聚合收银台（onepay）**、**H5 收银台（unionorder）**、**异步结果通知验签**。

签名算法：RSA（SHA1WithRSA）与 RSA2（SHA256WithRSA）开箱即用；SM2 与 SM4 已预留（SM4 已含纯 PHP 实现，SM2 需第三方国密实现）。

官方入口
----

[](#官方入口)

对接、开通账号请访问：

- 通联支付官网：
- 收银宝商服平台（商户开通账号 / 商户后台）：
- 通商云开放平台（接口文档 / 开发者对接）：

环境要求
----

[](#环境要求)

- PHP &gt;= 7.2
- ext-openssl、ext-json（必须）
- ext-curl（可选，默认 `CurlHttpClient` 使用；可自行实现 `HttpClientInterface` 替换）

安装
--

[](#安装)

发布到 Packagist 后：

```
composer require oephpopen/allinpay-syb
```

统一返回（ret / msg / data）
----------------------

[](#统一返回ret--msg--data)

业务方法（`pay` / `query` / `refund` / `cancel` / `close` / `onepay` / `unionOrder` / `handleNotify`）统一返回：

```
[
    'ret'  => 1,        // 1 = 成功，0 = 失败
    'msg'  => 'ok',     // 对外提示语
    'data' => [...],    // 成功 = 网关返回字段；失败 = ['errcode' => 内部错误码, 'errmsg' => 内部详因]
]
```

- `ret = 1`：接口调用成功（网关 `retcode = SUCCESS`）。交易是否成功看 `data.trxstatus`：`0000`=已支付，`2000`/`2008`=处理中，其余=交易失败。
- `ret = 0`：调用失败，可能来自配置/参数不完整、签名/验签/网络异常或网关通信失败（`retcode != SUCCESS`）。
- `msg` 为对外提示语；`errcode` / `errmsg` 为内部错误码与详因，用于日志与排查。

业务方法不抛出异常；底层方法 `execute()` 返回 `ApiResponse` 并可抛出 SDK 异常（`ApiException` / `SignException` / `AllinpayException`），如需原始响应可自行调用。

### 错误码（`OephpOpen\AllinpaySyb\ResultCode`）

[](#错误码oephpopenallinpaysybresultcode)

errcode 常量含义msg`CONFIG_INCOMPLETE`关键配置缺失（密钥/cusid/appid/sign\_type）支付配置不完整`ENV_INVALID`环境值非法支付环境配置非法`PARAM_INVALID`业务参数不合法请求参数不合法`SIGN_FAILED`请求签名失败（商户私钥问题）请求签名失败`VERIFY_FAILED`响应/通知验签失败签名校验失败`RESPONSE_INVALID`网关响应非法（非 JSON 等）支付服务响应异常`NETWORK_ERROR`传输层失败（网络/cURL）网络请求失败，请稍后重试`GATEWAY_REJECTED`网关返回业务失败（retcode != SUCCESS）支付服务处理失败`INTERNAL_ERROR`未知异常系统繁忙，请稍后再试快速开始
----

[](#快速开始)

### 1. 配置

[](#1-配置)

凭证从后台/数据库注入（不要写死在代码里，尤其商户私钥）：

```
use OephpOpen\AllinpaySyb\Config;
use OephpOpen\AllinpaySyb\Environment;
use OephpOpen\AllinpaySyb\SignType;

$config = (new Config([
    'cusid'                => 'CUSID',       // 商户号
    'appid'                => 'APPID',              // 平台分配 appid
    'orgid'                => '',                      // 集团/代理商商户号（单商户模式留空）
    'sign_type'            => SignType::RSA,           // RSA | RSA2 | SM2
    'merchant_private_key' => '-----BEGIN PRIVATE KEY-----\n...',  // 商户私钥 PEM
    'allinpay_public_key'  => '-----BEGIN PUBLIC KEY-----\n...',   // 通联平台公钥 PEM（验签）
    'sm4_key'              => '',                      // SM4 密钥（32 位 hex，敏感字段加密用）
    'env'                  => Environment::SANDBOX,    // sandbox | production
    'notify_url'           => 'https://example.com/notify.php/allinpay/paycall',
]));
```

### 2. 客户端

[](#2-客户端)

```
use OephpOpen\AllinpaySyb\AllinpayClient;

$client = new AllinpayClient($config); // 可选：new AllinpayClient($config, $myHttpClient)
```

### 3. 下单（统一支付）

[](#3-下单统一支付)

```
// 微信小程序支付（W06）
$result = $client->pay([
    'reqsn'      => 'M202608240001',   // 商户唯一单号
    'trxamt'     => 100,               // 金额：分
    'paytype'    => 'W06',
    'body'       => '会员服务',
    'acct'       => $wxOpenid,         // 小程序 openid
    'sub_appid'  => 'wx1234567890',    // 微信小程序 appid
    'notify_url' => 'https://example.com/notify.php/allinpay/paycall',
]);

if ($result['ret'] !== 1) {
    // 失败：$result['msg'] 对外提示；$result['data']['errcode'] / ['errmsg'] 内部排查
    return $result;
}
$payInfo = $result['data']['payinfo'] ?? '';   // 小程序调起支付参数（JSON 字符串）
$trxid   = $result['data']['trxid'] ?? '';
```

常用 paytype：

- `W01` 微信扫码 / `A01` 支付宝扫码 / `U01` 云闪付扫码 / `S01` 数字人民币
- `W02` 微信公众号 JS / `A02` 支付宝 JS / `U02` 云闪付 JS
- `W03` 微信 APP / `A03` 支付宝 APP / `S03` 数字人民币 APP
- `W06` 微信小程序 / `W11` 微信订单

### 4. 聚合收银台（PC / H5）

[](#4-聚合收银台pc--h5)

```
$result = $client->onepay([
    'reqsn'      => 'M202608240002',
    'trxamt'     => 100,
    'body'       => '会员服务',
    'front_url'  => 'https://example.com/ret',          // 同步跳转（https、无参数）
    'notify_url' => 'https://example.com/notify.php/allinpay/paycall',
]);
if ($result['ret'] !== 1) {
    return $result;
}
// 网关重定向：跳转 http_build_query($result['data']) 或按需拼接支付链接
```

H5 自动选支付方式使用 `$client->unionOrder([...])`。

### 5. 查询 / 退款 / 撤销 / 关单

[](#5-查询--退款--撤销--关单)

```
$result = $client->query(['reqsn' => 'M202608240001']);          // 或 ['trxid' => $trxid]
$result = $client->refund([
    'reqsn'    => 'R202608240001',   // 退款单号（商户唯一）
    'trxamt'   => 100,
    'oldreqsn' => 'M202608240001',   // 原单号（与 oldtrxid 二选一）
]);
$result = $client->cancel(['reqsn' => 'C202608240001', 'trxamt' => 100, 'oldreqsn' => 'M202608240001']); // 当日全额
$result = $client->close(['oldreqsn' => 'M202608240001']);  // 关未支付单
```

判断交易结果统一看 `data.trxstatus`：

```
$status = $result['data']['trxstatus'] ?? '';
// '0000'        -> 交易成功（已支付）
// '2000'/'2008' -> 交易处理中
// 其它          -> 交易失败
```

### 6. 异步通知

[](#6-异步通知)

```
// $raw = file_get_contents('php://input'); // 表单编码的原始 body
$params = []; parse_str($raw, $params);

$result = $client->handleNotify($params);   // 验签失败：ret=0、errcode=VERIFY_FAILED
if ($result['ret'] !== 1) {
    echo 'fail';    // 返回非 success，通联会重发
    return;
}

$orderNo = $result['data']['cusorderid'];   // 下单时的 reqsn
$trxid   = $result['data']['trxid'];
$amt     = $result['data']['trxamt'];       // 分
// ... 幂等更新本地订单（先判断 trxstatus=0000）...

echo 'success';  // 必须返回 success，否则通联重发（15s/15s/5m/... 共 8 次）
```

> 通知字段均做了 UTF-8 urlencode；用 web 容器接收会自动解码，读原始流需自行 urldecode。

敏感字段加密（SM4）
-----------

[](#敏感字段加密sm4)

```
use OephpOpen\AllinpaySyb\Crypto\Sm4Cipher;

$name = Sm4Cipher::encrypt('张三李四', $config->getSm4Key());
// => 3IUFstZ1CNyG1D/nRprv/A==（官方测试向量一致）
$plain = Sm4Cipher::decrypt($name, $config->getSm4Key());
```

签名规范（对应官方「接口安全规范」）
------------------

[](#签名规范对应官方接口安全规范)

1. 取除 `sign` 外的所有**非空**字段；
2. 按字段名 ASCII 升序排序；
3. 拼接为 `key1=value1&key2=value2`；
4. RSA：用商户私钥 `SHA1WithRSA` 签名后 base64（RSA2 用 `SHA256WithRSA`）；SM2：`SM3WithSM2`（预留）；
5. 响应与异步通知用**通联平台公钥**验签，失败一律不处理。

测试
--

[](#测试)

```
php tests/run.php   # 无外部依赖的自测脚本（35 项），退出码 0 = 全部通过
php tests/run_all.php  # 依次运行下面 4 个主流程测试脚本
php tests/pay_test.php     # 统一支付主流程
php tests/cashier_test.php # 聚合收银台 onepay + H5 收银台 unionOrder
php tests/tranx_test.php   # 查询 / 退款 / 撤销 / 关单
php tests/notify_test.php  # 异步通知验签 + SM4 敏感字段加密
```

主流程测试脚本共享 `tests/bootstrap.php`（自动加载 SDK、生成临时 RSA 密钥对、用 `FakeHttp` 模拟网关完成 签名→请求→验签 全链路，不发起真实网络请求）。

接口清单
----

[](#接口清单)

方法接口生产地址`pay()`统一支付`https://vsp.allinpay.com/apiweb/unitorder/pay``query()`统一查询`https://vsp.allinpay.com/apiweb/tranx/query``refund()`统一退款`https://vsp.allinpay.com/apiweb/tranx/refund``cancel()`统一撤销`https://vsp.allinpay.com/apiweb/tranx/cancel``close()`统一交易关单`https://vsp.allinpay.com/apiweb/tranx/close``onepay()`聚合收银台`https://syb.allinpay.com/apiweb/h5unionpay/onepay``unionOrder()`H5 收银台`https://syb.allinpay.com/apiweb/h5unionpay/unionorder`测试环境统一走 `https://syb-test.allinpay.com`。

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance100

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

1d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/65141133?v=4)[goldenss](/maintainers/goldenss)[@goldenss](https://github.com/goldenss)

---

Top Contributors

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

---

Tags

paymentalipaywechatunionpayAllinpaysyb

### Embed Badge

![Health badge](/badges/oephpopen-allinpay-syb/health.svg)

```
[![Health](https://phpackages.com/badges/oephpopen-allinpay-syb/health.svg)](https://phpackages.com/packages/oephpopen-allinpay-syb)
```

###  Alternatives

[yansongda/pay

可能是我用过的最优雅的 Alipay 和 WeChat 的支付 SDK 扩展包了

5.4k1.3M68](/packages/yansongda-pay)[yansongda/laravel-pay

专注 Alipay/WeChat/Unipay 的 laravel 支付扩展包

1.2k375.5k13](/packages/yansongda-laravel-pay)[lokielse/omnipay-alipay

Alipay gateway for Omnipay payment processing library

586423.5k11](/packages/lokielse-omnipay-alipay)[lokielse/omnipay-wechatpay

Wechat gateway for Omnipay payment processing library

329226.4k7](/packages/lokielse-omnipay-wechatpay)[lokielse/omnipay-unionpay

UnionPay gateway for Omnipay payment processing library

11358.4k2](/packages/lokielse-omnipay-unionpay)[yansongda/hyperf-pay

可能是基于 hyperf 的最优雅的支付宝、微信、银联支付 SDK 了

9166.9k1](/packages/yansongda-hyperf-pay)

PHPackages © 2026

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