开发了多次支付,每次都要翻文档、找之前的项目复制过来,费时费事,为了便于支付的开发,
干脆自己去造了一个简单轮子,整合支付(微信、支付宝、银联、百度、字节跳动)相关开发。
!!请先熟悉 相关支付 说明文档!!请具有基本的 debug 能力!!
欢迎 Star,欢迎 PR!
特点
- 丰富的扩展,支持微信(商户直连和服务商)、支付宝、银联、百度、字节跳动
- 集成沙箱模式(支付宝、银联),便于开发者调试
- 符合 PSR 标准,方便的与你的框架集成
- 单文件结构清晰、简单,每个类单独封装扩展,便于单独使用
运行环境
使用文档
支持的支付
1、微信(Wechat)
method | 描述 |
---|
js | JSAPI下单 |
app | APP支付 |
h5 | H5支付 |
scan | Navicat支付 |
xcx | 小程序支付 |
query | 查询订单 |
close | 关闭订单 |
notify | 支付结果通知 |
refund | 申请退款 |
queryRefund | 查询退款 |
transfer | 转账到零钱 |
queryTransfer | 查询转账到零钱 |
profitSharing | 请求分账 |
profitsharingUnfreeze | 解冻剩余资金 |
queryProfitsharing | 查询分账结果/查询分账剩余金额 |
profitsharingReturn | 请求分账回退 |
receiversAdd | 添加分账接收方 |
receiversDelete | 删除分账接收方 |
2、支付宝(Alipay)
method | 描述 |
---|
web | 电脑网页支付 |
wap | 手机网站支付 |
xcx | 小程序支付 |
face | 发起当面付 |
app | app支付(JSAPI) |
query | 查询订单 |
close | 关闭订单 |
notify | 支付宝异步通知 |
refund | 订单退款 |
refundQuery | 查询订单退款 |
transfer | 转账到支付宝账户 |
transQuery | 查询转账到支付宝 |
relationBind | 分账关系绑定与解绑 |
relationQuery | 查询分账关系 |
settle | 统一收单交易结算接口 |
settleQuery | 交易分账查询接口 |
onsettleQuery | 分账比例查询 && 分账剩余金额查询 |
getToken | 获取access_token和user_id |
doGetUserInfo | 获取会员信息 |
3、银联(Union)
method | 描述 |
---|
web | 电脑在线网关支付 |
wap | 手机网页支付 |
query | 查询订单 |
notify | 银联异步通知 |
refund | 订单退款/交易撤销 |
4、百度(Baidu)
method | 描述 |
---|
xcx | 小程序支付 |
refund | 申请退款 |
notify | 支付结果通知 |
5、字节跳动(Bytedance)
method | 描述 |
---|
createOrder | 下单支付 |
queryOrder | 订单查询 |
notifyOrder | 订单回调验证 |
createRefund | 订单退款 |
queryRefund | 退款查询 |
settle | 分账请求 |
querySettle | 分账查询 |
安装
composer require fengkui/pay
完善相关配置
$wechatConfig = [
'xcxid' => '',
'appid' => '',
'mchid' => '',
'key' => '',
'appsecret' => '',
'sp_appid' => '',
'sp_mchid' => '',
'notify_url' => '',
'redirect_url' => '',
'serial_no' => '',
'cert_client' => './cert/apiclient_cert.pem',
'cert_key' => './cert/apiclient_key.pem',
'public_key' => './cert/public_key.pem',
];
$alipayConfig = [
'app_id' => '',
'public_key' => '',
'private_key' => '',
'notify_url' => '',
'return_url' => '',
'sign_type' => 'RSA2',
'is_sandbox' => false,
];
$unionConfig = [
'mchid' => '',
'sign_pwd' => '',
'sign_path' => './cert/acp_test_sign.pfx',
'verify_path' => './cert/verify_sign_acp.cer',
'acp_root' => './cert/acp_test_root.cer',
'acp_middle' => './cert/acp_test_middle.cer',
'notify_url' => '',
'return_url' => '',
'is_sandbox' => false,
];
$baiduConfig = [
'deal_id' => '',
'app_key' => '',
'private_key' => '',
'public_key' => '',
'notify_url' => '',
];
$bytedanceConfig = [
'app_id' => '',
'salt' => '',
'token' => '',
'notify_url' => '',
'thirdparty_id' => '',
];
使用说明
单独使用
$pay = new \fengkui\Pay\Wechat($wechatConfig);
$pay = new \fengkui\Pay\Alipay($alipayConfig);
$pay = new \fengkui\Pay\Unionpay($unionConfig);
$pay = new \fengkui\Pay\Baidu($baiduConfig);
$pay = new \fengkui\Pay\Bytedance($bytedanceConfig);
公共使用
<?php
require_once('./vendor/autoload.php');
class Payment
{
protected static $pay = '';
protected static $type = '';
protected static $config = [];
public function _initialize()
{
self::$type = $_GET['type'] ?? 'alipay';
self::config();
}
protected static function config($type='')
{
$type = $type ?: self::$type;
$alipayConfig = [];
if (in_array($type, ['wechat', 'baidu', 'bytedance', 'alipay', 'union'])) {
$config = $type . "Config";
self::$config = $config;
} else {
die('当前类型配置不存在');
}
$type && self::$pay =(new \fengkui\Pay())::$type(self::$config);
}
public function pay()
{
$order = [
'body' => 'subject-测试',
'order_sn' => time(),
'total_amount' => 0.01,
];
$result = self::$pay->web($order);
echo $result;
}
}