POPBill Developers
가이드

튜토리얼

Java 개발환경에서 팝빌 SDK를 추가하여 단문 문자 메시지 전송 (SendSMS) 함수를 구현하는 예시입니다.

1. POPBiLL SDK 추가

① 팝빌 연동자료실에서 Java - JSP SDK 예제코드 다운로드 후 압축을 해제합니다.

② SDK 예제코드의 WEB-INF/lib/ 폴더의 3개 jar파일 구현할 프로젝트의 라이브러리 폴더에 복사합니다.

2. POPBiLL SDK 설정

프로젝트 경로에 문자 서비스 연동환경 설정을 위한 "$CATALINA_HOME/webapps/ROOT/common.jsp" 파일을 생성하고 아래의 코드를 참고하여 API Key 를 설정합니다.

<%-- 문자 서비스 객체 초기화 --%>
<jsp:useBean id="messageService" scope="application" class="com.popbill.api.message.MessageServiceImp"/>

<%-- 링크아이디 --%>
<jsp:setProperty name="messageService" property="linkID" value="TESTER"/>

<%-- 비밀키 --%>
<jsp:setProperty name="messageService" property="secretKey" value="SwWxqU+0TExEXy/9TVjKPExI2VTUMMSLZtJf3Ed8q3I="/>

<%-- 연동환경 설정, true-테스트, false-운영(Production), (기본값:false) --%>
<jsp:setProperty name="messageService" property="test" value="true"/>

<%-- 인증토큰 IP 검증 설정, true-사용, false-미사용, (기본값:true) --%>
<jsp:setProperty name="messageService" property="IPRestrictOnOff" value="true"/>

<%-- 통신 IP 고정, true-사용, false-미사용, (기본값:false) --%>
<jsp:setProperty name="messageService" property="useStaticIP" value="false"/>

<%-- 로컬시스템 시간 사용여부, true-사용, false-미사용, (기본값:true) --%<
<jsp:setProperty name="messageService" property="useLocalTimeYN" value="true"/>

3. SendSMS 기능 구현

"$CATALINA_HOME/webapps/ROOT/SendSMS.jsp" 파일을 생성하고, 아래의 코드를 참조하여 함수 호출 코드를 추가합니다.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>Popbill Message Example</title>
    </head>
<%@ include file="common.jsp" %>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.popbill.api.PopbillException"%>
<%

    /*
     * SMS(단문)를 전송합니다.
     * - 메시지 내용이 90Byte 초과시 메시지 내용은 자동으로 제거됩니다.
     */

    // 팝빌회원 사업자번호
    String testCorpNum = "1234567890";

    // 팝빌회원 아이디
    String testUserID = "testkorea";

    // 발신번호
    String sender = "07043042991";

    // 수신번호
    String receiver = "010111222";

    // 수신자명
    String receiverName = "수신자명";

    // 메시지 내용, 90Byte초과된 내용은 길이가 조정되어 전송됨
    String content = "문자메세지 테스트1";

    // 예약전송일시(yyyyMMddHHmmss), null인 경우 즉시전송
    Date reserveDT = null;

    //	예약전송시 아래의 코드 참조
    //	String reserveDTtxt ="20141230190000";
    //	SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
    //	reserveDT = formatter.parse(reserveDTtxt);

    // 광고문자 전송여부
    Boolean adsYN = false;

    // 요청번호
    // 파트너가 전송 건에 대해 관리번호를 구성하여 관리하는 경우 사용.
    // 1~36자리로 구성. 영문, 숫자, 하이픈(-), 언더바(_)를 조합하여 팝빌 회원별로 중복되지 않도록 할당.
    String requestNum = "";

    String receiptNum = null;
    try {
        receiptNum = messageService.sendSMS(testCorpNum, sender, receiver, receiverName, content, reserveDT, adsYN, testUserID, requestNum);
    } catch (PopbillException pe) {
        //적절한 오류 처리를 합니다. pe.getCode() 로 오류코드를 확인하고, pe.getMessage()로 관련 오류메시지를 확인합니다.
        System.out.println("오류코드 " + pe.getCode());
        System.out.println("오류메시지 " + pe.getMessage());
        throw pe;
    }
%>
    <body>
        <p>Response</p>
        <br/>
        <fieldset>
            <legend>SMS 문자 전송</legend>
            <ul>
                <li>receiptNum (접수번호) :<%=receiptNum%></li>
            </ul>
        </fieldset>
    </body>
</html>

4. 결과 확인

함수 호출 반환 결과는 아래와 같습니다.
- 성공 : Response code 로 숫자 1 반환
- 실패 : PopbillException 으로 음의 정수 8자리 숫자값 오류코드와 오류메시지 반환 [오류코드]