pay is a free, open source e-commerce platforms project written in PHP and released under MIT. It has 5,367 GitHub stars, 1,052 forks and 6 open issues, and was last pushed 7 days ago. On this registry it ranks #13 of 30 tracked projects in E-commerce Platforms, with 5 head-to-head comparisons available.

What is pay?

What it is

Yansongda Pay is an open-source PHP payment SDK that provides a unified interface to multiple Chinese payment gateways, including Alipay, WeChat, Douyin, Unipay, Jiangsu Bank, Tonglian Pay, and BestPay. It lives in the PHP ecosystem and is distributed as a Composer package under the MIT license. The project has been maintained for nine years, carries 5,367 stars and 1,052 forks, and its most recent push was on 11 September 2026. Framework-specific wrappers exist for Laravel, Hyperf, and Yii, while the core package remains framework-agnostic.

The concrete problem it solves is the repetitive, error-prone work of integrating Chinese payment providers one by one. Each gateway ships its own signing rules, certificate handling, callback verification, and request formats, and developers normally end up writing the same glue code repeatedly. This SDK abstracts those differences behind a consistent configuration array and method surface, so a developer can call Pay::alipay()->web() or Pay::wechat()->scan() without hand-assembling JSON or XML payloads. It also removes the pain of first-time WeChat certificate retrieval by fetching the public certificate automatically.

Key capabilities

  • Unified gateway coverage for Alipay, WeChat, Douyin, Unipay, Jiangsu Bank eRong Pay, Tonglian Pay, and BestPay, each with its own set of supported payment methods.
  • Plugin mechanism that allows adding payment gateways not included in the project, and that makes the built-in gateways 100 percent compatible with the full feature sets of Alipay, WeChat, and Unipay, including service-provider functions.
  • Multi-tenant support, with service-provider mode configured through service_provider_id, sub_mch_id, and related sub-app identifiers.
  • Swoole support for coroutine-based runtimes.
  • Event system for hooking into payment lifecycle points.
  • Compliance with PSR-2, PSR-3, PSR-4, PSR-7, PSR-11, PSR-14, and PSR-18, allowing integration with arbitrary PHP frameworks.
  • Built-in automatic retrieval of the WeChat public certificate, plus configurable logging and Guzzle-based HTTP timeouts.

Who uses it and how

  • Laravel developers install the yansongda/laravel-pay wrapper and call the SDK from controllers or service classes.
  • Hyperf users install the yansongda/hyperf-pay wrapper to run payments inside a Swoole coroutine environment.
  • Yii developers use the guanguans/yii-pay wrapper maintained separately.
  • Merchants operating in service-provider mode configure sub-merchant identifiers to process payments on behalf of multiple sellers.
  • Teams handling asynchronous notifications implement callback handlers that verify signatures and
project readme (upstream, from github) — read inline

Logo

scrutinizer Tester Status Code Coverage Status Coding Style Status Stable Version Total Downloads License

前言

v3 版与 v2 版在底层有很大的不同,基础架构做了重新的设计,更易扩展,使用起来更方便。

开发了多次支付宝与微信支付后,很自然产生一种反感,惰性又来了,想在网上找相关的轮子,可是一直没有找到一款自己觉得逞心如意的,要么使用起来太难理解,要么文件结构太杂乱,只有自己撸起袖子干了。

欢迎 Star,欢迎 PR!

hyperf 扩展包请 传送至这里

laravel 扩展包请 传送至这里

yii 扩展包请 传送至这里

特点

  • 多租户支持
  • Swoole 支持
  • 灵活的插件机制
  • 丰富的事件系统
  • 命名不那么乱七八糟
  • 隐藏开发者不需要关注的细节
  • 根据支付宝、微信最新 API 开发而成
  • 高度抽象的类,免去各种拼json与xml的痛苦
  • 文件结构清晰易理解,可以随心所欲添加本项目中没有的支付网关
  • 方法使用更优雅,不必再去研究那些奇怪的的方法名或者类名是做啥用的
  • 内置自动获取微信公共证书方法,再也不用再费劲去考虑第一次获取证书的的问题了
  • 符合 PSR2、PSR3、PSR4、PSR7、PSR11、PSR14、PSR18 等各项标准,你可以各种方便的与你的框架集成

