POPBill Developers
가이드

튜토리얼

Java 개발환경에서 팝빌 SDK를 추가하여 휴폐업 대량조회 (CheckCorpNums) 함수를 구현하는 예시입니다.

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. CheckCorpNums 기능 구현

① 휴폐업조회 서비스 클래스 빈 객체 추가를 위해 @Autowired 어노테이션과 CheckCorpNums 함수 코드를 추가합니다.

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.CloseDownService;
import com.popbill.api.CorpState;
import com.popbill.api.PopbillException;

@Controller
public class ClosedownServiceController {

    @Autowired
    private CloseDownService closedownService;

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

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

        // 조회할 사업자번호 배열, 최대 1000건
        String[] CorpNumList = new String[]{"1231212312","6798700433"};

        try {

            CorpState[] corpStates = closedownService.CheckCorpNum(corpNum, CorpNumList);

            m.addAttribute("CorpStates", corpStates);

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

        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>
    <fieldset th:each="CorpState, index : ${CorpStates}">
      <ul>
        <li>corpNum (사업자번호) : <span th:text="${CorpState.corpNum}"></span></li>
        <li>type (사업 유형) : <span th:text="${CorpState.type}"></span></li>
        <li>state (휴폐업 상태) : <span th:text="${CorpState.state}"></span></li>
        <li>stateDate (휴폐업일자) : <span th:text="${CorpState.stateDate}"></span></li>
        <li>typeDate (과세유형 전환일자) : <span th:text="${CorpState.typeDate}"></span></li>
        <li>checkDate (확인일자) : <span th:text="${CorpState.checkDate}"></span></li>
      </ul>
    </fieldset>
  </body>
</html>

4. 결과 확인

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