Pay.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\common\factory;
  3. use app\common\factory\pay\LdysPay;
  4. use app\common\factory\pay\QzlPay;
  5. use app\common\factory\pay\SywPay;
  6. use app\common\factory\pay\XtyPay;
  7. use app\common\factory\pay\YyYbPay;
  8. use app\common\factory\pay\AliPay;
  9. class Pay
  10. {
  11. /**
  12. * 工厂方法示例
  13. *
  14. * @param string $way 支付方式类型
  15. *
  16. * @return mixed 支付方式实例
  17. * @throws \Exception
  18. */
  19. public static function createPayment($way)
  20. {
  21. // 根据支付方式类型返回不同的实例
  22. switch ($way) {
  23. case 'ldys_pay': // 联动优势支付
  24. return new LdysPay($way);
  25. case 'qzl_pay': // 趣支付
  26. return new QzlPay($way);
  27. case 'yyyb_pay': // 优亿支付
  28. return new YyYbPay($way);
  29. case 'xty_pay': // 喜钛游支付(腾春科技)
  30. return new XtyPay($way);
  31. case 'syw_pay': // 十一玩支付(Hi支付)
  32. return new SywPay($way);
  33. case 'ali_pay': // 支付宝
  34. return new AliPay($way);
  35. // 其他支付方式...
  36. default:
  37. throw new \Exception('当前支付方式未配置!');
  38. }
  39. }
  40. /**
  41. * 支付
  42. *
  43. * @param string $way 支付方式类型
  44. *
  45. * @return mixed
  46. * @throws \Exception
  47. */
  48. public static function makePay($way, $data, $type = '')
  49. {
  50. $payment = self::createPayment($way);
  51. return $payment->pay($data, $type);
  52. }
  53. /**
  54. * 回调
  55. *
  56. * @param string $way 支付方式类型
  57. * @param string $data 数据
  58. *
  59. * @return bool|void
  60. * @throws \Exception
  61. */
  62. public static function makeNotify($way, $data)
  63. {
  64. $payment = self::createPayment($way);
  65. return $payment->notify($data);
  66. }
  67. /**
  68. * 查询订单
  69. * @param string $way 支付方式类型
  70. *
  71. * @return void
  72. * @throws \Exception
  73. */
  74. public static function makeQuery($way, $data)
  75. {
  76. $payment = self::createPayment($way);
  77. return $payment->query($data);
  78. }
  79. // 退款
  80. public static function makeRefund($way, $data)
  81. {
  82. $payment = self::createPayment($way);
  83. return $payment->refund($data);
  84. }
  85. /**
  86. * 支付回调通知返回
  87. *
  88. * @param string $way 支付方式标识
  89. * @param string $returnType 状态标识: success/fail
  90. *
  91. * @return string
  92. * @throws \Exception
  93. */
  94. public static function makeReturnNotify($way, $returnType)
  95. {
  96. $payment = self::createPayment($way);
  97. $result = $payment->returnNotify($returnType);
  98. log_message('## '.$way.' - 回调返回: '. $returnType, 'log', LOG_PATH . 'PayNotify/');
  99. return $result;
  100. }
  101. }