mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-28 21:40:50 +00:00
28 lines
687 B
PHP
28 lines
687 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace crmeb\services\bot;
|
|
|
|
use crmeb\utils\Http;
|
|
|
|
abstract class BaseBot implements BotInterface
|
|
{
|
|
protected string $webhook = '';
|
|
|
|
public function setWebhook(string $webhook): void
|
|
{
|
|
$this->webhook = $webhook;
|
|
}
|
|
|
|
protected function request(array $data): bool
|
|
{
|
|
if (empty($this->webhook)) return false;
|
|
try {
|
|
$response = Http::postRequest($this->webhook, json_encode($data));
|
|
$result = json_decode($response, true);
|
|
return ($result['errcode'] ?? -1) === 0 || ($result['code'] ?? -1) === 0;
|
|
} catch (\Throwable $e) {
|
|
return false;
|
|
}
|
|
}
|
|
} |