42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
// config/LineBot.php
|
|
require_once __DIR__ . '/config.php';
|
|
require_once dirname(__DIR__) . '/models/Setting.php';
|
|
|
|
class LineBot {
|
|
|
|
public function sendGroupMessage($message, $jobId = null) {
|
|
$settingModel = new Setting();
|
|
$token = $settingModel->get('line_bot_token', '');
|
|
|
|
if (empty($token)) {
|
|
return false; // Skip if token is not set
|
|
}
|
|
|
|
$text = $message;
|
|
|
|
if ($jobId) {
|
|
$acceptUrl = BASE_URL . "?page=staff&action=accept&job_id=" . $jobId;
|
|
$text .= "\n\n🔗 กดรับงาน: " . $acceptUrl;
|
|
}
|
|
|
|
$queryData = http_build_query([
|
|
'message' => "\n" . $text
|
|
]);
|
|
|
|
// LINE Notify API
|
|
$ch = curl_init('https://notify-api.line.me/api/notify');
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $queryData);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
'Content-Type: application/x-www-form-urlencoded',
|
|
'Authorization: Bearer ' . $token
|
|
));
|
|
$result = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
return $result;
|
|
}
|
|
}
|