目前已拥有支付宝支付、微信支付、微信支付v3、通联支付
return [//默认支付模式'default' => 'wechat_pay',//支付方式'payType' => ['weixin' => '微信支付', 'yue' => '余额支付', 'offline' => '线下支付'],//提现方式'extractType' => ['alipay', 'bank', 'weixin'],//配送方式'deliveryType' => ['send' => '商家配送', 'express' => '快递配送'],//驱动模式'stores' => [//微信支付'wechat_pay' => [],//支付宝支付'ali_pay' => []]];
驱动里面可以配置支付的额外参数
namespace crmeb\services\pay\storage;use crmeb\services\pay\BasePay;use crmeb\services\pay\PayInterface;class WechatPay extends BasePay implements PayInterface{protected function initialize(array $config){//$config取值config('pay.stores.wechat_pay');}}
扩展需要继承BaseManager,设置空间名,设置默认扩展
namespace crmeb\services\pay;use crmeb\basic\BaseManager;use crmeb\services\pay\storage\AliPay;use crmeb\services\pay\storage\WechatPay;use think\facade\Config;/*** 第三方支付* Class Pay* @package crmeb\services\pay* @mixin AliPay* @mixin WechatPay*/class Pay extends BaseManager{/*** 空间名* @var string*/protected $namespace = '\crmeb\services\pay\storage\';/*** 默认驱动* @return mixed*/protected function getDefaultDriver(){return Config::get('pay.default', 'wechat_pay');}}
默认支付为微信支付,如果需要切换其他支付传入第一个参数支付方式,目前支付方式有:wechat_pay、ali_pay两种支付方式。
$pay = new Pay();//创建订单支付$pay->create(string $orderId, string $totalFee, string $attach, string $body, string $detail, array $options = []);//支付到零钱$pay->merchantPay(string $openid, string $orderId, string $amount, array $options = []);//退款$pay->refund(string $outTradeNo, string $totalAmount, string $refund_id, array $options = []);//查询退款$pay->queryRefund(string $outTradeNo, string $outRequestNo, array $other = []);//订单异步回调$pay->handleNotify();
修改config/pay.php
return [//驱动模式'stores' => [//微信支付'wechat_pay' => [],//支付宝支付'ali_pay' => [],//银联支付'union_pay '=>[],]];
创建文件:/crmeb/services/pay/storage/UnionPay.php
需要完成以下接口
namespace crmeb\services\pay\storage;use crmeb\services\pay\BasePay;use crmeb\services\pay\PayInterface;class UnionPay extends BasePay implements PayInterface{protected function initialize(array $config){//$config取值config('pay.stores.wechat_pay');}//创建订单支付public function create(string $orderId, string $totalFee, string $attach, string $body, string $detail, array $options = []){}//支付到零钱public function merchantPay(string $openid, string $orderId, string $amount, array $options = []){}//退款public function refund(string $outTradeNo, string $totalAmount, string $refund_id, array $options = []){}//查询退款订单public function queryRefund(string $outTradeNo, string $outRequestNo, array $other = []){}//异步回调public static function handleNotify(){}}
增加银联扩展后,需要前台支付的时候传入pay_type=union_pay,就会自动调用银联扩展
use crmeb\services\pay;//实例化银联支付扩展$pay = new Pay('union_pay');//给银联支付扩展传参//$pay = new Pay('union_pay',[// 'appid'=>'998845566',// 'key'=>'123456'//]);//接受参数//class UnionPay extends BasePay implements PayInterface//{//// protected function initialize(array $config)// {// //接受银联支付传的appid和key参数// }//}//进行创建订单发起支付$pay->create(string $orderId, string $totalFee, string $attach, string $body, string $detail, array $options = []);
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号