POPBill Developers
가이드

튜토리얼

Java 개발환경에서 팝빌 SDK를 추가하여 계좌 거래내역 수집요청 (RequestJob) 함수를 구현하는 예시입니다.

1. POPBiLL SDK 추가

팝빌 Java SDK를 추가하기 위해 Spring 프로젝트 "pom.xml" 파일에 팝빌 Java SDK dependency 정보를 추가하고 Maven 업데이트합니다.

<dependency>
    <groupId>kr.co.linkhub</groupId>
    <artifactId>popbill-sdk</artifactId>
    <version>1.63.1</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"/>

    <util:properties id="EXAMPLE_CONFIG">
        <!-- 링크아이디 -->
        <beans:prop key="LinkID">TESTER</beans:prop>
        <!-- 비밀키 -->
        <beans:prop key="SecretKey">SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=</beans:prop>
        <!-- 연동환경 설정값 true(개발용), false(상업용) -->
        <beans:prop key="IsTest">true</beans:prop>
        <!-- 인증토큰 아이피 제한 기능 사용여부 권장(true) -->
        <beans:prop key="IsIPRestrictOnOff">true</beans:prop>
        <!-- 팝빌 API 서비스 고정 IP 사용여부, true-사용, false-미사용, 기본값(false) -->
        <beans:prop key="UseStaticIP">false</beans:prop>
        <!-- 로컬시스템 시간 사용여부 true-사용(기본값-권장), false-미사용 -->
        <beans:prop key="UseLocalTimeYN">true</beans:prop>
    </util:properties>

    <beans:beans>
        <!-- 계좌조회 Service Implementation Bean registration.  -->
        <beans:bean id="easyFinBankService"
            class="com.popbill.api.easyfin.EasyFinBankServiceImp">
            <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. RequestJob 기능 구현

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

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

@Controller
public class EasyFinBankServiceExample {

    @Autowired
    private EasyFinBankService easyFinBankService;

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

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

        // 기관코드
        String BankCode = "0048";

        // 계좌번호
        String AccountNumber = "3011599770921";

        // 시작일자, 날짜형식(yyyyMMdd)
        String SDate = "20220101";

        // 종료일자, 닐짜형식(yyyyMMdd)
        String EDate = "20220130";

        try {
            /*
             * 계좌 거래내역 수집을 요청합니다.
             * - 검색기간은 현재일 기준 90일 이내로만 요청할 수 있습니다.
             * - 수집 요청후 반환받은 작업아이디(JobID)의 유효시간은 1시간 입니다.
            */
            String jobID = easyFinBankService.requestJob(testCorpNum, BankCode, AccountNumber, SDate, EDate);
            m.addAttribute("Result", jobID);

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

        return "response";
    }

}

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

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>Popbill Spring Example</title>
</head>
<body>
<div>
    <p>Response</p>
    <br>
    <fieldset>
        <legend>수집요청</legend>
        <ul>
            <li>JobID(작업아이디) : ${Result}</li>
        </ul>
    </fieldset>
</div>
</body>
</html>

4. 결과 확인

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