Lae/app/Providers/AppServiceProvider.php

108 lines
3.2 KiB
PHP
Raw Normal View History

2022-08-12 07:56:56 +00:00
<?php
namespace App\Providers;
2022-08-19 09:51:52 +00:00
use Illuminate\Support\Facades\Http;
// use Illuminate\Support\Facades\Storage;
2022-10-29 05:53:32 +00:00
use Illuminate\Support\ServiceProvider;
2022-10-30 02:29:59 +00:00
2022-08-12 07:56:56 +00:00
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
2022-09-08 16:12:02 +00:00
require_once app()->basePath('app') . '/Helpers.php';
2022-08-12 07:56:56 +00:00
}
public function boot()
{
2022-10-29 05:53:32 +00:00
$this->generateInstanceId();
// $this->app->make(\Illuminate\Notifications\ChannelManager::class)->extend('your-channel', function () {
// return $this->app->make(App\Channels\YourChannel::class);
// });
2022-08-12 07:56:56 +00:00
//
2022-08-19 09:51:52 +00:00
2022-09-09 04:56:23 +00:00
// header('server: Cluster Ready!');
// header('x-powered-by: LaeCloud');
// header('x-for-you: Code is Poetry.');
2022-09-08 16:12:02 +00:00
2022-08-19 09:51:52 +00:00
Http::macro('remote', function ($api_token, $url) {
2022-08-27 08:28:39 +00:00
// 关闭证书验证
return Http::withoutVerifying()->withHeaders([
2022-08-19 09:51:52 +00:00
'X-Remote-Api-Token' => $api_token,
2022-08-29 09:31:08 +00:00
'Content-Type' => 'application/json'
2022-10-04 10:34:23 +00:00
])->withOptions([
'version' => 2,
2022-08-19 09:51:52 +00:00
])->baseUrl($url);
});
2022-10-30 02:29:59 +00:00
// $wechat_pay_config = [
// 'mch_id' => config('payment.wepay.mch_id'),
2022-09-01 09:48:29 +00:00
2022-10-30 02:29:59 +00:00
// // 商户证书
// 'private_key' => __DIR__ . '/certs/apiclient_key.pem',
// 'certificate' => __DIR__ . '/certs/apiclient_cert.pem',
2022-09-01 09:48:29 +00:00
2022-10-30 02:29:59 +00:00
// // v3 API 秘钥
// 'secret_key' =>
// config('payment.wepay.v3_secret_key'),
2022-09-01 09:48:29 +00:00
2022-10-30 02:29:59 +00:00
// // v2 API 秘钥
// 'v2_secret_key' => config('payment.wepay.v2_secret_key'),
2022-09-01 09:48:29 +00:00
2022-10-30 02:29:59 +00:00
// // 平台证书:微信支付 APIv3 平台证书,需要使用工具下载
// // 下载工具https://github.com/wechatpay-apiv3/CertificateDownloader
// 'platform_certs' => [
// // '/path/to/wechatpay/cert.pem',
// ],
2022-09-01 09:48:29 +00:00
2022-10-30 02:29:59 +00:00
// /**
// * 接口请求相关配置,超时时间等,具体可用参数请参考:
// * https://github.com/symfony/symfony/blob/5.3/src/Symfony/Contracts/HttpClient/HttpClientInterface.php
// */
// 'http' => [
// 'throw' => true, // 状态码非 200、300 时是否抛出异常,默认为开启
// 'timeout' => 5.0,
// ],
// ];
2022-09-01 09:48:29 +00:00
2022-10-30 02:29:59 +00:00
// $app = new WePay($wechat_pay_config);
2022-09-01 09:48:29 +00:00
2022-10-30 02:29:59 +00:00
// // mount app to global
// app()->instance('wepay', $app);
2022-08-12 07:56:56 +00:00
}
2022-10-29 05:53:32 +00:00
public function generateInstanceId()
{
if (config('app.instance_id') == null) {
2022-10-30 02:29:59 +00:00
$instance_id = uniqid();
2022-10-29 05:53:32 +00:00
// 获取 .env 目录
$env_path = dirname(__DIR__) . '/../.env';
// 追加到 .env 文件
file_put_contents($env_path, PHP_EOL . "INSTANCE_ID={$instance_id}", FILE_APPEND);
2022-10-31 07:35:59 +00:00
// 重新加载配置
config(['app.instance_id' => $instance_id]);
2022-10-29 05:53:32 +00:00
// $env = file_get_contents(app()->environmentFilePath());
// $env = preg_replace('/INSTANCE_ID=(.*)/', 'INSTANCE_ID=' . $instance_id, $env);
// file_put_contents(app()->environmentFilePath(), $env);
}
}
2022-08-12 07:56:56 +00:00
}