完善日志系统,调整日志等级

This commit is contained in:
yansongda 2018-09-13 11:03:58 +08:00
parent 244219e2a3
commit cef2f2d384
18 changed files with 54 additions and 24 deletions

View File

@ -102,6 +102,8 @@ class Alipay implements GatewayApplicationInterface
*/
public function pay($gateway, $params = [])
{
Log::debug('Starting To Alipay', [$gateway, $params]);
$this->payload['return_url'] = $params['return_url'] ?? $this->payload['return_url'];
$this->payload['notify_url'] = $params['notify_url'] ?? $this->payload['notify_url'];
unset($params['return_url'], $params['notify_url']);
@ -138,7 +140,7 @@ class Alipay implements GatewayApplicationInterface
$data = Support::encoding($data, 'utf-8', $data['charset'] ?? 'gb2312');
Log::debug('Receive Alipay Request:', $data);
Log::info('Received Alipay Request', $data);
if (Support::verifySign($data, $this->config->get('ali_public_key'))) {
return new Collection($data);
@ -169,7 +171,7 @@ class Alipay implements GatewayApplicationInterface
$this->payload['biz_content'] = json_encode(is_array($order) ? $order : ['out_trade_no' => $order]);
$this->payload['sign'] = Support::generateSign($this->payload, $this->config->get('private_key'));
Log::debug('Alipay Find An Order:', [$this->gateway, $this->payload]);
Log::info('Starting To Find An Alipay Order', [$this->gateway, $this->payload]);
return Support::requestApi($this->payload, $this->config->get('ali_public_key'));
}
@ -193,7 +195,7 @@ class Alipay implements GatewayApplicationInterface
$this->payload['biz_content'] = json_encode($order);
$this->payload['sign'] = Support::generateSign($this->payload, $this->config->get('private_key'));
Log::debug('Alipay Refund An Order:', [$this->gateway, $this->payload]);
Log::info('Starting To Refund An Alipay Order', [$this->gateway, $this->payload]);
return Support::requestApi($this->payload, $this->config->get('ali_public_key'));
}
@ -217,7 +219,7 @@ class Alipay implements GatewayApplicationInterface
$this->payload['biz_content'] = json_encode(is_array($order) ? $order : ['out_trade_no' => $order]);
$this->payload['sign'] = Support::generateSign($this->payload, $this->config->get('private_key'));
Log::debug('Alipay Cancel An Order:', [$this->gateway, $this->payload]);
Log::info('Starting To Cancel An Alipay Order', [$this->gateway, $this->payload]);
return Support::requestApi($this->payload, $this->config->get('ali_public_key'));
}
@ -241,7 +243,7 @@ class Alipay implements GatewayApplicationInterface
$this->payload['biz_content'] = json_encode(is_array($order) ? $order : ['out_trade_no' => $order]);
$this->payload['sign'] = Support::generateSign($this->payload, $this->config->get('private_key'));
Log::debug('Alipay Close An Order:', [$this->gateway, $this->payload]);
Log::info('Starting To Close An Alipay Order', [$this->gateway, $this->payload]);
return Support::requestApi($this->payload, $this->config->get('ali_public_key'));
}
@ -265,7 +267,7 @@ class Alipay implements GatewayApplicationInterface
$this->payload['biz_content'] = json_encode(is_array($bill) ? $bill : ['bill_type' => 'trade', 'bill_date' => $bill]);
$this->payload['sign'] = Support::generateSign($this->payload, $this->config->get('private_key'));
Log::debug('Alipay Download Bill:', [$this->gateway, $this->payload]);
Log::info('Starting To Download The Alipay Bill', [$this->gateway, $this->payload]);
$result = Support::requestApi($this->payload, $this->config->get('ali_public_key'));

View File

@ -49,7 +49,7 @@ class AppGateway implements GatewayInterface
));
$payload['sign'] = Support::generateSign($payload, $this->config->get('private_key'));
Log::debug('Paying An App Order:', [$endpoint, $payload]);
Log::info('Starting To Pay An Alipay App Order', [$endpoint, $payload]);
return Response::create(http_build_query($payload));
}

View File

@ -54,7 +54,7 @@ class PosGateway implements GatewayInterface
));
$payload['sign'] = Support::generateSign($payload, $this->config->get('private_key'));
Log::debug('Paying A Pos Order:', [$endpoint, $payload]);
Log::info('Starting To Pay An Alipay Pos Order', [$endpoint, $payload]);
return Support::requestApi($payload, $this->config->get('ali_public_key'));
}

View File

@ -51,7 +51,7 @@ class ScanGateway implements GatewayInterface
));
$payload['sign'] = Support::generateSign($payload, $this->config->get('private_key'));
Log::debug('Paying A Scan Order:', [$endpoint, $payload]);
Log::info('Starting To Pay An Alipay Scan Order', [$endpoint, $payload]);
return Support::requestApi($payload, $this->config->get('ali_public_key'));
}

