BasePay.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace core\pay;
  3. use core\loader\Storage;
  4. use GuzzleHttp\Psr7\Response;
  5. use Psr\Http\Message\MessageInterface;
  6. use Yansongda\Supports\Collection;
  7. /**
  8. * 文件管理驱动类
  9. * Class BasePay
  10. */
  11. abstract class BasePay extends Storage
  12. {
  13. protected $config;//配置
  14. /**
  15. * 初始化
  16. * @param array $config
  17. * @return void
  18. */
  19. protected function initialize(array $config = [])
  20. {
  21. }
  22. /**
  23. * 网页支付
  24. * @param array $params
  25. * @return mixed
  26. */
  27. abstract protected function web(array $params);
  28. /**
  29. * 手机网站支付
  30. * @param array $params
  31. * @return mixed
  32. */
  33. abstract protected function wap(array $params);
  34. /**
  35. * app支付
  36. * @param array $params
  37. * @return mixed
  38. */
  39. abstract protected function app(array $params);
  40. /**
  41. * 小程序支付
  42. * @param array $params
  43. * @return mixed
  44. */
  45. abstract protected function mini(array $params);
  46. /**
  47. * 付款码支付
  48. * @param array $params
  49. * @return mixed
  50. */
  51. abstract protected function pos(array $params);
  52. /**
  53. * 扫码支付
  54. * @param array $params
  55. * @return mixed
  56. */
  57. abstract protected function scan(array $params);
  58. /**
  59. * 转账
  60. * @param array $params
  61. * @return mixed
  62. */
  63. abstract protected function transfer(array $params);
  64. /**
  65. * 公众号支付
  66. * @param array $params
  67. * @return mixed
  68. */
  69. abstract protected function mp(array $params);
  70. /**
  71. * 支付关闭
  72. * @param string $out_trade_no
  73. * @return mixed
  74. */
  75. abstract protected function close(string $out_trade_no);
  76. /**
  77. * 退款
  78. * @param array $params
  79. * @return mixed
  80. */
  81. abstract protected function refund(array $params);
  82. /**
  83. * 支付通知
  84. * @param string $action
  85. * @param callable $callback
  86. * @return mixed
  87. */
  88. abstract protected function notify(string $action, callable $callback);
  89. /**
  90. * 查询支付订单
  91. * @param array $params
  92. * @return mixed
  93. */
  94. abstract protected function getOrder(array $params);
  95. /**
  96. * 查询退款订单
  97. * @param string $out_trade_no
  98. * @param string|null $refund_no
  99. * @return mixed
  100. */
  101. abstract protected function getRefund(string $out_trade_no, ?string $refund_no);
  102. /**
  103. * 查询转账订单
  104. * @param string $transfer_no
  105. * @return mixed
  106. */
  107. abstract protected function getTransfer(string $transfer_no, $out_transfer_no = '');
  108. /**
  109. * 初始化
  110. * @param array $config
  111. * @param string $type
  112. * @return mixed
  113. */
  114. protected function payConfig(array $config, string $type)
  115. {
  116. return array_merge(
  117. [
  118. 'logger' => [
  119. 'enable' => true,
  120. 'file' => root_path('runtime') . 'paylog' . DIRECTORY_SEPARATOR . date('Ym') . DIRECTORY_SEPARATOR . date('d') . '.log',
  121. 'level' => env('app_debug') ? 'debug' : 'info', // 建议生产环境等级调整为 info,开发环境为 debug
  122. 'type' => 'single', // optional, 可选 daily.
  123. 'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
  124. ],
  125. 'http' => [ // optional
  126. 'timeout' => 5.0,
  127. ]
  128. ],
  129. [
  130. $type => [
  131. 'default' => $config
  132. ]
  133. ],
  134. ['_force' => true]
  135. );
  136. }
  137. public function returnFormat($param)
  138. {
  139. if ($param instanceof MessageInterface || $param instanceof Response) {
  140. $return_value = $param->getBody()->getContents();
  141. } else if ($param instanceof Collection) {
  142. $return_value = $param->toArray();
  143. } else {
  144. $return_value = $param;
  145. }
  146. return $return_value;
  147. }
  148. /**
  149. * 解析退款返回数据并解析
  150. * @param $our_trade_no
  151. * @param $refund_no
  152. * @param $status
  153. * @param int $success_time
  154. * @param string $reason
  155. * @return array
  156. */
  157. public function getRefundData($our_trade_no, $refund_no, $status, $success_time = 0, $reason = '')
  158. {
  159. return [
  160. 'our_trade_no' => $our_trade_no,
  161. 'refund_no' => $refund_no,
  162. 'status' => $status,
  163. 'success_time' => $success_time,
  164. 'reason' => $reason
  165. ];
  166. }
  167. /**
  168. * 获取转账数据并解析
  169. * @param $transfer_no
  170. * @param $status
  171. * @param $reason
  172. * @return void
  173. */
  174. public function getTransferData($transfer_no, $status, $reason)
  175. {
  176. }
  177. }