| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace app\common\factory;
- use app\common\factory\pay\LdysPay;
- use app\common\factory\pay\QzlPay;
- use app\common\factory\pay\SywPay;
- use app\common\factory\pay\XtyPay;
- use app\common\factory\pay\YyYbPay;
- use app\common\factory\pay\AliPay;
- class Pay
- {
- /**
- * 工厂方法示例
- *
- * @param string $way 支付方式类型
- *
- * @return mixed 支付方式实例
- * @throws \Exception
- */
- public static function createPayment($way)
- {
- // 根据支付方式类型返回不同的实例
- switch ($way) {
- case 'ldys_pay': // 联动优势支付
- return new LdysPay($way);
- case 'qzl_pay': // 趣支付
- return new QzlPay($way);
- case 'yyyb_pay': // 优亿支付
- return new YyYbPay($way);
- case 'xty_pay': // 喜钛游支付(腾春科技)
- return new XtyPay($way);
- case 'syw_pay': // 十一玩支付(Hi支付)
- return new SywPay($way);
- case 'ali_pay': // 支付宝
- return new AliPay($way);
- // 其他支付方式...
- default:
- throw new \Exception('当前支付方式未配置!');
- }
- }
- /**
- * 支付
- *
- * @param string $way 支付方式类型
- *
- * @return mixed
- * @throws \Exception
- */
- public static function makePay($way, $data, $type = '')
- {
- $payment = self::createPayment($way);
- return $payment->pay($data, $type);
- }
- /**
- * 回调
- *
- * @param string $way 支付方式类型
- * @param string $data 数据
- *
- * @return bool|void
- * @throws \Exception
- */
- public static function makeNotify($way, $data)
- {
- $payment = self::createPayment($way);
- return $payment->notify($data);
- }
- /**
- * 查询订单
- * @param string $way 支付方式类型
- *
- * @return void
- * @throws \Exception
- */
- public static function makeQuery($way, $data)
- {
- $payment = self::createPayment($way);
- return $payment->query($data);
- }
- // 退款
- public static function makeRefund($way, $data)
- {
- $payment = self::createPayment($way);
- return $payment->refund($data);
- }
- /**
- * 支付回调通知返回
- *
- * @param string $way 支付方式标识
- * @param string $returnType 状态标识: success/fail
- *
- * @return string
- * @throws \Exception
- */
- public static function makeReturnNotify($way, $returnType)
- {
- $payment = self::createPayment($way);
- $result = $payment->returnNotify($returnType);
- log_message('## '.$way.' - 回调返回: '. $returnType, 'log', LOG_PATH . 'PayNotify/');
- return $result;
- }
- }
|