BasePay.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 $params
  111. * @return mixed
  112. */
  113. abstract protected function transferCancel(array $params);
  114. /**
  115. * 初始化
  116. * @param array $config
  117. * @param string $type
  118. * @return mixed
  119. */
  120. protected function payConfig(array $config, string $type)
  121. {
  122. return array_merge(
  123. [
  124. 'logger' => [
  125. 'enable' => true,
  126. 'file' => root_path('runtime') . 'paylog' . DIRECTORY_SEPARATOR . date('Ym') . DIRECTORY_SEPARATOR . date('d') . '.log',
  127. 'level' => env('app_debug') ? 'debug' : 'info', // 建议生产环境等级调整为 info,开发环境为 debug
  128. 'type' => 'single', // optional, 可选 daily.
  129. 'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
  130. ],
  131. 'http' => [ // optional
  132. 'timeout' => 5.0,
  133. ]
  134. ],
  135. [
  136. $type => [
  137. 'default' => $config
  138. ]
  139. ],
  140. ['_force' => true]
  141. );
  142. }
  143. public function returnFormat($param)
  144. {
  145. if ($param instanceof MessageInterface || $param instanceof Response) {
  146. $return_value = $param->getBody()->getContents();
  147. } else if ($param instanceof Collection) {
  148. $return_value = $param->toArray();
  149. } else {
  150. $return_value = $param;
  151. }
  152. return $return_value;
  153. }
  154. /**
  155. * 解析退款返回数据并解析
  156. * @param $our_trade_no
  157. * @param $refund_no
  158. * @param $status
  159. * @param int $success_time
  160. * @param string $reason
  161. * @return array
  162. */
  163. public function getRefundData($our_trade_no, $refund_no, $status, $success_time = 0, $reason = '')
  164. {
  165. return [
  166. 'our_trade_no' => $our_trade_no,
  167. 'refund_no' => $refund_no,
  168. 'status' => $status,
  169. 'success_time' => $success_time,
  170. 'reason' => $reason
  171. ];
  172. }
  173. /**
  174. * 获取转账数据并解析
  175. * @param $transfer_no
  176. * @param $status
  177. * @param $reason
  178. * @return void
  179. */
  180. public function getTransferData($transfer_no, $status, $reason)
  181. {
  182. }
  183. }