版本计划

https://pay.yansongda.cn/docs/v3/overview/planning

详细文档

https://pay.yansongda.cn

支持的支付方法

yansongda/pay 100% 兼容 支付宝/微信/银联 所有功能(包括服务商功能),只需通过「插件机制」引入即可。

同时,SDK 直接支持内置了以下插件,详情请查阅文档。

支付宝

  • 电脑支付
  • 手机网站支付
  • APP 支付
  • 刷卡支付
  • 扫码支付
  • 账户转账
  • 小程序支付
  • ...

微信

  • 公众号支付
  • 小程序支付
  • H5 支付
  • 扫码支付
  • APP 支付
  • 刷卡支付
  • ...

抖音

  • 小程序支付(通用交易系统,JSAPI 下单签名)
  • 订单查询
  • CPS 查询
  • 退款
  • 退款审核
  • 支付/退款/退款申请回调
  • ...

银联

  • 手机网站支付
  • 电脑网站支付
  • 刷卡支付
  • 扫码支付
  • ...

江苏银行(e融支付)

  • 聚合扫码支付(微信,支付宝,银联,e融)
  • ...

通联支付

  • 统一支付(微信/支付宝/银联等 paytype)
  • 被扫/主扫支付
  • 查询、确认查询、退款、撤销、关单

翼支付(BestPay)

  • PC 收银台(超级收银台)
  • 手机收银台
  • 聚合收款码
  • 订单查询 / 退款 / 关单
  • 支付/退款回调(证书验签)
  • ...

安装

composer require yansongda/pay:~3.7.0 -vvv

深情一撇

支付宝

<?php

namespace App\Http\Controllers;

use Yansongda\Pay\Pay;

class AlipayController
{
    protected $config = [
        'alipay' => [
            'default' => [
                // 必填-支付宝分配的 app_id
                'app_id' => '2016082000295641',
                // 必填-应用私钥 字符串或路径
                'app_secret_cert' => '89iZ2iC16H6/6a3YcP+hDZUjiNGQx9cuwi9eJyykvcwhD...',
                // 必填-应用公钥证书 路径
                'app_public_cert_path' => '/Users/yansongda/pay/cert/appCertPublicKey_2016082000295641.crt',
                // 必填-支付宝公钥证书 路径
                'alipay_public_cert_path' => '/Users/yansongda/pay/cert/alipayCertPublicKey_RSA2.crt',
                // 必填-支付宝根证书 路径
                'alipay_root_cert_path' => '/Users/yansongda/pay/cert/alipayRootCert.crt',
                'return_url' => 'https://yansongda.cn/alipay/return',
                'notify_url' => 'https://yansongda.cn/alipay/notify',
                // 选填-第三方应用授权token
                'app_auth_token' => '',
                // 选填-服务商模式下的服务商 id,当 mode 为 Pay::MODE_SERVICE 时使用该参数
                'service_provider_id' => '',
                // 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SANDBOX, MODE_SERVICE
                'mode' => Pay::MODE_NORMAL,
            ],       
        ],   
        'logger' => [ // optional
            'enable' => false,
            'file' => './logs/alipay.log',
            'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
            'type' => 'single', // optional, 可选 daily.
            'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
        ],
        'http' => [ // optional
            'timeout' => 5.0,
            'connect_timeout' => 5.0,
            // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
        ],
    ];

    public function web()
    {
        Pay::config($this->config);
        
        $result = Pay::alipay()->web([
            'out_trade_no' => ''.time(),
            'total_amount' => '0.01',
            'subject' => 'yansongda 测试 - 1',
        ]);
        
        return $result;
    }

    public function returnCallback()
    {
        Pay::config($this->config);
    
        $data = Pay::alipay()->callback(); // 是的,验签就这么简单!

        // 订单号:$data->out_trade_no
        // 支付宝交易号:$data->trade_no
        // 订单总金额:$data->total_amount
    }

