POPBill Developers
  • 가이드
  • API Reference
  • SDK
  • 오류코드
팩스
  • 전자세금계산서
  • 현금영수증
  • 전자명세서
  • 홈택스수집(세금)
  • 홈택스수집(현금)
  • 사업자등록상태조회
  • 기업정보조회
  • 계좌조회
  • 예금주조회
  • 카카오톡
  • 문자
  • 팩스
Java
  • Java
  • PHP
  • .NET
  • .NET Core
  • Node.js
  • Python
  • Ruby
  • ASP
  • Delphi
  • PowerBuilder
  • Visual Basic
  • MS Access
가이드

튜토리얼

Java 개발환경에서 팝빌 SDK를 추가하여 팩스 전송 (SendFAX) 함수를 구현하는 예시입니다.

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.17.0'
}

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

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

import java.io.File;
import java.net.URISyntaxException;
import java.util.Date;

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

@Controller
public class FaxServiceController {

    @Autowired
    private FaxService faxService;

    @RequestMapping(value = "sendFAX", method = RequestMethod.GET)
    public String sendFAX(Model m) throws URISyntaxException {

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

        // 발신번호
        // 팝빌에 등록되지 않은 번호를 입력하는 경우 '원발신번호'로 팩스 전송됨
        String sendNum = "07043042995";

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

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

        // 파일 목록
        // 파일 전송 개수 최대 20개
        File[] files = new File[2];
        try {
            files[0] = new File(getClass().getClassLoader().getResource("static/image/nonbg_statement.pdf").toURI());
            files[1] = new File(getClass().getClassLoader().getResource("static/image/nonbg_statement.pdf").toURI());
        } catch (URISyntaxException e1) {
            throw e1;
        }

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

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

        // 광고팩스 전송여부 , true / false 중 택 1
        // └ true = 광고 , false = 일반
        // └ 미입력 시 기본값 false 처리
        Boolean adsYN = false;

        // 팩스제목
        String title = "팩스 제목";

        // 요청번호
        // 파트너가 접수 단위를 식별하기 위해 할당하는 관리번호
        // 1~36자리로 구성. 영문, 숫자, 하이픈(-), 언더바(_)를 조합하여 팝빌 회원별로 중복되지 않도록 할당.
        String requestNum = "";

        try {

            String receiptNum = faxService.sendFAX(CorpNum, sendNum, receiveNum, receiveName, files,
                reserveDT, UserID, adsYN, title, requestNum);

            m.addAttribute("Result", receiptNum);

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

4. 결과 확인

함수 호출 반환 결과는 아래와 같습니다.
- 성공 : ReceiptNum(접수번호) 18자리 문자열 반환
- 실패 : PopbillException 음의 정수 8자리 숫자값 오류코드와 오류메시지 반환 [오류코드]