PHPackages                             super-vle/easy\_pay - 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. super-vle/easy\_pay

ActiveLibrary[Payment Processing](/categories/payments)

super-vle/easy\_pay
===================

PHP支付集成组件，支持微信支付、微信合作平台（服务商模式）、支付宝等常见支付方式

1.0.0(1mo ago)00MITPHPPHP &gt;=7.4

Since Jul 13Pushed 1mo agoCompare

[ Source](https://github.com/super-vle/easy_pay)[ Packagist](https://packagist.org/packages/super-vle/easy_pay)[ RSS](/packages/super-vle-easy-pay/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

EasyPay
=======

[](#easypay)

PHP 支付集成组件，统一封装微信支付、微信合作平台（服务商模式）、支付宝、慧收款（宝付聚合支付）等常见支付方式，提供一致的 API 调用体验。

支持的支付方式
-------

[](#支持的支付方式)

支付网关类名说明微信支付`Wechat\WechatPay`普通商户模式，支持 JSAPI/APP/H5/Native/付款码微信合作平台`Wechat\PartnerPay`服务商模式，支持子商户管理支付宝`Alipay\Alipay`支持电脑网站/手机网站/APP/扫码/JSAPI慧收款`Huishouqian\Huishouqian`宝付聚合支付，支持全场景支付/查询/退款/通知环境要求
----

[](#环境要求)

- PHP &gt;= 7.4
- ext-json
- ext-openssl
- ext-curl
- Composer

安装
--

[](#安装)

```
composer require easy/easy_pay
```

快速开始
----

[](#快速开始)

### 微信支付（普通商户）

[](#微信支付普通商户)

```
use EasyPay\EasyPay;

$wechat = EasyPay::wechat([
    'app_id'     => '你的公众号/小程序/APP的AppID',
    'mch_id'     => '你的商户号',
    'api_key'    => '你的API密钥',
    'notify_url' => 'https://your-domain.com/notify/wechat',
]);

// JSAPI 支付（公众号/小程序）
$result = $wechat->pay([
    'body'         => '测试商品',
    'out_trade_no' => 'ORDER20231201001',
    'total_fee'    => 1,  // 金额单位：分
    'trade_type'   => 'JSAPI',
    'openid'       => '用户的openid',
]);
// 返回前端调起支付所需的参数

// Native 扫码支付
$result = $wechat->pay([
    'body'         => '扫码测试商品',
    'out_trade_no' => 'ORDER20231201002',
    'total_fee'    => 100,
    'trade_type'   => 'NATIVE',
]);
// $result['code_url'] 为支付二维码链接

// APP 支付
$result = $wechat->pay([
    'body'         => 'APP商品',
    'out_trade_no' => 'ORDER20231201003',
    'total_fee'    => 100,
    'trade_type'   => 'APP',
]);

// H5 支付
$result = $wechat->pay([
    'body'         => 'H5商品',
    'out_trade_no' => 'ORDER20231201004',
    'total_fee'    => 100,
    'trade_type'   => 'MWEB',
    'scene_info'   => json_encode([
        'h5_info' => ['type' => 'Wap', 'wap_url' => 'https://your-domain.com', 'wap_name' => '测试网站']
    ]),
]);
```

### 微信合作平台（服务商模式）

[](#微信合作平台服务商模式)

```
use EasyPay\EasyPay;

$partner = EasyPay::wechatPartner([
    'app_id'     => '服务商AppID',
    'mch_id'     => '服务商商户号',
    'sub_mch_id' => '子商户商户号',
    'sub_app_id' => '子商户AppID（可选）',
    'api_key'    => 'API密钥',
    'notify_url' => 'https://your-domain.com/notify/wechat',
]);

// 服务商为子商户发起支付（参数与普通模式类似，自动附加子商户信息）
$result = $partner->pay([
    'body'         => '子商户商品',
    'out_trade_no' => 'SUB20231201001',
    'total_fee'    => 100,
    'trade_type'   => 'JSAPI',
    'openid'       => '用户的openid',
]);
```

### 支付宝

[](#支付宝)

```
use EasyPay\EasyPay;

$alipay = EasyPay::alipay([
    'app_id'            => '你的支付宝AppID',
    'private_key'       => '/path/to/private_key.pem',       // 应用私钥路径或内容
    'alipay_public_key' => '/path/to/alipay_public_key.pem', // 支付宝公钥路径或内容
    'notify_url'        => 'https://your-domain.com/notify/alipay',
    'return_url'        => 'https://your-domain.com/return/alipay',
    'sign_type'         => 'RSA2',  // RSA 或 RSA2
]);

// 电脑网站支付（返回自动提交的 HTML 表单）
$html = $alipay->pagePay([
    'subject'      => '测试商品',
    'out_trade_no' => 'ALI20231201001',
    'total_amount' => '0.01',  // 金额单位：元
    'body'         => '商品描述',
]);
echo $html;

// 手机网站支付
$result = $alipay->wapPay([
    'subject'      => '手机商品',
    'out_trade_no' => 'ALI20231201002',
    'total_amount' => '0.01',
]);

// APP 支付（返回参数字符串）
$paramStr = $alipay->appPay([
    'subject'      => 'APP商品',
    'out_trade_no' => 'ALI20231201003',
    'total_amount' => '0.01',
]);

// 扫码支付
$result = $alipay->preCreate([
    'subject'      => '扫码商品',
    'out_trade_no' => 'ALI20231201004',
    'total_amount' => '0.01',
]);

// 付款码支付
$result = $alipay->barCodePay([
    'subject'      => '付款码商品',
    'out_trade_no' => 'ALI20231201005',
    'total_amount' => '0.01',
    'auth_code'    => '用户付款码',
]);
```

### 慧收款（宝付聚合支付）

[](#慧收款宝付聚合支付)

```
use EasyPay\EasyPay;

$hsq = EasyPay::huishouqian([
    'mer_id'      => '宝付分配的商户号',
    'ter_id'      => '宝付分配的终端号',
    'private_key' => '/path/to/private_key.pem',   // 商户私钥
    'public_key'  => '/path/to/public_key.pem',    // 宝付平台公钥
    'sign_type'   => 'RSA',  // RSA 或 SM2（国密）
    'notify_url'  => 'https://your-domain.com/notify/huishouqian',
]);

// JSAPI 支付（公众号/小程序）
$result = $hsq->payJsapi([
    'body'         => '测试商品',
    'out_trade_no' => 'HSQ20231201001',
    'total_amount' => '0.01',  // 金额单位：元
    'openid'       => '用户的openid',
]);

// APP 支付
$result = $hsq->payApp([
    'body'         => 'APP商品',
    'out_trade_no' => 'HSQ20231201002',
    'total_amount' => '0.01',
]);

// H5 支付
$result = $hsq->payH5([
    'body'         => 'H5商品',
    'out_trade_no' => 'HSQ20231201003',
    'total_amount' => '0.01',
]);

// PC 支付
$result = $hsq->payPc([
    'body'         => 'PC商品',
    'out_trade_no' => 'HSQ20231201004',
    'total_amount' => '0.01',
]);

// 主扫支付（用户扫码）
$result = $hsq->masterScan([
    'body'         => '扫码商品',
    'out_trade_no' => 'HSQ20231201005',
    'total_amount' => '0.01',
]);
// $result['code_url'] 为二维码链接

// 被扫支付（商户扫用户付款码）
$result = $hsq->microPay([
    'body'         => '付款码商品',
    'out_trade_no' => 'HSQ20231201006',
    'total_amount' => '0.01',
    'auth_code'    => '用户付款码',
]);

// 综合支付（前端自动选择支付方式）
$result = $hsq->composite([
    'body'         => '综合商品',
    'out_trade_no' => 'HSQ20231201007',
    'total_amount' => '0.01',
]);

// 查询订单
$order = $hsq->query('HSQ20231201001');

// 关闭订单
$hsq->close('HSQ20231201001');

// 申请退款
$refund = $hsq->refund([
    'out_trade_no'  => 'HSQ20231201001',
    'out_refund_no' => 'RF20231201001',
    'total_amount'  => '0.01',
    'refund_amount' => '0.01',
    'refund_reason' => '用户申请退款',
]);

// 处理回调
try {
    $data = $hsq->notify();  // 自动验签
    // 处理业务逻辑
    echo $hsq->replySuccess();  // 返回 "OK"
} catch (\EasyPay\Exceptions\PaymentException $e) {
    echo $hsq->replyFail();
}
```

通用操作
----

[](#通用操作)

### 订单查询

[](#订单查询)

```
// 微信
$order = $wechat->query('ORDER20231201001');

// 支付宝
$order = $alipay->query('ALI20231201001');
```

### 关闭订单

[](#关闭订单)

```
// 微信
$wechat->close('ORDER20231201001');

// 支付宝
$alipay->close('ALI20231201001');
```

### 申请退款

[](#申请退款)

```
// 微信
$refund = $wechat->refund([
    'out_trade_no'  => 'ORDER20231201001',
    'out_refund_no' => 'RF20231201001',
    'total_fee'     => 100,   // 原订单金额（分）
    'refund_fee'    => 50,    // 退款金额（分）
    'refund_desc'   => '用户申请退款',
]);

// 支付宝
$refund = $alipay->refund([
    'out_trade_no'   => 'ALI20231201001',
    'out_request_no' => 'RF20231201001',
    'refund_amount'  => '0.01',  // 退款金额（元）
    'refund_reason'  => '用户申请退款',
]);
```

### 查询退款

[](#查询退款)

```
// 微信
$refundInfo = $wechat->queryRefund('RF20231201001');

// 支付宝
$refundInfo = $alipay->queryRefund('RF20231201001');
```

### 处理支付回调通知

[](#处理支付回调通知)

```
// 微信
try {
    $data = $wechat->notify();  // 自动验签
    // 根据 $data['out_trade_no'] 处理业务逻辑
    echo $wechat->replySuccess();
} catch (\EasyPay\Exceptions\PaymentException $e) {
    echo $wechat->replyFail($e->getMessage());
}

// 支付宝
try {
    $data = $alipay->notify();  // 自动验签
    // 处理业务逻辑
    echo $alipay->replySuccess();
} catch (\EasyPay\Exceptions\PaymentException $e) {
    echo $alipay->replyFail();
}
```

微信 v3 API（可选）
-------------

[](#微信-v3-api可选)

```
// JSAPI v3
$result = $wechat->payJsapi([
    'description'  => '测试商品',
    'out_trade_no' => 'ORDER20231201001',
    'amount'       => ['total' => 1, 'currency' => 'CNY'],
    'openid'       => '用户的openid',
]);

// Native v3
$result = $wechat->payNative([
    'description'  => '测试商品',
    'out_trade_no' => 'ORDER20231201002',
    'amount'       => ['total' => 1, 'currency' => 'CNY'],
]);
```

异常处理
----

[](#异常处理)

```
use EasyPay\Exceptions\PaymentException;
use EasyPay\Exceptions\InvalidConfigException;

try {
    $result = $wechat->pay([...]);
} catch (InvalidConfigException $e) {
    // 配置错误
    echo "配置错误: " . $e->getMessage();
} catch (PaymentException $e) {
    // 支付业务异常
    echo "支付失败: " . $e->getMessage();
    echo "错误码: " . $e->getErrorCode();
    print_r($e->getRaw());  // 原始响应数据
}
```

目录结构
----

[](#目录结构)

```
easy_pay/
├── composer.json
├── src/
│   ├── EasyPay.php              # 主入口类
│   ├── AbstractPayment.php      # 抽象基类
│   ├── Contracts/
│   │   └── PaymentInterface.php # 支付接口契约
│   ├── Exceptions/
│   │   ├── PaymentException.php # 支付异常
│   │   └── InvalidConfigException.php
│   ├── Wechat/
│   │   ├── WechatPay.php        # 微信支付（普通商户）
│   │   └── PartnerPay.php       # 微信支付（服务商模式）
│   ├── Alipay/
│   │   └── Alipay.php                # 支付宝支付
│   ├── Huishouqian/
│   │   └── Huishouqian.php          # 慧收款（宝付聚合支付）
│   └── Support/
│       ├── Config.php           # 配置管理
│       ├── HttpClient.php       # HTTP 客户端
│       └── Utils.php            # 工具方法

```

License
-------

[](#license)

MIT

###  Health Score

34

—

LowBetter than 74% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 75% 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

48d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/221994428?v=4)[super-vle](/maintainers/super-vle)[@super-vle](https://github.com/super-vle)

---

Top Contributors

[![super-vle](https://avatars.githubusercontent.com/u/221994428?v=4)](https://github.com/super-vle "super-vle (3 commits)")[![chenvle](https://avatars.githubusercontent.com/u/41420442?v=4)](https://github.com/chenvle "chenvle (1 commits)")

---

Tags

paymentalipaywechatwechat-pay

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/super-vle-easy-pay/health.svg)

```
[![Health](https://phpackages.com/badges/super-vle-easy-pay/health.svg)](https://phpackages.com/packages/super-vle-easy-pay)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

35.4k569.8M21.9k](/packages/laravel-framework)[craftcms/cms

Craft CMS

3.6k3.7M3.5k](/packages/craftcms-cms)[tempest/framework

The PHP framework that gets out of your way.

2.3k42.4k21](/packages/tempest-framework)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k4.0M551](/packages/pimcore-pimcore)[google/cloud

Google Cloud Client Library

1.2k17.1M58](/packages/google-cloud)[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

350141.3M156](/packages/google-cloud-core)

PHPackages © 2026

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