efps-version
elf 2 years ago
parent 6beac12c64
commit f80b66f3ba

@ -68,7 +68,7 @@ class JinlingCommand extends HyperfCommand
$data = [
'order_name' => '测试订单',
'currency' => 'CNY',
'amount' => '20',
'amount' => '2000',
'notify_url' => 'http://www.baidu.com',
'redirect_url' => 'http://www.google.com',
'out_order_no' => '1122',

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Helper\OmiPay;
use App\Helper\Log;
use App\Helper\OmiPay\Request\AbstractRequest;
use App\Helper\StringHelper;
use App\Helper\TimeHelper;
@ -30,10 +31,13 @@ abstract class AbstractApi
$params = self::getCommonParams();
$params = array_merge($params, $request->getParams());
try {
Log::info('url:' . $request->getUrl(), [], 'omipay');
$response = self::getClient()->post($request->getUrl(), [
'query' => $params
]);
Log::info('request:', $params, 'omipay');
$body = (string)$response->getBody();
Log::info('response:' . $body, [], 'omipay');
$result = json_decode($body, true);
if (empty($result)) {
$result = [
@ -44,6 +48,7 @@ abstract class AbstractApi
}
return new Result($result);
} catch (Exception $e) {
Log::error('error:' . $e->getMessage(), [], 'omipay');
return new Result([
'return_code' => 'FAIL',
'error_code' => 'NETWORK_ERROR',

@ -10,10 +10,11 @@ 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];
return [
'order_name' => ['required', 'max:64'],
'out_order_no' => ['required', 'max:32'],
'amount' => ['required', Rule::in([5,10,20,30,50,80,98,198,298,398,498,598,698,798,898,998])],
'amount' => ['required', Rule::in($amountList)],
'currency' => ['required', Rule::in(['CNY'])],
'show_pc_pay_url' => ['integer', Rule::in([1, 2])],
'direct_pay' => ['integer', Rule::in([1, 2])],

@ -21,6 +21,7 @@ class PaymentService extends AbstractService
$order->app_id = $app->app_id;
$order->order_no = $this->generateOrderNo();
$order->out_order_no = $params['out_order_no'];
$order->order_name = $params['order_name'];
$order->amount = $params['amount'];
$order->currency = $params['currency'];
$order->redirect_url = $params['redirect_url'];
@ -64,13 +65,18 @@ class PaymentService extends AbstractService
throw new BusinessException('订单重复');
}
$order = $this->createOrder($app, $params);
$result = Api::getExchangeRate('AUD', 'CNY');
if (!$result->isSuccess()) {
throw new BusinessException('获取汇率接口失败');
}
$rate = $result->get('rate');
$result = Api::makeJSAPIOrder(
$order->order_name,
$order->order_no,
$order->currency,
$order->amount,
'http://146.70.113.165:9501/payment/notify',
'http://146.70.113.165:9501/payment/page?order_no=' . $order->order_no
'AUD',
intval($order->amount / $rate),
config('base_url') . '/payment/notify',
config('base_url') . '/payment/page?order_no=' . $order->order_no
);
$this->updateOrderResult($order, $result);
return $order;
@ -85,9 +91,9 @@ class PaymentService extends AbstractService
}
$order = Order::where('order_no', $params['out_order_no'])->where('status', Order::STATUS_WAIT_PAY)->first();
$order->status = Order::STATUS_PAYED;
$order->payed_at = date('Y-m-d');
$order->exchange_rate = $params['exchange_rate'];
$order->cny_amount = $params['cny_amount'];
$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()) {
return 'SUCCESS';

@ -16,6 +16,7 @@ return [
'app_name' => env('APP_NAME', 'skeleton'),
'app_env' => env('APP_ENV', 'dev'),
'scan_cacheable' => env('SCAN_CACHEABLE', false),
'base_url' => env('BASE_URL'),
StdoutLoggerInterface::class => [
'log_level' => [
LogLevel::ALERT,

@ -12,6 +12,6 @@ Router::get('/favicon.ico', function () {
Router::addGroup('/payment',function () {
Router::post('/jsapi', [PayController::class, 'jsapi']);
Router::post('/page', [PageController::class, 'index']);
Router::get('/page', [PageController::class, 'index']);
Router::post('/notify', [PayController::class, 'index']);
});

Loading…
Cancel
Save