Skip to content
Permalink
Browse files

优化代码

  • Loading branch information...
yansongda committed Mar 25, 2019
1 parent 0650359 commit 4118eedf319f0cbffb130f93ff47f78db7a8ed7a
@@ -7,9 +7,11 @@
use Yansongda\Pay\Contracts\GatewayApplicationInterface;
use Yansongda\Pay\Contracts\GatewayInterface;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidGatewayException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Pay\Gateways\Alipay\Support;
use Yansongda\Pay\Log;
use Yansongda\Supports\Collection;
use Yansongda\Supports\Config;
use Yansongda\Supports\Str;
@@ -175,28 +177,34 @@ public function verify($data = null, $refund = false): Collection
* @author yansongda <me@yansongda.cn>
*
* @param string|array $order
* @param bool $refund
* @param bool $transfer
* @param string $type
* @param bool $transfer @deprecated since v2.7.3
*
* @throws InvalidSignException
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidConfigException
*
* @return Collection
*/
public function find($order, $refund = false, $transfer = false): Collection
public function find($order, $type = 'wap', $transfer = false): Collection
{
$method = 'alipay.trade.query';
$requestOrder = is_array($order) ? $order : ['out_trade_no' => $order];
if ($refund) {
$method = 'alipay.trade.fastpay.refund.query';
if ($type === true || $transfer) {
Log::warning('DEPRECATED: In Alipay->find(), the REFUND/TRANSFER param is deprecated since v2.7.3, use TYPE param instead!');
@trigger_error('In yansongda/pay Alipay->find(), the REFUND/TRANSFER param is deprecated since v2.7.3, use TYPE param instead!', E_USER_DEPRECATED);
$type = $type === true ? 'refund' : 'transfer';
}
if ($transfer) {
$requestOrder = is_array($order) ? $order : ['out_biz_no' => $order];
$method = 'alipay.fund.trans.order.query';
$gateway = get_class($this).'\\'.Str::studly($type).'Gateway';
if (!class_exists($gateway) || !is_callable([$gateway, 'find'])) {
throw new GatewayException("{$gateway} Done Not Exist Or Done Not Has FIND Method");
}
$this->payload['method'] = $method;
$this->payload['biz_content'] = json_encode($requestOrder);
$config = call_user_func([$gateway, 'find'], $order);
$this->payload['method'] = $config['method'];
$this->payload['biz_content'] = $config['biz_content'];
$this->payload['sign'] = Support::generateSign($this->payload);
Events::dispatch(Events::METHOD_CALLED, new Events\MethodCalled('Alipay', 'Find', $this->gateway, $this->payload));
@@ -0,0 +1,27 @@
<?php
namespace Yansongda\Pay\Gateways\Alipay;
use Yansongda\Pay\Contracts\GatewayInterface;
use Yansongda\Pay\Events;
use Yansongda\Supports\Collection;
class RefundGateway
{
/**
* Find.
*
* @author yansongda <me@yansongda.cn>
*
* @param $order
*
* @return array
*/
public function find($order): array
{
return [
'method' => 'alipay.trade.fastpay.refund.query',
'biz_content' => json_encode(is_array($order) ? $order : ['out_trade_no' => $order])
];
}
}
@@ -130,10 +130,30 @@ public static function requestApi(array $data): Collection
});
$result = mb_convert_encoding(self::$instance->post('', $data), 'utf-8', 'gb2312');
$result = json_decode($result, true);
Events::dispatch(Events::API_REQUESTED, new Events\ApiRequested('Alipay', '', self::$instance->getBaseUri(), $result));
return self::processingApiResult($data, $result);
}
/**
* processingApiResult.
*
* @author yansongda <me@yansongda.cn>
*
* @param $data
* @param $result
*
* @throws GatewayException
* @throws InvalidConfigException
* @throws InvalidSignException
*
* @return Collection
*/
protected static function processingApiResult($data, $result): Collection
{
$method = str_replace('.', '_', $data['method']).'_response';
if (!isset($result['sign']) || $result[$method]['code'] != '10000') {
@@ -35,4 +35,21 @@ public function pay($endpoint, array $payload): Collection
return Support::requestApi($payload);
}
/**
* Find.
*
* @author yansongda <me@yansongda.cn>
*
* @param $order
*
* @return array
*/
public function find($order): array
{
return [
'method' => 'alipay.fund.trans.order.query',
'biz_content' => json_encode(is_array($order) ? $order : ['out_biz_no' => $order])
];
}
}
@@ -6,6 +6,7 @@
use Symfony\Component\HttpFoundation\Response;
use Yansongda\Pay\Contracts\GatewayInterface;
use Yansongda\Pay\Events;
use Yansongda\Supports\Collection;
class WebGateway implements GatewayInterface
{
@@ -39,6 +40,23 @@ public function pay($endpoint, array $payload): Response
return $this->buildPayHtml($endpoint, $payload, $method);
}
/**
* Find.
*
* @author yansongda <me@yansongda.cn>
*
* @param $order
*
* @return array
*/
public function find($order): array
{
return [
'method' => 'alipay.trade.query',
'biz_content' => json_encode(is_array($order) ? $order : ['out_trade_no' => $order])
];
}
/**
* Build Html response.
*

0 comments on commit 4118eed

Please sign in to comment.
You can’t perform that action at this time.