튜토리얼
Java 개발환경에서 팝빌 SDK를 추가하고, 카카오톡 알림톡 전송 (SendATS) API를 호출하는 기본 과정을 단계별로 따라 해볼 수 있도록 구성된 가이드 입니다.
1. POPBiLL SDK 추가
팝빌 Java SDK를 추가하기 위해 Spring 프로젝트 "pom.xml" 파일에 팝빌 Java SDK dependency 정보를 추가하고 Maven 업데이트합니다.
<dependency>
<groupId>kr.co.linkhub</groupId>
<artifactId>popbill-sdk</artifactId>
<version>1.69.0</version>
</dependency>
2. POPBiLL SDK 설정
카카오톡 클래스를 Spring 빈으로 추가합니다. 아래의 코드를 참조하여 "servlet-context.xml" 파일을 수정합니다.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<annotation-driven/>
<resources mapping="/resources/**" location="/resources/"/>
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/"/>
<beans:property name="suffix" value=".jsp"/>
</beans:bean>
<context:component-scan base-package="com.popbill.example"/>
<!--
<테스트 연동개발 준비사항>
1) API Key 변경 (연동신청 시 메일로 전달된 정보)
- LinkID : 팝빌에서 발급한 링크아이디
- SecretKey : 팝빌에서 발급한 비밀키
2) SDK 환경설정 옵션 설정
- IsTest : 연동환경 설정, true-테스트, false-운영(Production), (기본값:false)
- IPRestrictOnOff : 인증토큰 IP 검증 설정, true-사용, false-미사용, (기본값:true)
- UseStaticIP : 통신 IP 고정, true-사용, false-미사용, (기본값:false)
- UseLocalTimeYN : 로컬시스템 시간 사용여부, true-사용, false-미사용, (기본값:true)
-->
<util:properties id="EXAMPLE_CONFIG">
<beans:prop key="LinkID">TESTER</beans:prop>
<beans:prop key="SecretKey">SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=</beans:prop>
<beans:prop key="IsTest">true</beans:prop>
<beans:prop key="IsIPRestrictOnOff">true</beans:prop>
<beans:prop key="UseStaticIP">false</beans:prop>
<beans:prop key="UseLocalTimeYN">true</beans:prop>
</util:properties>
<beans:beans>
<!-- 카카오톡 서비스 객체 초기화 -->
<beans:bean id="kakaoService" class="com.popbill.api.kakao.KakaoServiceImp">
<beans:property name="linkID" value="#{EXAMPLE_CONFIG.LinkID}"/>
<beans:property name="secretKey" value="#{EXAMPLE_CONFIG.SecretKey}"/>
<beans:property name="test" value="#{EXAMPLE_CONFIG.IsTest}"/>
<beans:property name="IPRestrictOnOff" value="#{EXAMPLE_CONFIG.IsIPRestrictOnOff}"/>
<beans:property name="useStaticIP" value="#{EXAMPLE_CONFIG.UseStaticIP}"/>
<beans:property name="useLocalTimeYN" value="#{EXAMPLE_CONFIG.UseLocalTimeYN}"/>
</beans:bean>
</beans:beans>
</beans:beans>
3. SendATS 기능 구현
① 서비스 클래스 빈 객체 추가를 위해 @Autowired 어노테이션과 SendATS 함수 호출 코드를 추가합니다.
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.popbill.api.KakaoService;
import com.popbill.api.PopbillException;
import com.popbill.api.kakao.KakaoButton;
@Controller
public class KakaoServiceExample {
@Autowired
private KakaoService kakaoService;
@RequestMapping(value = "sendATS_one", method = RequestMethod.GET)
public String sendATS_one(Model m) {
// 팝빌회원 사업자번호
String CorpNum = "1234567890";
// 승인된 알림톡 템플릿코드
// └ 알림톡 템플릿 관리 팝업 URL(GetATSTemplateMgtURL API) 함수, 알림톡 템플릿 목록
// 확인(ListATStemplate API) 함수를 호출하거나
// 팝빌사이트에서 승인된 알림톡 템플릿 코드를 확인 가능.
String templateCode = "022070000338";
// 발신번호
// altSendType = 'C' / 'A' 일 경우, 대체문자를 전송할 발신번호
// altSendType = '' 일 경우, null 또는 공백 처리
// ※ 대체문자를 전송하는 경우에는 사전에 등록된 발신번호 입력 필수
String senderNum = "07043042991";
//강조표기 타이틀 (최대 50자)
String emphasizeTitle = "테스트";
// 알림톡 내용 (최대 1000자)
String content = "[ 팝빌 ]\n" +
"신청하신 #{템플릿코드}에 대한 심사가 완료되어 승인 처리되었습니다.\n"
+ "해당 템플릿으로 전송 가능합니다.\n\n"
+ "문의사항 있으시면 파트너센터로 편하게 연락주시기 바랍니다.\n\n"
+ "팝빌 파트너센터 : 1600-8536\n"
+ "support@linkhub.co.kr";
// 대체문자 제목
// - 메시지 길이(90byte)에 따라 장문(LMS)인 경우에만 적용.
String altSubject = "대체문자 제목1234";
// 대체문자 내용, 대체문자 유형(altSendType)이 "A"일 경우, 대체문자로 전송할 내용 (최대 2000byte)
// └ 팝빌이 메시지 길이에 따라 단문(90byte 이하) 또는 장문(90byte 초과)으로 전송처리
String altContent = "대체문자 내용";
// 대체문자 유형 (null , "C" , "A" 중 택 1)
// null = 미전송, C = 알림톡과 동일 내용 전송 , A = 대체문자 내용(altContent)에 입력한 내용 전송
String altSendType = "C";
// 수신번호
String receiverNum = "01022223333";
// 수신자명
String receiverName = "수신자명";
// 전송 예약일시, 형태(yyyyMMddHHmmss)
// - 분단위 전송, 미입력 시 즉시 전송
String sndDT = "";
// 팝빌회원 아이디
String UserID = "testkorea";
// 요청번호
// 팝빌이 접수 단위를 식별할 수 있도록 파트너가 할당한 식별번호.
// 1~36자리로 구성. 영문, 숫자, 하이픈(-), 언더바(_)를 조합하여 팝빌 회원별로 중복되지 않도록 할당.
String requestNum = "";
// 버튼 목록, 알림톡 버튼정보를 템플릿 신청시 기재한 버튼정보와 동일하게 전송하는 경우 null 처리.
KakaoButton[] btns = null;
// 버튼 목록, 알림톡 버튼 URL에 #{템플릿변수}를 기재한경우 템플릿변수 영역을 변경하여 버튼정보 구성
// KakaoButton[] btns = new KakaoButton[1];
// KakaoButton button = new KakaoButton();
// button.setN("버튼명"); // 버튼명
// button.setT("WL"); // 버튼 유형
// button.setU1("https://www.popbill.com"); // 버튼링크
// button.setU2("http://test.popbill.com"); // 버튼링크
// button.setTg("out"); // 아웃 링크
// btns[0] = button;
try {
String receiptNum = kakaoService.sendATS(CorpNum, templateCode, senderNum,
content, altSubject, altContent, altSendType, receiverNum, receiverName,
sndDT, requestNum, btns, emphasizeTitle, UserID);
m.addAttribute("Result", receiptNum);
} catch (PopbillException e) {
// 예외 발생 시, e.getCode() 로 오류 코드를 확인하고, e.getMessage()로 오류 메시지를 확인합니다.
System.out.println("오류 코드" + e.getCode());
System.out.println("오류 메시지" + e.getMessage());
}
return "response";
}
}
② 함수 호출결과 코드와 메시지를 출력하는 response.jsp 파일을 추가합니다.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Popbill SDK Response</title>
</head>
<body>
<p>ReceiptNum (접수번호) : ${Result}</p>
</body>
</html>
4. API 응답결과 확인
API 호출 응답결과는 다음과 같습니다.
| 구분 | 응답 |
| 성공 | ReceiptNum(접수번호) : 18자리 문자열 |
| 실패 |
code : 오류코드 (8자리 음의 정수) [오류코드] message : 오류메시지 |












