/** * Push_test.php * 푸시 알림 테스트 컨트롤러 * * 푸시 알림 기능을 테스트하기 위한 다양한 메소드를 제공합니다. * 개별 알림, 전체 알림, 토큰 테스트 등의 기능이 포함되어 있습니다. * * @author Claude * @version 1.0 * @date 2023-03-05 */ class Push_test extends CI_Controller { /** * 생성자 * 필요한 모델을 로드합니다. */ function __construct() { parent::__construct(); // clib_model 로드 $this->load->model('clib_model'); } /** * 개별 푸시 알림 테스트 * * 하드코딩된 테스트 토큰을 사용하여 개별 푸시 알림을 전송합니다. * 테스트 목적으로만 사용됩니다. */ public function individual_test() { // 테스트 토큰 (실제 테스트 시 유효한 토큰으로 변경 필요) $test_token = "테스트_토큰을_여기에_입력하세요"; // 알림 내용 설정 $title = "개별 알림 테스트"; $message = "이것은 개별 푸시 알림 테스트입니다. " . date('Y-m-d H:i:s'); $image_url = "https://example.com/image.jpg"; // 선택사항 $click_action = "https://example.com"; // 선택사항 // 푸시 알림 전송 $result = $this->clib_model->push_send($test_token, $message, $title, 'test', $image_url, $click_action); // 결과 출력 echo "

개별 푸시 알림 테스트

"; echo "
";
        print_r($result);
        echo "
"; } /** * 전체 푸시 알림 테스트 * * 사용자 유형(기사, 공장, 전체)에 따라 여러 사용자에게 * 테스트 푸시 알림을 전송합니다. * * @param string $user_type 사용자 유형 (engineer, company, all) */ public function broadcast_test($user_type = 'all') { // 사용자 유형에 따른 쿼리 조건 설정 $where = ""; if ($user_type == 'engineer') { $where = "mb_type = 'E' AND mem_fcm_key IS NOT NULL AND mem_fcm_key != ''"; $type_name = "기사"; } else if ($user_type == 'company') { $where = "mb_type = 'C' AND mem_fcm_key IS NOT NULL AND mem_fcm_key != ''"; $type_name = "공장"; } else { $where = "mem_fcm_key IS NOT NULL AND mem_fcm_key != ''"; $type_name = "전체"; } // 알림 내용 설정 $title = "{$type_name} 알림 테스트"; $message = "이것은 {$type_name} 푸시 알림 테스트입니다. " . date('Y-m-d H:i:s'); $image_url = "https://example.com/image.jpg"; // 선택사항 $click_action = "https://example.com"; // 선택사항 // 사용자 토큰 가져오기 $users = $this->clib_model->user_fetch($where); $tokens = array(); // 토큰 배열 생성 foreach ($users as $user) { if (!empty($user['mem_fcm_key'])) { $tokens[] = $user['mem_fcm_key']; } } // 결과 출력 시작 echo "

{$type_name} 푸시 알림 테스트

"; echo "

대상 사용자 수: " . count($tokens) . "명

"; // 토큰이 있는 경우에만 푸시 알림 전송 if (count($tokens) > 0) { $result = $this->clib_model->push_send($tokens, $message, $title, 'test', $image_url, $click_action); echo "
";
            print_r($result);
            echo "
"; } else { echo "

푸시 알림을 받을 수 있는 사용자가 없습니다.

"; } } /** * 토큰 테스트 폼 * * 사용자가 직접 FCM 토큰과 알림 내용을 입력하여 * 푸시 알림을 테스트할 수 있는 폼을 제공합니다. */ public function token_test() { // 폼 HTML 출력 echo ' FCM 토큰 테스트

FCM 토큰 테스트

테스트할 FCM 토큰을 입력하세요. 여러 토큰은 쉼표로 구분하세요.
'; } /** * 토큰 테스트 실행 * * 사용자가 입력한 FCM 토큰과 알림 내용으로 * 푸시 알림을 전송하고 결과를 표시합니다. */ public function send_token_test() { // POST 데이터 가져오기 $token = $this->input->post('token'); $title = $this->input->post('title'); $message = $this->input->post('message'); $image_url = $this->input->post('image_url'); $click_action = $this->input->post('click_action'); // 토큰을 배열로 변환 (쉼표로 구분된 여러 토큰 지원) $token_array = explode(',', $token); // 결과 출력 시작 echo ' FCM 토큰 테스트 결과

FCM 토큰 테스트 결과

'; // 푸시 알림 전송 $result = $this->clib_model->push_send($token_array, $message, $title, 'test', $image_url, $click_action); // 결과 출력 echo '
';
        print_r($result);
        echo '
'; echo '다시 테스트'; echo '
'; } }