테스트 사이트 - 개발 중인 베타 버전입니다

그누보드 특정게시판에 새글등록시 카카오톡 단톡방이나 친구에게 푸시 알림발송

미나라 2년 전 조회 1,999

구글 바드에게 물어보니 아래 소스로 알려주는데 작동할까요?

 

  // 알림 생성   $notification = array(     'title' => $title,     'content' => $content,   );

  // 알림 전송   $ch = curl_init();   curl_setopt($ch, CURLOPT_URL, 'https://kapi.kakao.com/v2/push/send');   curl_setopt($ch, CURLOPT_POST, true);   curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($notification));   curl_setopt($ch, CURLOPT_HTTPHEADER, array(     'Authorization: Bearer ' . $api_key,     'Content-Type: application/json',   ));   curl_exec($ch);   curl_close($ch); }

// 특정 게시판에 새글 등록시 콜백 함수 function new_article_notification($board_id) {   // 새글 목록 가져오기   $sql = "SELECT * FROM `articles` WHERE `board_id` = $board_id ORDER BY `created_at` DESC LIMIT 1";   $result = $GLOBALS['wpdb']->get_results($sql);

  // 새글이 있으면 알림 보내기   if ($result) {     $article = $result[0];     $title = '새글이 등록되었습니다!';     $content = $article->title;     send_kakao_push_notification($title, $content);   } }

// 새글 등록시 콜백 함수 등록 add_action('new_article_notification', 'new_article_notification'); ?>  

댓글을 작성하려면 로그인이 필요합니다.

답변 2개

2년 전

관리용도이고 무료로 사용하고 싶으시면  텔레그램 봇을 만들어서 텔레그램으로 보내 보세요~

 

class Telegram {     private $botToken;

    public function __construct($botToken) {         $this->botToken = $botToken;     }

    public function sendMessage($chatId, $text) {         $url = "https://api.telegram.org/bot{$this->botToken}/sendMessage";         $params = [             'chat_id' => $chatId,             'text' => $text,         ];

        $ch = curl_init();         curl_setopt($ch, CURLOPT_URL, $url);         curl_setopt($ch, CURLOPT_POST, true);         curl_setopt($ch, CURLOPT_POSTFIELDS, $params);         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);         $result = curl_exec($ch);         curl_close($ch);

        return $result;     } }  

 

require_once 'Telegram.php';

$botToken = 'YOUR_BOT_TOKEN'; $chatId = 'YOUR_CHAT_ID'; $message = 'Hello, Telegram! This is a push notification from PHP.';

$telegram = new Telegram($botToken); $response = $telegram->sendMessage($chatId, $message);

if ($response === false) {     echo 'Failed to send message.'; } else {     echo 'Message sent successfully.'; }  

?>

 

 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

타인에게 보내는 알림톡 자체가 건당 8원 유료인데요?

카카오 채널 비즈니스 인증도 받아야 하구요..

 

위 코드는 안드로이드 앱에서 앱끼리 알림을 주고 받을때 사용하는 코드로 보여집니다.

https://developers.kakao.com/docs/latest/en/push/rest-api

 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인