spore / payment
A modern PHP 8.0+ payment library supporting multiple payment gateways
v1.0.1
2026-02-23 05:39 UTC
Requires
- php: ^8.0
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
- ext-simplexml: *
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^9.5|^10.0
- squizlabs/php_codesniffer: ^3.0
This package is not auto-updated.
Last update: 2026-02-24 04:08:11 UTC
README
一个现代化的 PHP 8.0+ 支付库,支持多种支付网关,包括微信支付、支付宝、QQ支付、银联等45个支付插件。
特性
- PHP 8.0+ 严格类型声明
- PSR-4/PSR-12 标准编码规范
- 统一接口 45个支付插件统一调用接口
- 配置整合 相同支付方式的配置整合
- GuzzleHTTP 基于 GuzzleHTTP 的 HTTP 客户端
- 自动适配 自动生成适配器,兼容旧版插件
- 扩展性强 支持自定义网关和适配器
支持的支付方式(45个插件)
微信支付系列 (4个)
wxpay- 微信官方支付wxpayn- 微信支付(新版)wxpaynp- 微信支付(非官方)wxpaysl- 微信支付(手续费版)
支付宝系列 (6个)
alipay- 支付宝官方支付aliold- 支付宝旧版alipaybill- 支付宝账单alipayd- 支付宝D版alipayrp- 支付宝退款版alipaysl- 支付宝手续费版
QQ支付 (1个)
qqpay- QQ钱包支付
银联/银行支付 (3个)
unionpay- 银联支付chinaums- 银联在线支付allinpay- 通联支付
第三方支付 (30+个)
swiftpass- 威富通swiftpass2- 威富通2jeepay- 极支付epay- 易支付xorpay- XorPayxunhupay- 虎皮椒支付ympay- YM支付ysepay- 银盛支付duolabao- 哆啦宝huifu- 汇付jdpay- 京东支付sandpay- 杉德支付umfpay- 联动支付fubei- 付贝fuiou- 付钱拉heepay- 汇付宝hnapay- 海鸟支付jinyihui- 金一汇kayixin- 凯易信ltzf- 龙腾支付mirfupay- 米富支付passpay- 帕斯支付vmq- VMQwoaizf- 我爱支付zhangyishou- 章鱼手zyu- ZYU
国际支付 (2个)
stripe- Stripepaypal- PayPal
安装
composer require spore/payment-gateway
快速开始
初始化应用
<?php
declare(strict_types=1);
use Payment\Payment\Manager;
$config = [
// 默认支付方式
'default' => 'wechat',
// 微信支付配置
'wechat' => [
'appid' => 'wx1234567890',
'mch_id' => '1234567890',
'secret_key' => 'your_v3_secret_key',
'v2_secret_key' => 'your_v2_secret_key',
'private_key' => 'your_private_key',
'certificate' => 'your_certificate',
],
// 支付宝配置
'alipay' => [
'appid' => '2021234567890',
'private_key' => 'your_private_key',
'public_key' => 'your_public_key',
],
// QQ支付配置
'qqpay' => [
'appid' => 'your_qq_appid',
'mch_id' => 'your_qq_mchid',
'secret_key' => 'your_qq_secret_key',
],
// 第三方支付配置(以威富通为例)
'swiftpass' => [
'appid' => 'your_swiftpass_appid',
'appmchid' => 'your_swiftpass_mchid',
'appkey' => 'your_swiftpass_key',
'api_url' => 'https://pay.swiftpass.com/api',
],
];
$app = new Manager($config);
使用微信支付
// 微信扫码支付
$wechat = $app->wechat();
$response = $wechat->pay([
'out_trade_no' => 'ORDER' . time(),
'total_fee' => 100, // 单位:分
'body' => '商品描述',
'trade_type' => 'native',
]);
$qrCodeUrl = $response->get('code_url');
使用支付宝支付
// 支付宝电脑网站支付
$alipay = $app->alipay();
$response = $alipay->pay([
'out_trade_no' => 'ORDER' . time(),
'total_amount' => '1.00',
'subject' => '商品标题',
'product_code' => 'FAST_INSTANT_TRADE_PAY',
]);
使用微信支付系列其他版本
// 微信支付新版
$wxpayn = $app->gateway('wxpayn');
$response = $wxpayn->pay([...]);
// 微信支付非官方版
$wxpaynp = $app->gateway('wxpaynp');
$response = $wxpaynp->pay([...]);
// 微信支付手续费版
$wxpaysl = $app->gateway('wxpaysl');
$response = $wxpaysl->pay([...]);
使用支付宝系列其他版本
// 支付宝旧版
$aliold = $app->gateway('aliold');
$response = $aliold->pay([...]);
// 支付宝账单
$alipaybill = $app->gateway('alipaybill');
$response = $alipaybill->pay([...]);
使用QQ支付
$qqpay = $app->qqpay();
$response = $qqpay->pay([
'out_trade_no' => 'ORDER' . time(),
'total_fee' => 100,
'body' => '商品描述',
'trade_type' => 'native',
]);
使用银联支付
$unionpay = $app->gateway('unionpay');
$response = $unionpay->pay([
'out_trade_no' => 'ORDER' . time(),
'total_fee' => 100,
'body' => '商品描述',
'trade_type' => 'page',
]);
使用第三方支付(以威富通为例)
$swiftpass = $app->gateway('swiftpass');
$response = $swiftpass->pay([
'out_trade_no' => 'ORDER' . time(),
'total_fee' => 100,
'body' => '商品描述',
'trade_type' => 'native',
]);
使用国际支付
// Stripe支付
$stripe = $app->gateway('stripe');
$response = $stripe->pay([
'out_trade_no' => 'ORDER' . time(),
'total_amount' => '10.00',
'currency' => 'usd',
'description' => 'Product description',
'payment_method' => 'card',
]);
// PayPal支付
$paypal = $app->gateway('paypal');
$response = $paypal->pay([
'out_trade_no' => 'ORDER' . time(),
'total_amount' => '10.00',
'description' => 'Product description',
]);
配置
完整配置请参考 config/payment.php
插件适配器
所有45个支付插件都已通过适配器模式整合到新架构中:
- 原生网关类 - wxpay、alipay 等官方支付使用原生实现的网关类
- 专用适配器 - wxpayn、wxpaynp、aliold 等使用专用适配器
- 通用适配器 - 其他插件使用通用适配器自动适配
开发规范
本项目严格遵循 CLAUDE.md 中定义的编码规范。
测试
composer test
许可证
MIT License