PHPackages                             yurunsoft/pay-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. yurunsoft/pay-sdk

ActiveLibrary[Payment Processing](/categories/payments)

yurunsoft/pay-sdk
=================

PHP 集成支付 SDK ，集成了支付宝、微信支付的支付接口和其它相关接口的操作。

v3.1.8(1mo ago)890104.3k—7.1%181[7 issues](https://github.com/Yurunsoft/PaySDK/issues)[1 PRs](https://github.com/Yurunsoft/PaySDK/pulls)1MITPHPPHP &gt;=5.5

Since Oct 12Pushed 1mo ago37 watchersCompare

[ Source](https://github.com/Yurunsoft/PaySDK)[ Packagist](https://packagist.org/packages/yurunsoft/pay-sdk)[ RSS](/packages/yurunsoft-pay-sdk/feed)WikiDiscussions dev Synced 2w ago

READMEChangelog (10)Dependencies (4)Versions (43)Used By (1)

PaySDK
======

[](#paysdk)

[![Latest Version](https://camo.githubusercontent.com/3a077796ca852487c1aedce1df44f8fb73d08300236fe5398492b71bce8b2bc5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f797572756e736f66742f7061792d73646b2e737667)](https://packagist.org/packages/yurunsoft/pay-sdk)[![Php Version](https://camo.githubusercontent.com/913f261430ae17dc0b7a17c7877fdf3090f36705b5ad84b40801cd47ee732ba9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d352e352d627269676874677265656e2e737667)](https://secure.php.net/)[![IMI Doc](https://camo.githubusercontent.com/8a45ed26be92338e9c97fc73a6d772a77ee94fb973e93efc89decb1ea59a8bd7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d70617373696e672d677265656e2e737667)](http://doc.yurunsoft.com/PaySDK)[![IMI License](https://camo.githubusercontent.com/93bcacfd9ad0141e803fe4becb3f2a427a464832396e32ba8081090e56bda3ad/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f597572756e736f66742f50617953444b2e737667)](https://github.com/Yurunsoft/PaySDK/blob/master/LICENSE)

介绍
--

[](#介绍)

PaySDK 是 PHP 集成支付 SDK ，集成了支付宝、微信支付的支付接口和其它相关接口的操作。

无框架依赖，支持所有框架，支持 Swoole 协程环境。

我们有完善的在线技术文档：

API 文档：

此项目进入维护阶段，不会支持微信V3接口，懒得跟着他们折腾，如有需要请找别处！

作者本人不提供任何技术支持，如有需要可以加群讨论：17916227 [![点击加群](https://camo.githubusercontent.com/75b53e353bb9e5064662e185a6d39f4bb88c4e45bd3a1240ddf599525edb6afa/68747470733a2f2f7075622e69647171696d672e636f6d2f7770612f696d616765732f67726f75702e706e67 "点击加群")](https://jq.qq.com/?_wv=1027&k=5wXf4Zq)，有没有人回复就不一定了。

大家在开发中肯定会对接各种各样的支付平台，我个人精力有限，欢迎各位来 [Github](https://github.com/Yurunsoft/PaySDK) 提交 PR，一起完善 PaySDK ，让它能够支持更多的支付平台，更加稳定可靠好用。

支持的支付接口
-------

[](#支持的支付接口)

### 支付宝

[](#支付宝)

- 即时到账-电脑网站支付（老）
- 即时到账-手机网站支付（老）
- 当面付
- 手机网站支付
- 电脑网站支付
- APP支付服务端
- 小程序支付
- 单笔转账到支付宝账户
- 海外支付（电脑网站、手机网站、APP、扫码）
- 海关报关
- 其它辅助交易接口（退款、查询等）

### 微信支付

[](#微信支付)

- 刷卡支付
- 公众号支付
- 扫码支付
- APP支付
- H5支付
- 小程序支付
- 企业付款到零钱
- 企业付款到银行卡
- 海外支付（刷卡、公众号、扫码、APP）
- 海关报关
- 其它辅助交易接口（退款、查询等）

安装
--

[](#安装)

在您的composer.json中加入配置：

`PHP >= 5.5`

```
{
    "require": {
        "yurunsoft/pay-sdk": "~3.0"
    }
}
```

`PHP >= 5.4`

```
{
    "require": {
        "yurunsoft/pay-sdk": "~2.0"
    }
}
```

> 3.x 版本支持 PHP &gt;= 5.5，持续迭代维护中

> 2.x 版本支持 PHP &gt;= 5.4，支持长期 BUG 维护，保证稳定可用，停止功能性更新

然后执行`composer update`命令。

代码示例
----

[](#代码示例)

### 支付宝即时到账

[](#支付宝即时到账)

```
// SDK实例化，传入公共配置
$pay = new \Yurun\PaySDK\Alipay\SDK($params);

// 支付接口
$request = new \Yurun\PaySDK\Alipay\Params\Pay\Request;
$request->notify_url = ''; // 支付后通知地址（作为支付成功回调，这个可靠）
$request->return_url = ''; // 支付后跳转返回地址
$request->businessParams->seller_id = $GLOBALS['PAY_CONFIG']['appid']; // 卖家支付宝用户号
$request->businessParams->out_trade_no = 'test' . mt_rand(10000000,99999999); // 商户订单号
$request->businessParams->total_fee = 0.01; // 价格
$request->businessParams->subject = '测试商品'; // 商品标题

// 跳转到支付页面
// $pay->redirectExecute($request);

// 获取跳转url
$pay->prepareExecute($request, $url);
var_dump($url);
```

### 支付宝手机网站支付

[](#支付宝手机网站支付)

```
// SDK实例化，传入公共配置
$pay = new \Yurun\PaySDK\AlipayApp\SDK($params);

// 支付接口
$request = new \Yurun\PaySDK\AlipayApp\Wap\Params\Pay\Request;
$request->notify_url = ''; // 支付后通知地址（作为支付成功回调，这个可靠）
$request->return_url = ''; // 支付后跳转返回地址
$request->businessParams->out_trade_no = 'test' . mt_rand(10000000,99999999); // 商户订单号
$request->businessParams->total_amount = 0.01; // 价格
$request->businessParams->subject = '小米手机9黑色陶瓷尊享版'; // 商品标题

// 跳转到支付页面
// $pay->redirectExecute($request);

// 获取跳转url
$pay->prepareExecute($request, $url);
var_dump($url);
```

### 微信H5支付

[](#微信h5支付)

```
// SDK实例化，传入公共配置
$pay = new \Yurun\PaySDK\Weixin\SDK($params);

// 支付接口
$request = new \Yurun\PaySDK\Weixin\H5\Params\Pay\Request;
$request->body = 'test'; // 商品描述
$request->out_trade_no = 'test' . mt_rand(10000000,99999999); // 订单号
$request->total_fee = 1; // 订单总金额，单位为：分
$request->spbill_create_ip = '127.0.0.1'; // 客户端ip
$request->notify_url = ''; // 异步通知地址

// 调用接口
$result = $pay->execute($request);
if($pay->checkResult())
{
    // 跳转支付界面
    header('Location: ' . $result['mweb_url']);
}
else
{
    var_dump($pay->getErrorCode() . ':' . $pay->getError());
}
exit;
```

### Swoole 协程环境支持

[](#swoole-协程环境支持)

在支付、退款异步通知中，需要赋值 `Swoole` 的 `Request` 和 `Response` 对象，或者遵循 PSR-7 标准的对象即可。

主流框架的 `Request` 和 `Response` 对象，一般都遵循 PSR-7 标准，可以直接使用。

#### imi 框架中使用

[](#imi-框架中使用)

imi 是基于 PHP Swoole 的高性能协程应用开发框架，它支持 HttpApi、WebSocket、TCP、UDP 服务的开发。

在 Swoole 的加持下，相比 php-fpm 请求响应能力，I/O密集型场景处理能力，有着本质上的提升。

imi 框架拥有丰富的功能组件，可以广泛应用于互联网、移动通信、企业软件、云计算、网络游戏、物联网（IOT）、车联网、智能家居等领域。可以使企业 IT 研发团队的效率大大提升，更加专注于开发创新产品。

```
/**
 * 这是一个在控制器中的动作方法
 * @Action
 */
public function test()
{
    $payNotify = new class extends \Yurun\PaySDK\Weixin\Notify\Pay
    {
        /**
         * 后续执行操作
         * @return void
         */
        protected function __exec()
        {

        }
    };
    $context = RequestContext::getContext();
    // 下面两行很关键
    $payNotify->swooleRequest = $context['request'];
    $payNotify->swooleResponse = $context['response'];

    $sdk->notify($payNotify);

    // 这句话必须填写
    return $payNotify->swooleResponse;
}
```

#### 其它框架（Swoole 对象）

[](#其它框架swoole-对象)

```
$payNotify = new class extends \Yurun\PaySDK\Weixin\Notify\Pay
{
    /**
     * 后续执行操作
     * @return void
     */
    protected function __exec()
    {

    }
};
// 下面两行很关键，$request、$response 从 request 中获取
// 或者查阅如何从你使用的框架中获取
$payNotify->swooleRequest = $request;
$payNotify->swooleResponse = $response;

$sdk->notify($payNotify);
```

#### 其它框架（PSR-7 对象）

[](#其它框架psr-7-对象)

```
$payNotify = new class extends \Yurun\PaySDK\Weixin\Notify\Pay
{
    /**
     * 后续执行操作
     * @return void
     */
    protected function __exec()
    {

    }
};
// 目前主流 Swoole 基本都支持 PSR-7 标准的对象
// 所以可以直接传入，如何获取请查阅对应框架的文档
$payNotify->swooleRequest = $request;
$payNotify->swooleResponse = $response;

$sdk->notify($payNotify);

// 处理完成后需要将 $response 从控制器返回或者赋值给上下文
// 不同框架的操作不同，请自行查阅对应框架的文档
return $payNotify->swooleResponse;
```

商业服务
----

[](#商业服务)

**服务内容：**

- 低费率开户（仅合法商户）
- 问题排查及咨询
- 代接支付
- 其它合作

如有需要加QQ：`369124067` 微信：`wx_zhangrunyu`（注明来意）

捐赠
--

[](#捐赠)

[![](https://raw.githubusercontent.com/Yurunsoft/PaySDK/master/res/pay.png)](https://raw.githubusercontent.com/Yurunsoft/PaySDK/master/res/pay.png)

开源不求盈利，多少都是心意，生活不易，随缘随缘……

###  Health Score

66

—

FairBetter than 99% of packages

Maintenance93

Actively maintained with recent releases

Popularity56

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 94.2% 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 ~80 days

Recently: every ~409 days

Total

41

Last Release

30d ago

Major Versions

v1.0.12 → v2.02018-07-09

v2.x-dev → v3.0.02020-03-24

PHP version history (3 changes)v1.0.4PHP ^5.4|^7.0

v3.0.0PHP &gt;=7.1

v3.0.1PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f917bb42280d114c53cebadc2942a13ee03abe14971089f88895e266d637169?d=identicon)[Yurunsoft](/maintainers/Yurunsoft)

---

Top Contributors

[![Yurunsoft](https://avatars.githubusercontent.com/u/20104656?v=4)](https://github.com/Yurunsoft "Yurunsoft (179 commits)")[![lvjiaben](https://avatars.githubusercontent.com/u/90166263?v=4)](https://github.com/lvjiaben "lvjiaben (4 commits)")[![LRRun](https://avatars.githubusercontent.com/u/37306014?v=4)](https://github.com/LRRun "LRRun (2 commits)")[![lanshe](https://avatars.githubusercontent.com/u/672378?v=4)](https://github.com/lanshe "lanshe (1 commits)")[![anxiaowen](https://avatars.githubusercontent.com/u/22000601?v=4)](https://github.com/anxiaowen "anxiaowen (1 commits)")[![l1n6yun](https://avatars.githubusercontent.com/u/19780706?v=4)](https://github.com/l1n6yun "l1n6yun (1 commits)")[![sy-records](https://avatars.githubusercontent.com/u/33931153?v=4)](https://github.com/sy-records "sy-records (1 commits)")[![BadmintonCode](https://avatars.githubusercontent.com/u/17247494?v=4)](https://github.com/BadmintonCode "BadmintonCode (1 commits)")

---

Tags

alipay-sdkalipaysdkcoroutinepaymentpaysdkphpswooleweixin-pay

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/yurunsoft-pay-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/yurunsoft-pay-sdk/health.svg)](https://phpackages.com/packages/yurunsoft-pay-sdk)
```

###  Alternatives

[pagseguro/php

Biblioteca de integração com o PagSeguro

23260.3k6](/packages/pagseguro-php)

PHPackages © 2026

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