리눅스로 프로그램을 만들어서 문자로 알림을 받는기능을 찾던중에 텔레그램 봇이 가장 좋을 것 같아서 알아봤다.
TelegramBotPHP를 설치하고, 해당 폴더에서 php를 실행하면 된다.
봇ID와 챗ID는 개인별로 설정을 해줘야하고, 그림을 보낼경우 절대경로(상대경로는 되는지 확인을 안해봤음)와 파일명을 함께 적어줘야한다.
// curl 이 설치되어있어야 한다, 아래 명령어는 curl 설치 명령어
sudo apt-get update
sudo apt-get install php5-curl
// 아래 명령어는 그림보낼때 사용하는 Php 스크립트
sudo git clone https://github.com/Eleirbag89/TelegramBotPHP
문자 보낼때
<?php
include("Telegram.php");
$telegram = new Telegram("봇ID");
$chat_id = "챗ID";
//$telegram = new Telegram($bot_id);
//$chat_id = $telegram->ChatID();
$content = array('chat_id' => $chat_id, 'text' => "Test");
$telegram->sendMessage($content);
?>
그림 보낼때
<?php
include("Telegram.php");
$telegram = new Telegram("봇ID");
$chat_id = "챗ID";
$img = curl_file_create('/var/www/cronjob/cctv.jpg','image/jpg');
$content = array('chat_id' => $chat_id, 'photo' => $img );
$telegram->sendPhoto($content);
?>
사진을 찍어서 텔레그램으로 전송
<?php
$checka= escapeshellcmd('/usr/bin/raspistill -vf -hf -o /var/www/cronjob/cctv.jpg -w 400 -h 300');
$checkb = shell_exec($checka);
include("Telegram.php");
$telegram = new Telegram("봇ID");
$chat_id = "챗ID";
$img = curl_file_create('/var/www/cronjob/cctv.jpg','image/jpg');
$content = array('chat_id' => $chat_id, 'photo' => $img );
$telegram->sendPhoto($content);
?>
'Computer > Programing' 카테고리의 다른 글
Python 실행값을 PHP로 불러오기 (0) | 2019.02.07 |
---|---|
Parsing - Python (0) | 2019.02.07 |
텍스트 분석 후 특정파일만 출력 (0) | 2019.02.07 |
Snoopy 이용법해서 파싱 방법 (0) | 2019.02.07 |
Mysql 입력 출력 (0) | 2019.02.07 |
Parsing - PHP (0) | 2019.02.07 |
CSS 사용법 / 차이 (0) | 2019.02.07 |
접속한 사용자의 IP 주소 기록 php (0) | 2019.02.07 |