亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 46
粉絲 0
評論 0
訪問量 9346
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
PHP 支付系統(tǒng)擴(kuò)展實(shí)戰(zhàn):從微信 / 支付寶到銀聯(lián)的多驅(qū)動架構(gòu)設(shè)計(jì)
い獨(dú)霸天下う
原創(chuàng)
258人瀏覽過

目前已擁有支付寶支付、微信支付、微信支付v3、通聯(lián)支付

支付配置

  1. return [
  2. //默認(rèn)支付模式
  3. 'default' => 'wechat_pay',
  4. //支付方式
  5. 'payType' => ['weixin' => '微信支付', 'yue' => '余額支付', 'offline' => '線下支付'],
  6. //提現(xiàn)方式
  7. 'extractType' => ['alipay', 'bank', 'weixin'],
  8. //配送方式
  9. 'deliveryType' => ['send' => '商家配送', 'express' => '快遞配送'],
  10. //驅(qū)動模式
  11. 'stores' => [
  12. //微信支付
  13. 'wechat_pay' => [],
  14. //支付寶支付
  15. 'ali_pay' => []
  16. ]
  17. ];

驅(qū)動里面可以配置支付的額外參數(shù)

配置參數(shù)接收

  1. namespace crmeb\services\pay\storage;
  2. use crmeb\services\pay\BasePay;
  3. use crmeb\services\pay\PayInterface;
  4. class WechatPay extends BasePay implements PayInterface
  5. {
  6. protected function initialize(array $config)
  7. {
  8. //$config取值config('pay.stores.wechat_pay');
  9. }
  10. }

擴(kuò)展入口

擴(kuò)展需要繼承BaseManager,設(shè)置空間名,設(shè)置默認(rèn)擴(kuò)展

  1. namespace crmeb\services\pay;
  2. use crmeb\basic\BaseManager;
  3. use crmeb\services\pay\storage\AliPay;
  4. use crmeb\services\pay\storage\WechatPay;
  5. use think\facade\Config;
  6. /**
  7. * 第三方支付
  8. * Class Pay
  9. * @package crmeb\services\pay
  10. * @mixin AliPay
  11. * @mixin WechatPay
  12. */
  13. class Pay extends BaseManager
  14. {
  15. /**
  16. * 空間名
  17. * @var string
  18. */
  19. protected $namespace = '\crmeb\services\pay\storage\';
  20. /**
  21. * 默認(rèn)驅(qū)動
  22. * @return mixed
  23. */
  24. protected function getDefaultDriver()
  25. {
  26. return Config::get('pay.default', 'wechat_pay');
  27. }
  28. }

使用方法

默認(rèn)支付為微信支付,如果需要切換其他支付傳入第一個參數(shù)支付方式,目前支付方式有:wechat_pay、ali_pay兩種支付方式。

  1. $pay = new Pay();
  2. //創(chuàng)建訂單支付
  3. $pay->create(string $orderId, string $totalFee, string $attach, string $body, string $detail, array $options = []);
  4. //支付到零錢
  5. $pay->merchantPay(string $openid, string $orderId, string $amount, array $options = []);
  6. //退款
  7. $pay->refund(string $outTradeNo, string $totalAmount, string $refund_id, array $options = []);
  8. //查詢退款
  9. $pay->queryRefund(string $outTradeNo, string $outRequestNo, array $other = []);
  10. //訂單異步回調(diào)
  11. $pay->handleNotify();

擴(kuò)展支付插件

首先增加支付類型配置

修改config/pay.php

  1. return [
  2. //驅(qū)動模式
  3. 'stores' => [
  4. //微信支付
  5. 'wechat_pay' => [],
  6. //支付寶支付
  7. 'ali_pay' => [],
  8. //銀聯(lián)支付
  9. 'union_pay '=>[],
  10. ]
  11. ];

舉例:增加銀聯(lián)支付擴(kuò)展

創(chuàng)建文件:/crmeb/services/pay/storage/UnionPay.php

需要完成以下接口

  1. namespace crmeb\services\pay\storage;
  2. use crmeb\services\pay\BasePay;
  3. use crmeb\services\pay\PayInterface;
  4. class UnionPay extends BasePay implements PayInterface
  5. {
  6. protected function initialize(array $config)
  7. {
  8. //$config取值config('pay.stores.wechat_pay');
  9. }
  10. //創(chuàng)建訂單支付
  11. public function create(string $orderId, string $totalFee, string $attach, string $body, string $detail, array $options = [])
  12. {
  13. }
  14. //支付到零錢
  15. public function merchantPay(string $openid, string $orderId, string $amount, array $options = [])
  16. {
  17. }
  18. //退款
  19. public function refund(string $outTradeNo, string $totalAmount, string $refund_id, array $options = [])
  20. {
  21. }
  22. //查詢退款訂單
  23. public function queryRefund(string $outTradeNo, string $outRequestNo, array $other = [])
  24. {
  25. }
  26. //異步回調(diào)
  27. public static function handleNotify()
  28. {
  29. }
  30. }
銀聯(lián)擴(kuò)展使用方法

增加銀聯(lián)擴(kuò)展后,需要前臺支付的時候傳入pay_type=union_pay,就會自動調(diào)用銀聯(lián)擴(kuò)展

  1. use crmeb\services\pay;
  2. //實(shí)例化銀聯(lián)支付擴(kuò)展
  3. $pay = new Pay('union_pay');
  4. //給銀聯(lián)支付擴(kuò)展傳參
  5. //$pay = new Pay('union_pay',[
  6. // 'appid'=>'998845566',
  7. // 'key'=>'123456'
  8. //]);
  9. //接受參數(shù)
  10. //class UnionPay extends BasePay implements PayInterface
  11. //{
  12. //
  13. // protected function initialize(array $config)
  14. // {
  15. // //接受銀聯(lián)支付傳的appid和key參數(shù)
  16. // }
  17. //}
  18. //進(jìn)行創(chuàng)建訂單發(fā)起支付
  19. $pay->create(string $orderId, string $totalFee, string $attach, string $body, string $detail, array $options = []);

附件:https://gitee.com/ZhongBangKeJi/CRMEB

本博文版權(quán)歸博主所有,轉(zhuǎn)載請注明地址!如有侵權(quán)、違法,請聯(lián)系admin@php.cn舉報(bào)處理!
全部評論 文明上網(wǎng)理性發(fā)言,請遵守新聞評論服務(wù)協(xié)議
0條評論
關(guān)于我們 免責(zé)申明 意見反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長!
關(guān)注服務(wù)號 技術(shù)交流群
PHP中文網(wǎng)訂閱號
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號

  • 登錄PHP中文網(wǎng),和優(yōu)秀的人一起學(xué)習(xí)!
    全站2000+教程免費(fèi)學(xué)