efps-version
ljl 2 years ago
parent f80b66f3ba
commit 8e0ab3f46c

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Controller\Payment;
use App\Helper\Log;
use App\Model\Order;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Psr\Http\Message\ResponseInterface as Psr7ResponseInterface;
@ -14,6 +15,7 @@ class PageController extends AbstractController
public function index(RequestInterface $request, ResponseInterface $response): Psr7ResponseInterface
{
$orderNo = $request->input('order_no', '');
Log::info('redirectToOut orderNo:' . $orderNo, [], 'omipay');
if (!$orderNo) {
return '订单号错误';
}
@ -21,6 +23,7 @@ class PageController extends AbstractController
if (!$order) {
return '订单号错误';
}
Log::info('redirectToOut url:' . $order->redirect_url, [], 'omipay');
return $response->redirect($order->redirect_url);
}
}

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace App\Helper\Platform;
use GuzzleHttp\Client;
use Hyperf\Guzzle\CoroutineHandler;
use GuzzleHttp\HandlerStack;
class Notification
{
public static function post($url, $params): BaseClient {
$client = new Client([
'handler' => HandlerStack::create(new CoroutineHandler()),
'timeout' => 5,
'swoole' => [
'timeout' => 10,
'socket_buffer_size' => 1024 * 1024 * 2,
],
]);
$response = $client->request('POST', $url, [
'json' => $params
]);
return (string)$response->getBody();
}
}

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace App\Helper\Platform;
class Signer
{
public static function sign($params, $secretKey) {
$signString = $params['app_id'] . '&'
. $params['timestamp'] . '&'
. $params['nonce_str'] . '&'
. $params['data'] . '&'
. $secretKey;
return md5($signString);
}
public static function verify($params, $secretKey) {
$sign = self::sign($params, $secretKey);
return $sign == $params['sign'];
}
}

@ -10,7 +10,7 @@ class JsapiPayRequest extends ApiRequest
{
public function rules(): array
{
$amountList = [500, 1000, 2000, 3000, 5000, 8000, 9800, 19800, 29800, 39800, 49800, 59800, 69800, 79800, 89800, 99800];
$amountList = [10, 500, 1000, 2000, 3000, 5000, 8000, 9800, 19800, 29800, 39800, 49800, 59800, 69800, 79800, 89800, 99800];
return [
'order_name' => ['required', 'max:64'],
'out_order_no' => ['required', 'max:32'],

@ -5,11 +5,15 @@ declare(strict_types=1);
namespace App\Service;
use App\Exception\BusinessException;
use App\Helper\Log;
use App\Helper\OmiPay\Api;
use App\Helper\OmiPay\Result;
use App\Helper\OmiPay\Signer;
use App\Helper\Platform\Notification;
use App\Helper\Platform\Signer as PlatformSigner;
use App\Helper\Redis;
use App\Helper\RedisKey;
use App\Helper\StringHelper;
use App\Model\App;
use App\Model\Order;
@ -83,21 +87,54 @@ class PaymentService extends AbstractService
}
public function notify($params) {
Log::info('notify:', $params, 'omipay');
if (Signer::verify($params)) {
return 'SIGN FAIL';
}
if ($params['return_code'] != 'SUCCESS') {
return 'STATUS FAIL';
}
$order = Order::where('order_no', $params['out_order_no'])->where('status', Order::STATUS_WAIT_PAY)->first();
$app = App::where('app_id', $order->app_id)->first();
$order->status = Order::STATUS_PAYED;
$order->payed_at = date('Y-m-d H:i:s');
$order->exchange_rate = $params['exchange_rate'] ?: 0;
$order->cny_amount = $params['cny_amount'] ?: 0;
$order->save();
if ($order->save()) {
Log::info('notifyToOut url:' . $order->notify_url, 'omipay');
$result = Notification::post($order->notify_url, $this->buildNotifyParams($order, $app));
if ($result != 'SUCCESS') {
return 'NOTIFY FAIL';
}
return 'SUCCESS';
}
return 'UPDATE FAIL';
}
protected function buildNotifyParams(Order $roder, App $app) {
$params = [
'app_id' => $order->app_id,
'nonce_str' => StringHelper::getRandomString(32),
'timestamp' => time(),
];
$bizData = [
'code' => 'SUCCESS',
'order_no' => $roder->order_no,
'out_order_no' => $roder->out_order_no,
'currency' => $roder->currency,
'total_amount' => $roder->amount,
'order_time' => date('YmdHis', strtotime($roder->created_at)),
'pay_time' => date('YmdHis', strtotime($roder->payed_at)),
'exchange_rate' => $roder->exchange_rate,
'cny_amount' => $roder->cny_amount,
];
$params['data'] = json_encode($bizData);
$params['sign'] = PlatformSigner::sign($params, $app->app_key);
Log::info('notifyToOut params:', $params, 'omipay');
return $params;
}
}

Loading…
Cancel
Save