123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- namespace core\pay;
- use core\loader\Storage;
- use GuzzleHttp\Psr7\Response;
- use Psr\Http\Message\MessageInterface;
- use Yansongda\Supports\Collection;
- /**
- * 文件管理驱动类
- * Class BasePay
- */
- abstract class BasePay extends Storage
- {
- protected $config;//配置
- /**
- * 初始化
- * @param array $config
- * @return void
- */
- protected function initialize(array $config = [])
- {
- }
- /**
- * 网页支付
- * @param array $params
- * @return mixed
- */
- abstract protected function web(array $params);
- /**
- * 手机网站支付
- * @param array $params
- * @return mixed
- */
- abstract protected function wap(array $params);
- /**
- * app支付
- * @param array $params
- * @return mixed
- */
- abstract protected function app(array $params);
- /**
- * 小程序支付
- * @param array $params
- * @return mixed
- */
- abstract protected function mini(array $params);
- /**
- * 付款码支付
- * @param array $params
- * @return mixed
- */
- abstract protected function pos(array $params);
- /**
- * 扫码支付
- * @param array $params
- * @return mixed
- */
- abstract protected function scan(array $params);
- /**
- * 转账
- * @param array $params
- * @return mixed
- */
- abstract protected function transfer(array $params);
- /**
- * 公众号支付
- * @param array $params
- * @return mixed
- */
- abstract protected function mp(array $params);
- /**
- * 支付关闭
- * @param string $out_trade_no
- * @return mixed
- */
- abstract protected function close(string $out_trade_no);
- /**
- * 退款
- * @param array $params
- * @return mixed
- */
- abstract protected function refund(array $params);
- /**
- * 支付通知
- * @param string $action
- * @param callable $callback
- * @return mixed
- */
- abstract protected function notify(string $action, callable $callback);
- /**
- * 查询支付订单
- * @param array $params
- * @return mixed
- */
- abstract protected function getOrder(array $params);
- /**
- * 查询退款订单
- * @param string $out_trade_no
- * @param string|null $refund_no
- * @return mixed
- */
- abstract protected function getRefund(string $out_trade_no, ?string $refund_no);
- /**
- * 查询转账订单
- * @param string $transfer_no
- * @return mixed
- */
- abstract protected function getTransfer(string $transfer_no, $out_transfer_no = '');
- /**
- * 取消转账
- * @param array $params
- * @return mixed
- */
- abstract protected function transferCancel(array $params);
- /**
- * 初始化
- * @param array $config
- * @param string $type
- * @return mixed
- */
- protected function payConfig(array $config, string $type)
- {
- return array_merge(
- [
- 'logger' => [
- 'enable' => true,
- 'file' => root_path('runtime') . 'paylog' . DIRECTORY_SEPARATOR . date('Ym') . DIRECTORY_SEPARATOR . date('d') . '.log',
- 'level' => env('app_debug') ? 'debug' : 'info', // 建议生产环境等级调整为 info,开发环境为 debug
- 'type' => 'single', // optional, 可选 daily.
- 'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
- ],
- 'http' => [ // optional
- 'timeout' => 5.0,
- ]
- ],
- [
- $type => [
- 'default' => $config
- ]
- ],
- ['_force' => true]
- );
- }
- public function returnFormat($param)
- {
- if ($param instanceof MessageInterface || $param instanceof Response) {
- $return_value = $param->getBody()->getContents();
- } else if ($param instanceof Collection) {
- $return_value = $param->toArray();
- } else {
- $return_value = $param;
- }
- return $return_value;
- }
- /**
- * 解析退款返回数据并解析
- * @param $our_trade_no
- * @param $refund_no
- * @param $status
- * @param int $success_time
- * @param string $reason
- * @return array
- */
- public function getRefundData($our_trade_no, $refund_no, $status, $success_time = 0, $reason = '')
- {
- return [
- 'our_trade_no' => $our_trade_no,
- 'refund_no' => $refund_no,
- 'status' => $status,
- 'success_time' => $success_time,
- 'reason' => $reason
- ];
- }
- /**
- * 获取转账数据并解析
- * @param $transfer_no
- * @param $status
- * @param $reason
- * @return void
- */
- public function getTransferData($transfer_no, $status, $reason)
- {
- }
- }
|