目前已擁有支付寶支付、微信支付、微信支付v3、通聯(lián)支付
return [
//默認(rèn)支付模式
'default' => 'wechat_pay',
//支付方式
'payType' => ['weixin' => '微信支付', 'yue' => '余額支付', 'offline' => '線下支付'],
//提現(xiàn)方式
'extractType' => ['alipay', 'bank', 'weixin'],
//配送方式
'deliveryType' => ['send' => '商家配送', 'express' => '快遞配送'],
//驅(qū)動模式
'stores' => [
//微信支付
'wechat_pay' => [],
//支付寶支付
'ali_pay' => []
]
];
驅(qū)動里面可以配置支付的額外參數(shù)
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');
}
}
擴(kuò)展需要繼承BaseManager,設(shè)置空間名,設(shè)置默認(rèn)擴(kuò)展
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\';
/**
* 默認(rèn)驅(qū)動
* @return mixed
*/
protected function getDefaultDriver()
{
return Config::get('pay.default', 'wechat_pay');
}
}
默認(rèn)支付為微信支付,如果需要切換其他支付傳入第一個參數(shù)支付方式,目前支付方式有:wechat_pay、ali_pay兩種支付方式。
$pay = new Pay();
//創(chuàng)建訂單支付
$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 = []);
//訂單異步回調(diào)
$pay->handleNotify();
修改config/pay.php
return [
//驅(qū)動模式
'stores' => [
//微信支付
'wechat_pay' => [],
//支付寶支付
'ali_pay' => [],
//銀聯(lián)支付
'union_pay '=>[],
]
];
創(chuàng)建文件:/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');
}
//創(chuàng)建訂單支付
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 = [])
{
}
//異步回調(diào)
public static function handleNotify()
{
}
}
增加銀聯(lián)擴(kuò)展后,需要前臺支付的時候傳入pay_type=union_pay,就會自動調(diào)用銀聯(lián)擴(kuò)展
use crmeb\services\pay;
//實(shí)例化銀聯(lián)支付擴(kuò)展
$pay = new Pay('union_pay');
//給銀聯(lián)支付擴(kuò)展傳參
//$pay = new Pay('union_pay',[
// 'appid'=>'998845566',
// 'key'=>'123456'
//]);
//接受參數(shù)
//class UnionPay extends BasePay implements PayInterface
//{
//
// protected function initialize(array $config)
// {
// //接受銀聯(lián)支付傳的appid和key參數(shù)
// }
//}
//進(jìn)行創(chuàng)建訂單發(fā)起支付
$pay->create(string $orderId, string $totalFee, string $attach, string $body, string $detail, array $options = []);
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號