웹에서 내 휴대폰을 이용해서 문자 보내기
웹에서 내 휴대폰을 이용해서 문자 보내기
*실행되는 순서*
웹 발신명령 -> ntfy 로 명령수신 -> 테스커에서 응답 문자발송
<?php
function send_sms_via_tasker($receiver_phone, $sms_content) {
$topic = "고유 토픽명"; // 1단계에서 정한 고유 토픽명
$url = "https://ntfy.sh/" . $topic;
$headers = [
"Title: " . $receiver_phone, // 수신자 전화번호를 Title 헤더로 전달
"Priority: urgent", // 즉각 수신을 위해 높은 우선순위 설정
"Content-Type: text/plain; charset=utf-8"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sms_content); // 문자 본문
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ($http_code == 200);
}
// 실행 예시
$target_number = "발송할 전화번호";
$message = "주문이 정상적으로 접수되었습니다. (자동 발송)";
if (send_sms_via_tasker($target_number, $message)) {
echo "문자 발송 요청 전송 성공";
} else {
echo "문자 발송 요청 실패";
}
?>
*실행되는 순서*
웹 발신명령 -> ntfy 로 명령수신 -> 테스커에서 응답 문자발송
<?php
function send_sms_via_tasker($receiver_phone, $sms_content) {
$topic = "고유 토픽명"; // 1단계에서 정한 고유 토픽명
$url = "https://ntfy.sh/" . $topic;
$headers = [
"Title: " . $receiver_phone, // 수신자 전화번호를 Title 헤더로 전달
"Priority: urgent", // 즉각 수신을 위해 높은 우선순위 설정
"Content-Type: text/plain; charset=utf-8"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sms_content); // 문자 본문
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ($http_code == 200);
}
// 실행 예시
$target_number = "발송할 전화번호";
$message = "주문이 정상적으로 접수되었습니다. (자동 발송)";
if (send_sms_via_tasker($target_number, $message)) {
echo "문자 발송 요청 전송 성공";
} else {
echo "문자 발송 요청 실패";
}
?>
댓글