加入CACTI程式裡, 取代原有的2G簡訊系統, 改由LineNotify
增加在plugins: settings & thold 的function 內
#
vim plugins/settings/include/functions.php
function send_mail {}
#
vim plugins/thold/thold_functions.php
function thold_mail {}
$subject 是要傳送的文字訊息.
## line token
$ch = curl_init();
$lineurl="https://notify-api.line.me/api/notify" ;
$linehead=array("Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXX");
$linefields=array("message" => $subject);
curl_setopt($ch, CURLOPT_URL, $lineurl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $linehead);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $linefields);
curl_exec($ch);
curl_close($ch);
另一種方式, curl 命令模式:
$ curl -X POST https://notify-api.line.me/api/notify \
-H 'Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXX \
-F 'message=alert' \
-F 'imageFile=@/tmp/alert.jpg'
第三種, 附加圖檔(jpeg or png)
function
curl_file_create() 產生上傳檔案
<?php
if (!function_exists('curl_file_create')) {
function curl_file_create($filename, $mimetype = '', $postname = '') {
return "@$filename;filename="
.($postname ?: basename($filename))
.($mimetype ? ";type=$mimetype" : '');
}
}
$ch = curl_init();
$lineurl="https://notify-api.line.me/api/notify" ;
$linehead=array("
Content-Type: multipart/form-data",
"Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXX");
$linefields = array('
message' => 'Alert',
'
imageFile' =>
curl_file_create('/tmp/alert.jpg'));
curl_setopt($ch, CURLOPT_URL, $lineurl);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $linehead);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $linefields);
curl_exec($ch);
curl_close($ch);
?>