POPBill Developers
가이드

튜토리얼

Java 개발환경에서 팝빌 SDK를 추가하여 카카오톡 알림톡 전송 (SendATS) 함수를 구현하는 예시입니다.

1. POPBiLL SDK 추가

Popbill SpringBoot Starter 추가를 위해 SpringBoot 프로젝트 "build.gradle" 파일에 dependency를 추가 후 Refresh 합니다.
※ Popbill SpringBoot Starter는 SpringBoot v1.0 이상에서 사용 가능하며 Popbill Java SDK AutoConfiguration을 지원합니다.

dependencies {
    implementation 'kr.co.linkhub:popbill-spring-boot-starter:1.14.3'
}

2. POPBiLL SDK 설정

SDK 설정을 위해 아래의 코드를 application.yml 파일에 추가합니다.

popbill:
  #링크아이디
  linkId: TESTER
  #비밀키
  secretKey: SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=
  #연동환경 설정, true-테스트, false-운영(Production), (기본값:false)
  isTest: true
  #인증토큰 IP 검증 설정, true-사용, false-미사용, (기본값:true)
  isIpRestrictOnOff: true
  #통신 IP 고정, true-사용, false-미사용, (기본값:false)
  useStaticIp: false
  #로컬시스템 시간 사용여부, true-사용, false-미사용, (기본값:true)
  useLocalTimeYn: true

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 KakaoServiceController {

    @Autowired
    private KakaoService kakaoService;

    @RequestMapping(value = "sendATS", method = RequestMethod.GET)
    public String sendATS_one(Model m) {

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

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

        // 알림톡 템플릿코드
        // 승인된 알림톡 템플릿 코드는 ListATStemplate API, GetATSTemplateMgtURL API, 또는 팝빌사이트에서 확인 가능합니다.
        String templateCode = "019020000163";

        // 발신번호 (팝빌에 등록된 발신번호만 이용가능)
        String senderNum = "07043042991";

        // 알림톡 내용 (최대 1000자)
        String content = "[ 팝빌 ]\n";
        content += "신청하신 #{템플릿코드}에 대한 심사가 완료되어 승인 처리되었습니다.\n";
        content += "해당 템플릿으로 전송 가능합니다.\n\n";
        content += "문의사항 있으시면 파트너센터로 편하게 연락주시기 바랍니다.\n\n";
        content += "팝빌 파트너센터 : 1600-8536\n";
        content += "support@linkhubcorp.com";

        // 대체문자 내용 (최대 2000byte)
        String altContent = "대체문자 내용";

        // 대체문자 전송유형, 공백-미전송, C-알림톡 내용전송, A-대체문자 내용 전송
        String altSendType = "C";

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

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

        // 예약전송일시, 형태(yyyyMMddHHmmss)
        String sndDT = "";

        // 요청번호
        // 파트너가 전송 건에 대해 관리번호를 구성하여 관리하는 경우 사용.
        // 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"); // 버튼링크1
        //        button.setU2("http://test.popbill.com"); // 버튼링크2
        //        btns[0] = button;

        try {

            String receiptNum = kakaoService.sendATS(corpNum, templateCode, senderNum, content, altContent,
            altSendType, receiverNum, receiverName, sndDT, userID, requestNum, btns);

            m.addAttribute("Result", receiptNum);

        } catch (PopbillException e) {
            // 예외 발생 시, e.getCode() 로 오류 코드를 확인하고, e.getMessage()로 오류 메시지를 확인합니다.
            System.out.println("오류 코드" + e.getCode());
            System.out.println("오류 메시지" + e.getMessage());
            m.addAttribute("Result", "오류 코드와 메시지를 확인하세요.");
        }

        return "response";
    }
}

② 함수 호출결과 코드와 메시지를 출력하는 response.html 파일을 추가합니다.

<html xmlns:th="http://www.thymeleaf.org"">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Popbill SDK Response</title>
  </head>
  <body>

    <ul>
      <li>접수번호(ReceiptNum) : <span th:text="${Result}"></span></li>
    </ul>
  </body>
</html>

4. 결과 확인

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