94 lines
2.2 KiB
PHP
94 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
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();
|
|
}
|
|
|
|
/**
|
|
* 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,
|
|
]);
|
|
|
|
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']);
|
|
});
|
|
}
|
|
}
|