PaymentFactory.php 520 Bytes
<?php
/**
 * Created by PhpStorm.
 * User: lishuai
 * Date: 2022/2/15
 * Time: 4:25 PM
 */

namespace App\Payment;

class PaymentFactory
{
    public function init($pay_type)
    {
        switch ($pay_type){
            case 'alipay':
                return new AliPayment();
            case 'wechat':
                return new WechatPayment();
            case 'paypal':
                return new PayPalPayment();
            default:
                throw new \Exception('未知的支付方式');
        }
    }
}