59 lines
1.5 KiB
PHP
59 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Bitrix;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class BitrixSender
|
|
{
|
|
public $url;
|
|
public $data;
|
|
public function __construct(string $url, array $data)
|
|
{
|
|
$this->url = $url;
|
|
$this->data = $data;
|
|
}
|
|
public function send()
|
|
{
|
|
$postdata = http_build_query(
|
|
$this->data
|
|
);
|
|
$opts = array(
|
|
'ssl' => array(
|
|
'verify_peer' => true,
|
|
'verify_peername' => true
|
|
),
|
|
'http' => array(
|
|
'method' => 'POST',
|
|
'header' =>
|
|
'Content-type: application/x-www-form-urlencoded' . "\r\n" .
|
|
'',
|
|
'content' => $postdata
|
|
)
|
|
);
|
|
try
|
|
{
|
|
$context = stream_context_create($opts);
|
|
$result = file_get_contents($this->url, false, $context);
|
|
$result = json_decode($result, $associative = true);
|
|
if (array_key_exists('result', $result))
|
|
{
|
|
return $result['result'];
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (\Exception $e)
|
|
{
|
|
Log::build([
|
|
'driver' => 'single',
|
|
'path' => storage_path('logs/bitrix.log'),
|
|
])->error($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|