47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Bitrix;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class BitrixSender
|
|
{
|
|
public $url;
|
|
public $data;
|
|
public function __construct($url, $data) {
|
|
$this->url = $url;
|
|
$this->data = $data;
|
|
}
|
|
public function send() {
|
|
$postdata = http_build_query(
|
|
$this->data
|
|
);
|
|
$opts = array(
|
|
'ssl' => array(
|
|
'verify_peer' => false,
|
|
'verify_peername' => false
|
|
),
|
|
'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) {
|
|
dd($e);
|
|
return false;
|
|
}
|
|
}
|
|
}
|