AppServiceProvider.php 964 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Support\ServiceProvider;
  4. use Laravel\Cashier\Cashier;
  5. use GuzzleHttp\Client as HttpClient;
  6. class AppServiceProvider extends ServiceProvider
  7. {
  8. /**
  9. * Bootstrap any application services.
  10. *
  11. * @return void
  12. */
  13. public function boot()
  14. {
  15. Cashier::useCurrency(config('cart.currency'), config('cart.currency_symbol'));
  16. }
  17. /**
  18. * Register any application services.
  19. *
  20. * @return void
  21. */
  22. public function register()
  23. {
  24. // 以单例模式绑定 HttpClient 实例到 App 容器
  25. $this->app->singleton('HttpClient', function ($app) {
  26. return new HttpClient([
  27. 'base_uri' => config('services.micro.api_gateway'),
  28. 'timeout' => config('services.micro.timeout'),
  29. 'headers' => [
  30. 'Content-Type' => 'application/json'
  31. ]
  32. ]);
  33. });
  34. }
  35. }