    public function notifyCallback()
    {
        Pay::config($this->config);
        
        try{
            $data = Pay::alipay()->callback(); // 是的,验签就这么简单!

            // 请自行对 trade_status 进行判断及其它逻辑进行判断,在支付宝的业务通知中,只有交易通知状态为 TRADE_SUCCESS 或 TRADE_FINISHED 时,支付宝才会认定为买家付款成功。
            // 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号;
            // 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额);
            // 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email);
            // 4、验证app_id是否为该商户本身。
            // 5、其它业务逻辑情况
        } catch (\Throwable $e) {
            dd($e);
        }

        return Pay::alipay()->success();
    }
}

微信

<?php

namespace App\Http\Controllers;

use Yansongda\Pay\Pay;

class WechatController
{
    protected $config = [
        'wechat' => [
            'default' => [
                // 必填-商户号
                'mch_id' => '',
                // 选填-v2商户私钥
                'mch_secret_key_v2' => '',
                // 必填-v3商户秘钥
                'mch_secret_key' => '',
                // 必填-商户私钥 字符串或路径
                'mch_secret_cert' => '',
                // 必填-商户公钥证书路径
                'mch_public_cert_path' => '',
                // 必填
                'notify_url' => 'https://yansongda.cn/wechat/notify',
                // 选填-公众号 的 app_id
                'mp_app_id' => '',
                // 选填-小程序 的 app_id
                'mini_app_id' => '',
                // 选填-app 的 app_id
                'app_id' => '',
                // 选填-服务商模式下,子公众号 的 app_id
                'sub_mp_app_id' => '',
                // 选填-服务商模式下,子 app 的 app_id
                'sub_app_id' => '',
                // 选填-服务商模式下,子小程序 的 app_id
                'sub_mini_app_id' => '',
                // 选填-服务商模式下,子商户id
                'sub_mch_id' => '',
                // 选填-微信平台公钥证书路径, optional,强烈建议 php-fpm 模式下配置此参数
                'wechat_public_cert_path' => [
                    '45F59D4DABF31918AFCEC556D5D2C6E376675D57' => __DIR__.'/Cert/wechatpay_45F***D57.pem',
                ],
                // 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SERVICE
                'mode' => Pay::MODE_NORMAL,
            ]
        ],
        'logger' => [ // optional
            'enable' => false,
            'file' => './logs/wechat.log',
            'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
            'type' => 'single', // optional, 可选 daily.
            'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
        ],
        'http' => [ // optional
            'timeout' => 5.0,
            'connect_timeout' => 5.0,
            // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
        ],
    ];

    public function index()
    {
        Pay::config($this->config);
        
        $order = [
            'out_trade_no' => time().'',
            'description' => 'subject-测试',
            'amount' => [
                 'total' => 1,
            ],
            'payer' => [
                 'openid' => 'onkVf1FjWS5SBxxxxxxxx',
            ],
        ];

        $pay = Pay::wechat()->mp($order);

        // $pay->appId
        // $pay->timeStamp
        // $pay->nonceStr
        // $pay->package
        // $pay->signType
    }

    public function callback()
    {
        Pay::config($this->config);
        
        try{
            $data = Pay::wechat()->callback(); // 是的,验签就这么简单!
        } catch (\Throwable $e) {
            dd($e);
        }
        
        return Pay::wechat()->success();
    }
}

抖音

<?php

namespace App\Http\Controllers;

use Psr\Http\Message\ServerRequestInterface;
use Yansongda\Pay\Pay;

class DouyinController
{
    p

readme truncated — read the full docs on github

Frequently asked questions

Is pay free to use?

pay is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does pay do?

可能是我用过的最优雅的 Alipay/WeChat/Douyin/Unipay/江苏银行 的支付 SDK 扩展包了

What is pay written in?

pay is primarily written in PHP. Its source is publicly available at https://github.com/yansongda/pay, and it has 5,367 GitHub stars.