Merge branch 'trunk'
This commit is contained in:
commit
4b76902940
2 changed files with 87 additions and 0 deletions
70
app/Lib/LDC/MailjetSms.php
Normal file
70
app/Lib/LDC/MailjetSms.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace App\Lib\LDC;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class MailjetSms
|
||||
{
|
||||
/** @var Application $app */
|
||||
protected $app;
|
||||
/** @var array $config */
|
||||
protected $config = [];
|
||||
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->loadDefaultOptions();
|
||||
}
|
||||
|
||||
protected function loadDefaultOptions(): MailjetSms
|
||||
{
|
||||
$this->config = $this->app['config']->get('services.mailjet');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function buildHttpClient(): Client
|
||||
{
|
||||
return new Client([
|
||||
'allow_redirects' => false,
|
||||
'connect_timeout' => 3,
|
||||
'verify' => false,
|
||||
'headers' => [
|
||||
'User-Agent' => 'LDCMailjetSms/1.0',
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => sprintf('Bearer %s', $this->config['sms_token']),
|
||||
],
|
||||
'timeout' => 5,
|
||||
]);
|
||||
}
|
||||
|
||||
public function send(string $message, string $to, $from = null): ResponseInterface
|
||||
{
|
||||
$from = $from ?? $this->config['sms_from'];
|
||||
$client = $this->buildHttpClient();
|
||||
|
||||
try {
|
||||
$response = $client->post($this->config['sms_endpoint'], [
|
||||
'json' => [
|
||||
'Text' => $message,
|
||||
'From' => $from,
|
||||
'To' => $to,
|
||||
]
|
||||
]);
|
||||
} catch (\GuzzleHttp\Exception\RequestException $ex) {
|
||||
Log::debug('error ' . $ex->getMessage());
|
||||
if (!is_null($ex->getResponse())){
|
||||
Log::debug((string) $ex->getResponse()->getBody());
|
||||
}
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
17
resources/views/emails/exception.blade.php
Normal file
17
resources/views/emails/exception.blade.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Le Gaulois Exception Handler</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>Une erreur est survenue sur le site Le Gaulois</h1>
|
||||
<h2>{{ $exception->getMessage() }}</h2>
|
||||
<p>url : {{ $url ?? 'none' }}</p>
|
||||
<p>date : {{ date('Y-m-d H:i:s') }}</p>
|
||||
<p>code : {{$exception->getCode() }}</p>
|
||||
<p>file : {{$exception->getFile() }}</p>
|
||||
<p>line : {{$exception->getLine() }}</p>
|
||||
<p>Veuillez vérifier les logs pour en voir la trace.</p>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue