127 lines
3.6 KiB
PHP
127 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Alipay\EasySDK\Kernel\Config as AlipayConfig;
|
|
use Alipay\EasySDK\Kernel\EasySDKKernel as AlipayKernel;
|
|
use App\Services\SettingService;
|
|
use EasyWeChat\Factory as EasyWeChatFactory;
|
|
use EasyWeChat\Payment\Application as EasyWeChatPaymentApplication;
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Overtrue\EasySms\EasySms;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
$this->registerEasySms();
|
|
$this->registerEasyWeChat();
|
|
$this->registerRequestRealIp();
|
|
$this->registerSettings();
|
|
$this->registerAlipay();
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
Relation::enforceMorphMap([
|
|
'user' => \App\Models\User::class,
|
|
'order' => \App\Models\Order::class,
|
|
'order_refund_log' => \App\Models\OrderRefundLog::class,
|
|
'after_sale' => \App\Models\AfterSale::class,
|
|
'wallet_to_bank_log' => \App\Models\WalletToBankLog::class,
|
|
'balance_log' => \App\Models\BalanceLog::class,
|
|
'distribution_pre_income' => \App\Models\DistributionPreIncome::class,
|
|
'admin_users' => \App\Models\Admin\Administrator::class,
|
|
'quota_v1_send_logs' => \App\Models\QuotaV1SendLog::class,
|
|
]);
|
|
|
|
JsonResource::withoutWrapping();
|
|
}
|
|
|
|
/**
|
|
* 注册微信服务
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerEasyWeChat()
|
|
{
|
|
$this->app->singleton(EasyWeChatPaymentApplication::class, function ($app) {
|
|
return EasyWeChatFactory::payment($app['config']->get('wechat.payment.default'));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 注册短信发送服务
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerEasySms()
|
|
{
|
|
$this->app->singleton(EasySms::class, function ($app) {
|
|
return new EasySms($app['config']->get('easysms'));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 在请求上注册 realIp 宏
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerRequestRealIp()
|
|
{
|
|
Request::macro('realIp', function () {
|
|
return $this->ip();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 注册应用设置服务
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerSettings()
|
|
{
|
|
$this->app->singleton(SettingService::class, function ($app) {
|
|
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);
|
|
});
|
|
}
|
|
}
|