43 lines
799 B
PHP
43 lines
799 B
PHP
|
<?php
|
||
|
|
||
|
|
||
|
namespace BMail;
|
||
|
|
||
|
use GuzzleHttp\Client;
|
||
|
|
||
|
|
||
|
class BMailApi
|
||
|
{
|
||
|
/**
|
||
|
* The API key
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
private $api_key;
|
||
|
|
||
|
public function __construct(string $api_key)
|
||
|
{
|
||
|
$this->api_key = $api_key;
|
||
|
}
|
||
|
|
||
|
public function send($template)
|
||
|
{
|
||
|
$url = "http://127.0.0.1:9000/api/project/template/send";
|
||
|
|
||
|
// TODO
|
||
|
// $url = "http://127.0.0.1:9000/api/project/template/send";
|
||
|
|
||
|
$client = new Client();
|
||
|
|
||
|
try {
|
||
|
return $client->request('post', $url, [
|
||
|
'form_params' => $template,
|
||
|
'headers' => ['Authorization' => 'Bearer ' . $this->api_key]
|
||
|
])->getBody();
|
||
|
|
||
|
} catch(\Exception $e) {
|
||
|
throw new BMailException($e->getMessage());
|
||
|
}
|
||
|
}
|
||
|
}
|