View File

@ -126,6 +126,8 @@ class Support
openssl_sign(self::getSignContent($params), $sign, $privateKey, OPENSSL_ALGO_SHA256);
Log::debug('Alipay Generate Sign Before Base64', [$params, $sign]);
return base64_encode($sign);
}
@ -191,6 +193,8 @@ class Support
}
}
Log::debug('Alipay Generate Sign Content Before Trim', [$data, $stringToBeSigned]);
return trim($stringToBeSigned, '&');
}

View File

@ -51,7 +51,7 @@ class TransferGateway implements GatewayInterface
));
$payload['sign'] = Support::generateSign($payload, $this->config->get('private_key'));
Log::debug('Paying A Transfer Order:', [$endpoint, $payload]);
Log::info('Starting To Pay An Alipay Transfer Order', [$endpoint, $payload]);
return Support::requestApi($payload, $this->config->get('ali_public_key'));
}

View File

@ -49,7 +49,7 @@ class WebGateway implements GatewayInterface
));
$payload['sign'] = Support::generateSign($payload, $this->config->get('private_key'));
Log::debug('Paying A Web/Wap Order:', [$endpoint, $payload]);
Log::info('Starting To Pay An Alipay Web/Wap Order', [$endpoint, $payload]);
return $this->buildPayHtml($endpoint, $payload);
}

View File

@ -74,6 +74,8 @@ class Wechat implements GatewayApplicationInterface
* @author yansongda <me@yansongda.cn>
*
* @param Config $config
*
* @throws \Exception
*/
public function __construct(Config $config)
{
@ -129,6 +131,8 @@ class Wechat implements GatewayApplicationInterface
*/
public function pay($gateway, $params = [])
{
Log::debug('Starting To Wechat', [$gateway, $params]);
$this->payload = array_merge($this->payload, $params);
$gateway = get_class($this).'\\'.Str::studly($gateway).'Gateway';
@ -155,13 +159,17 @@ class Wechat implements GatewayApplicationInterface
*/
public function verify($content = null, $refund = false): Collection
{
$data = Support::fromXml($content ?? Request::createFromGlobals()->getContent());
$content = $content ?? Request::createFromGlobals()->getContent();
Log::info('Received Wechat Request', $content);
$data = Support::fromXml($content);
if ($refund) {
$decrypt_data = Support::decryptRefundContents($data['req_info'], $this->config->get('key'));
$data = array_merge(Support::fromXml($decrypt_data), $data);
}
Log::debug('Receive Wechat Request:', $data);
Log::debug('Resolved The Received Wechat Request Data', $data);
if ($refund || Support::generateSign($data, $this->config->get('key')) === $data['sign']) {
return new Collection($data);
@ -190,7 +198,7 @@ class Wechat implements GatewayApplicationInterface
{
$this->payload = Support::filterPayload($this->payload, $order, $this->config);
Log::debug('Wechat Find An Order:', [$this->gateway, $this->payload]);
Log::info('Starting To Find An Wechat Order', [$this->gateway, $this->payload]);
return Support::requestApi(
$refund ? 'pay/refundquery' : 'pay/orderquery',
@ -216,7 +224,7 @@ class Wechat implements GatewayApplicationInterface
{
$this->payload = Support::filterPayload($this->payload, $order, $this->config, true);
Log::debug('Wechat Refund An Order:', [$this->gateway, $this->payload]);
Log::info('Starting To Refund An Wechat Order', [$this->gateway, $this->payload]);
return Support::requestApi(
'secapi/pay/refund',
@ -239,7 +247,9 @@ class Wechat implements GatewayApplicationInterface
*/
public function cancel($order): Collection
{
throw new GatewayException('Wechat Do Not Have Cancel API! Plase use Close API!');
Log::warning('Using Not Exist Wechat Cancel API', $order);
throw new GatewayException('Wechat Do Not Have Cancel API! Please use Close API!');
}
/**
@ -261,7 +271,7 @@ class Wechat implements GatewayApplicationInterface
$this->payload = Support::filterPayload($this->payload, $order, $this->config);
Log::debug('Wechat Close An Order:', [$this->gateway, $this->payload]);
Log::info('Starting To Close An Wechat Order', [$this->gateway, $this->payload]);
return Support::requestApi('pay/closeorder', $this->payload, $this->config->get('key'));
}

View File

@ -41,7 +41,7 @@ class AppGateway extends Gateway
];
$payRequest['sign'] = Support::generateSign($payRequest, $this->config->get('key'));
Log::debug('Paying An App Order:', [$endpoint, $payRequest]);
Log::info('Starting To Pay A Wechat App Order', [$endpoint, $payRequest]);
return JsonResponse::create($payRequest);
}

View File

@ -59,7 +59,7 @@ abstract class Gateway implements GatewayInterface
abstract protected function getTradeType();
/**
* Preorder an order.
* Schedule an order.
*
* @author yansongda <me@yansongda.cn>
*
@ -76,7 +76,7 @@ abstract class Gateway implements GatewayInterface
{
$payload['sign'] = Support::generateSign($payload, $this->config->get('key'));
Log::debug('Pre Order:', [$endpoint, $payload]);
Log::info('Starting To Schedule A Wechat order', [$endpoint, $payload]);
return Support::requestApi($endpoint, $payload, $this->config->get('key'));
}

View File

@ -33,7 +33,7 @@ class GroupRedpackGateway extends Gateway
$payload['sign'] = Support::generateSign($payload, $this->config->get('key'));
Log::debug('Paying A Groupredpack Order:', [$endpoint, $payload]);
Log::info('Starting To Pay A Wechat Group Redpack Order', [$endpoint, $payload]);
return Support::requestApi(
'mmpaymkttransfers/sendgroupredpack',

View File

@ -19,6 +19,7 @@ class MpGateway extends Gateway
* @throws \Yansongda\Pay\Exceptions\GatewayException
* @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
* @throws \Yansongda\Pay\Exceptions\InvalidSignException
* @throws \Exception
*
* @return Collection
*/
@ -35,7 +36,7 @@ class MpGateway extends Gateway
];
$payRequest['paySign'] = Support::generateSign($payRequest, $this->config->get('key'));
Log::debug('Paying A JSAPI Order:', [$endpoint, $payRequest]);
Log::info('Starting To Pay A Wechat JSAPI Order', [$endpoint, $payRequest]);
return new Collection($payRequest);
}

View File

@ -2,6 +2,7 @@
namespace Yansongda\Pay\Gateways\Wechat;
use Yansongda\Pay\Log;
use Yansongda\Supports\Collection;
class PosGateway extends Gateway
@ -24,6 +25,8 @@ class PosGateway extends Gateway
{
unset($payload['trade_type'], $payload['notify_url']);
Log::info('Starting To Pay A Wechat Pos Order', [$endpoint, $payload]);
return $this->preOrder('pay/micropay', $payload);
}

View File

@ -34,7 +34,7 @@ class RedpackGateway extends Gateway
$payload['sign'] = Support::generateSign($payload, $this->config->get('key'));
Log::debug('Paying A Redpack Order:', [$endpoint, $payload]);
Log::info('Starting To Pay A Wechat Redpack Order', [$endpoint, $payload]);
return Support::requestApi(
'mmpaymkttransfers/sendredpack',

View File

@ -3,6 +3,7 @@
namespace Yansongda\Pay\Gateways\Wechat;
use Symfony\Component\HttpFoundation\Request;
use Yansongda\Pay\Log;
use Yansongda\Supports\Collection;
class ScanGateway extends Gateway
@ -26,6 +27,8 @@ class ScanGateway extends Gateway
$payload['spbill_create_ip'] = Request::createFromGlobals()->server->get('SERVER_ADDR');
$payload['trade_type'] = $this->getTradeType();
Log::info('Starting To Pay A Wechat Scan Order', [$endpoint, $payload]);
return $this->preOrder('pay/unifiedorder', $payload);
}

View File

@ -155,6 +155,8 @@ class Support
$string = md5(self::getSignContent($data).'&key='.$key);
Log::debug('Wechat Generate Sign Before UPPER', [$data, $string]);
return strtoupper($string);
}
@ -175,6 +177,8 @@ class Support
$buff .= ($k != 'sign' && $v != '' && !is_array($v)) ? $k.'='.$v.'&' : '';
}
Log::debug('Wechat Generate Sign Content Before Trim', [$data, $buff]);
return trim($buff, '&');
}

View File

@ -39,7 +39,7 @@ class TransferGateway extends Gateway
$payload['sign'] = Support::generateSign($payload, $this->config->get('key'));
Log::debug('Paying A Transfer Order:', [$endpoint, $payload]);
Log::info('Starting To Pay A Wechat Transfer Order', [$endpoint, $payload]);
return Support::requestApi(
'mmpaymkttransfers/promotion/transfers',

View File

@ -4,6 +4,7 @@ namespace Yansongda\Pay\Gateways\Wechat;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Yansongda\Pay\Log;
class WapGateway extends Gateway
{
@ -25,6 +26,8 @@ class WapGateway extends Gateway
{
$payload['trade_type'] = $this->getTradeType();
Log::info('Starting To Pay A Wechat Wap Order', [$endpoint, $payload]);
$data = $this->preOrder('pay/unifiedorder', $payload);
$url = is_null($this->config->get('return_url')) ? $data->mweb_url : $data->mweb_url.