본문 바로가기 주메뉴 바로가기
Push Notification

회원 연동 푸시 알림

웹사이트 회원 연동 푸시알림 이용안내 입니다.

1회원 아이디와 스마트폰 디바이스 맵핑

고객님의 앱을 설치한 스마트폰 기기와 웹사이트의 회원아이디를 서로 맵핑(연결) 시키기 위해, 웹사이트에 다음과 같은 JavaScript 내용을 추가합니다.
맵핑한 회원아이디는 회원 연동 푸시서비스에 사용 됩니다.
  • 사용하는 언어는 JavaScript 를 사용합니다.
  • 고객의 앱에서 실행될 때 회원아이디와 스마트폰기기가 맵핑 됩니다.
# CASE 1 운영하는 웹사이트에서 로그인 이후 첫 페이지에 아래 함수를 추가 합니다.
<script language="javascript">
    // 페이지 로딩 직후 앱에서 자동 호출 합니다.
    function callFromApp() {
        if (typeof app_login_complete === 'function') {
            app_login_complete('회원아이디');
        }
    }
</script>
  • callFromApp() 함수는 앱에서 페이지 로딩이 다 끝난 직후 호출하는 함수로 이름을 변경하면 안됩니다.
  • 회원아이디 : 스마트폰 디바이스와 맵핑하기 위해 웹사이트에 로그인 한 회원의 아이디를 넣어 줍니다.
# CASE 2 ajax 방식으로 로그인 처리 한 경우의 사용법 입니다.
function login() {
    ...
    $.ajax({
        type: "POST",
        url: action,
        data: form_data,
        success: function(response) {
            // 로그인 성공시
            if (response == 'success') {
                if (typeof app_login_complete === 'function') {
                    app_login_complete('회원아이디');
                }
            }
            ...
        }
    });
}

2회원연동 푸시 알림 보내기

  • 회원연동 푸시 알림 보내기는 웹사이트에서 appmake_sendpush.js를 include 한 후, sendPush() 함수를 이용해서 전송 합니다.
회원연동 푸시 알림 요청 함수 정의
구분내용
자바스크립트 위치
https://www.appmake.co.kr/asset/js/appmake_sendpush.js
요청함수
sendPush(no, app_srno, send_id, receive_id, title, contents, push_type=1, save_yn='Y', image='', link='')
파라미터 값
· no -> 발송요청번호, 이 번호를 이용하여 결과를 확인
· app_srno -> 앱 고유번호 (앱메이크에서 만드신 앱의 고유번호)
· send_id -> 발송자 회원아이디
· receive_id -> 수신자 회원아이디 (여러명에게 전송할 경우 '|'를 이용)
· title -> 푸시알림 제목
· contents -> 푸시알림 내용
· push_type -> 1 : 상단 노티 + 팝업 (기본값), 2 : 상단 노티만
· save_yn -> Y : 알림정보 저장 (기본값), N : 저장 안함
· image -> 이미지 위치 URL, 없는 경우 ""
· link -> 클릭시 이동할 URL, 없는 경우 ""
회원연동 푸시 알림 결과 함수 정의
구분내용
자바스크립트 위치
해당 페이지에 선언
요청함수
function sendPush_result(data) {
    alert(data.no + ':' + data.result + ":" + data.msg);
}
파라미터 값
· data.no -> 발송요청번호
· data.result -> Y : 발송성공, N : 발송실패
· data.msg -> 발송결과에 따른 메시지
오류메시지 정보
· 발송자 정보가 등록되어 있지 않습니다.
· 수신자 정보가 등록되어 있지 않습니다.
· 등록된 도메인 정보와 맞지 않습니다.
# 예시
<script src="https://www.appmake.co.kr/asset/js/appmake_sendpush.js"></script>
<script>
// Case 1: 팝업푸시 + 상단 노티 표시
function clickButton1() {
    if (typeof sendPush === 'function') {
        sendPush(101, 1234, send_id, receive_id, title, contents);
    }
}

// Case 2: 상단 노티에만 표시
function clickButton2() {
    if (typeof sendPush === 'function') {
        sendPush(102, 1234, send_id, receive_id, title, contents, 2);
    }
}

// Case 3: 이미지 포함 노티
function clickButton3() {
    if (typeof sendPush === 'function') {
        image = 'https://www.website.co.kr/images/push_image_sample.jpg';
        sendPush(103, 1234, send_id, receive_id, title, contents, 2, 'N', image);
    }
}

// Case 4: 이미지 + 링크 URL
function clickButton4() {
    if (typeof sendPush === 'function') {
        image = 'https://www.website.co.kr/images/push_image_sample.jpg';
        link = 'https://sports.v.daum.net/v/20181011170226585?f=m';
        sendPush(104, 1234, send_id, receive_id, title, contents, 1, 'Y', image, link);
    }
}

// 발송 결과
function sendPush_result(data) {
    alert(data.no + ':' + data.result + ":" + data.msg);
}
</script>

3서버사이드 푸시 알림 보내기

  • 고객님의 특정 서버에서 푸시알림 발송하려고 할 때 이용 합니다. [1. 회원아이디와 스마트폰 디바이스 맵핑]이 적용 되어 있어야 합니다.
# PHP 예시
<?php
    $url = 'https://www.appmake.co.kr/PushClient/sendPush4ExtServer';
    $post_data["no"] = 101;
    $post_data["app_srno"] = 1234;
    $post_data["send_id"] = "sender@gmail.com";
    $post_data["receive_id"] = "receiver1@naver.com|receiver2@daum.net";
    $post_data["title"] = "서버에서 푸시발송";
    $post_data["contents"] = "서버에서 보내는 푸시발송 테스트 입니다.";
    $post_data["push_type"] = 1;
    $post_data["save_yn"] = "Y";
    $post_data["image"] = "";
    $post_data["link"] = "https://sports.v.daum.net/v/20181011170226585?f=m";
    $post_data["key"] = "e9Vc0SiPFp9XoMrREnBD79ijmnJTHanmyghABRGm72o=";
    $post_data["from"] = 2;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_POSTFIELDSIZE, 0);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, []);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $res = curl_exec($ch);

    $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $body = substr($res, $header_size);
    $body_json = json_decode($body, true);
    print_r($body_json);

    curl_close($ch);
?>