支付宝
parent
1592f13ff5
commit
5f97414495
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Endpoint\Callback\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class AlipayController extends Controller
|
||||||
|
{
|
||||||
|
public function paidNotify(Request $request)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Endpoint\Callback\Http\Controllers\AlipayController;
|
||||||
use App\Endpoint\Callback\Http\Controllers\Kuaidi100Controller;
|
use App\Endpoint\Callback\Http\Controllers\Kuaidi100Controller;
|
||||||
use App\Endpoint\Callback\Http\Controllers\WeChatPayController;
|
use App\Endpoint\Callback\Http\Controllers\WeChatPayController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
@ -9,3 +10,5 @@ Route::post('kuaidi100', [Kuaidi100Controller::class, 'notify']);
|
||||||
// 微信支付通知
|
// 微信支付通知
|
||||||
Route::post('wxpay/paid-notify', [WeChatPayController::class, 'paidNotify'])->name('wxpay.paid_notify');
|
Route::post('wxpay/paid-notify', [WeChatPayController::class, 'paidNotify'])->name('wxpay.paid_notify');
|
||||||
Route::post('wxpay/order-refund-notify', [WeChatPayController::class, 'orderRefundedNotify'])->name('wxpay.order_refund_notify');
|
Route::post('wxpay/order-refund-notify', [WeChatPayController::class, 'orderRefundedNotify'])->name('wxpay.order_refund_notify');
|
||||||
|
|
||||||
|
Route::post('alipay/paid-notify', [AlipayController::class, 'paidNotify'])->name('alipay.paid_notify');
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ class PayLog extends Model
|
||||||
public const PAY_WAY_WXPAY_JSAPI = 'wxpay_jsapi'; // 微信支付 - JSAPI 支付
|
public const PAY_WAY_WXPAY_JSAPI = 'wxpay_jsapi'; // 微信支付 - JSAPI 支付
|
||||||
public const PAY_WAY_WXPAY_MINI = 'wxpay_mini'; // 微信支付 - 小程序支付
|
public const PAY_WAY_WXPAY_MINI = 'wxpay_mini'; // 微信支付 - 小程序支付
|
||||||
public const PAY_WAY_WXPAY_H5 = 'wxpay_h5'; // 微信支付 - H5 支付
|
public const PAY_WAY_WXPAY_H5 = 'wxpay_h5'; // 微信支付 - H5 支付
|
||||||
|
public const PAY_ALIPAY_APP = 'alipay_app'; // 支付宝 - app 支付
|
||||||
public const PAY_WAY_WALLET = 'wallet'; // 钱包付款(可提现)
|
public const PAY_WAY_WALLET = 'wallet'; // 钱包付款(可提现)
|
||||||
public const PAY_WAY_BALANCE = 'balance'; // 余额支付
|
public const PAY_WAY_BALANCE = 'balance'; // 余额支付
|
||||||
public const PAY_WAY_OFFLINE = 'offline'; // 线下支付
|
public const PAY_WAY_OFFLINE = 'offline'; // 线下支付
|
||||||
|
|
@ -78,6 +79,18 @@ class PayLog extends Model
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认支付方式是否是支付宝付款
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isAlipay(): bool
|
||||||
|
{
|
||||||
|
return in_array($this->pay_way, [
|
||||||
|
static::PAY_ALIPAY_APP,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 确认支付方式是否是线下支付
|
* 确认支付方式是否是线下支付
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use Alipay\EasySDK\Kernel\Config as AlipayConfig;
|
||||||
|
use Alipay\EasySDK\Kernel\EasySDKKernel as AlipayKernel;
|
||||||
use App\Services\SettingService;
|
use App\Services\SettingService;
|
||||||
use EasyWeChat\Factory as EasyWeChatFactory;
|
use EasyWeChat\Factory as EasyWeChatFactory;
|
||||||
use EasyWeChat\Payment\Application as EasyWeChatPaymentApplication;
|
use EasyWeChat\Payment\Application as EasyWeChatPaymentApplication;
|
||||||
|
|
@ -24,6 +26,7 @@ class AppServiceProvider extends ServiceProvider
|
||||||
$this->registerEasyWeChat();
|
$this->registerEasyWeChat();
|
||||||
$this->registerRequestRealIp();
|
$this->registerRequestRealIp();
|
||||||
$this->registerSettings();
|
$this->registerSettings();
|
||||||
|
$this->registerAlipay();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -95,4 +98,29 @@ class AppServiceProvider extends ServiceProvider
|
||||||
return new SettingService($app['cache.store']);
|
return new SettingService($app['cache.store']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册应用支付宝服务
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function registerAlipay()
|
||||||
|
{
|
||||||
|
$this->app->singleton(AlipayKernel::class, function ($app) {
|
||||||
|
$alipayConfigs = $app['config']->get('alipay');
|
||||||
|
|
||||||
|
$config = new AlipayConfig();
|
||||||
|
$config->protocol = 'https';
|
||||||
|
$config->gatewayHost = 'openapi.alipay.com';
|
||||||
|
$config->signType = 'RSA2';
|
||||||
|
$config->appId = $alipayConfigs['app_id'];
|
||||||
|
$config->merchantPrivateKey = $alipayConfigs['app_private_key'];
|
||||||
|
$config->merchantCertPath = $alipayConfigs['app_public_cert_path'];
|
||||||
|
$config->alipayCertPath = $alipayConfigs['public_cert_path'];
|
||||||
|
$config->alipayRootCertPath = $alipayConfigs['root_cert_path'];
|
||||||
|
$config->notifyUrl = $alipayConfigs['notify_url'] ?? url(route('alipay.paid_notify', [], false), [], true);
|
||||||
|
|
||||||
|
return new AlipayKernel($config);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Alipay\EasySDK\Kernel\EasySDKKernel;
|
||||||
|
use Alipay\EasySDK\Payment\App\Client as AppClient;
|
||||||
|
|
||||||
|
class AlipayService
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected EasySDKKernel $kernel,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付
|
||||||
|
*
|
||||||
|
* @param array $params
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function pay(array $params)
|
||||||
|
{
|
||||||
|
$result = (new AppClient($this->kernel))->pay(
|
||||||
|
$params['subject'],
|
||||||
|
$params['out_trade_no'],
|
||||||
|
$params['total_amount'],
|
||||||
|
);
|
||||||
|
|
||||||
|
return $result->body;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -779,29 +779,39 @@ class OrderService
|
||||||
}
|
}
|
||||||
} while ($payLog === null);
|
} while ($payLog === null);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'pay_sn' => $payLog->pay_sn,
|
||||||
|
];
|
||||||
|
|
||||||
// 如果支付方式为线下支付,或支付金额为 0,则按支付完成处理
|
// 如果支付方式为线下支付,或支付金额为 0,则按支付完成处理
|
||||||
if ($payLog->isOffline() || $order->total_amount === 0) {
|
if ($order->total_amount === 0 || $payLog->isOffline()) {
|
||||||
return (new PayService())->handleSuccess($payLog, [
|
(new PayService())->handleSuccess($payLog, [
|
||||||
'pay_at' => now(),
|
'pay_at' => now(),
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
if ($payLog->isWxpay()) {
|
$data = null;
|
||||||
|
} elseif ($payLog->isWxpay()) {
|
||||||
if (! isset(WeChatPayService::$tradeTypes[$payLog->pay_way])) {
|
if (! isset(WeChatPayService::$tradeTypes[$payLog->pay_way])) {
|
||||||
throw new BizException('支付方式不支持');
|
throw new BizException('支付方式不支持');
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new WeChatPayService())->pay([
|
$data = (new WeChatPayService())->pay([
|
||||||
'body' => app_settings('app.app_name').'-商城订单',
|
'body' => app_settings('app.app_name').'-商城订单',
|
||||||
'out_trade_no' => $payLog->pay_sn,
|
'out_trade_no' => $payLog->pay_sn,
|
||||||
'total_fee' => $order->total_amount,
|
'total_fee' => $order->total_amount,
|
||||||
'trade_type' => WeChatPayService::$tradeTypes[$payLog->pay_way],
|
'trade_type' => WeChatPayService::$tradeTypes[$payLog->pay_way],
|
||||||
]);
|
]);
|
||||||
|
} elseif ($payLog->isAlipay()) {
|
||||||
|
$data = app(AlipayService::class)->pay([
|
||||||
|
'subject' => app_settings('app.app_name').'-商城订单',
|
||||||
|
'out_trade_no' => $payLog->pay_sn,
|
||||||
|
'total_amount' => bcdiv($order->total_amount, 100, 2),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'pay_sn' => $payLog->pay_sn,
|
|
||||||
'pay_way' => $payLog->pay_way,
|
'pay_way' => $payLog->pay_way,
|
||||||
|
'data' => $data,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.0",
|
"php": "^8.0",
|
||||||
"alibabacloud/sts": "^1.8",
|
"alibabacloud/sts": "^1.8",
|
||||||
|
"alipaysdk/easysdk": "^2.2",
|
||||||
"alphasnow/aliyun-oss-laravel": "^3.0",
|
"alphasnow/aliyun-oss-laravel": "^3.0",
|
||||||
"dcat/laravel-admin": "2.1.5-beta",
|
"dcat/laravel-admin": "2.1.5-beta",
|
||||||
"fruitcake/laravel-cors": "^2.0",
|
"fruitcake/laravel-cors": "^2.0",
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
// 应用 ID
|
||||||
|
'app_id' => env('ALIPAY_APP_ID'),
|
||||||
|
// 应用私钥证书
|
||||||
|
'app_private_key' => env('ALIPAY_APP_PRIVATE_KEY'),
|
||||||
|
// 应用公钥证书文件路径
|
||||||
|
'app_public_cert_path' => env('ALIPAY_APP_PUBLIC_CERT_PATH'),
|
||||||
|
// 支付宝公钥证书文件路径
|
||||||
|
'public_cert_path' => env('ALIPAY_PUBLIC_CERT_PATH'),
|
||||||
|
// 支付宝根证书文件路径
|
||||||
|
'root_cert_path' => env('ALIPAY_ROOT_CERT_PATH'),
|
||||||
|
];
|
||||||
Loading…
Reference in New Issue