lk.zachem.info/app/Models/Bitrix/BitrixSender.php
2024-12-11 23:43:54 +08:00

49 lines
1.2 KiB
PHP

<?php
namespace App\Models\Bitrix;
use App\Models\Company;
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;
}
}
}