POPBill Developers
가이드

튜토리얼

Ruby 개발환경에서 팝빌 SDK를 추가하여 단문 문자 메시지 전송 (SendSMS) 함수를 구현하는 예시입니다.

1. POPBiLL SDK 추가

팝빌 Ruby SDK를 추가하기 위해 Rails 프로젝트 "Gemfile" 파일에 팝빌 Ruby Gem SDK 정보를 추가하고 bundle install을 진행합니다.

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.3.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.3'

# 팝빌 API Service
gem 'popbill', '1.52.0'

# 생략
# ...

2. POPBiLL SDK 설정

프로젝트에 문자 서비스 기능을 수행할 Controller를 생성합니다.

rails generate controller tutorial

Controller에 연동신청시 발급받은 인증정보를 변수로 선언하고 아래의 코드를 참조하여 문자 서비스 객체를 생성 합니다.

require 'popbill/message'

class TutorialController < ApplicationController

  # 연동신청시 발급받은 링크아이디, 비밀키
  LinkID = "TESTER"
  SecretKey = "SwWxqU+0TExEXy/9TVjKPExI2VTUMMSLZtJf3Ed8q3I="

  # 팝빌 문자 Service 초기화
  MSGService = MessageService.instance(
    TutorialController::LinkID,
    TutorialController::SecretKey
  )

  # 연동환경 설정, true-개발용, false-상업용
  MSGService.setIsTest(true)

  # 인증토큰 IP제한기능 사용여부, true-사용, false-미사용, 기본값(true)
  MSGService.setIpRestrictOnOff(true)

  # 팝빌 API 서비스 고정 IP 사용여부, true-사용, false-미사용, 기본값(false)
  MSGService.setUseStaticIP(false)

  #로컬시스템 시간 사용여부, true-사용, false-미사용, 기본값(true)
  MSGService.setUseLocalTimeYN(true)

end

3. SendSMS 기능 구현

Controller 코드에 단문 문자 메시지 전송 (SendSMS) 함수 호출 코드를 추가합니다.

def sendSMS

    # 팝빌회원 사업자번호
    corpNum = "1234567890"

    # 팝빌회원 아이디
    userID = "testkorea"

    # 발신번호
    sender = "07043042991"

    # 발신자명
    senderName = "tester"

    # 수신번호
    receiver = "010000111"

    # 수신자명
    receiverName = "MyPhone"

    # 메시지내용, 90byte초과된 내용은 삭제되어 전송됨..
    contents = "message send Test"

    # 예약전송일시(yyyyMMddHHmmss), 미기재시 즉시전송
    reserveDT = ""

    # 광고문자 전송여부
    adsYN = false

    # 요청번호, 파트너가 전송요청에 대한 관리번호를 직접 할당하여 관리하는 경우 기재
    # 최대 36자리, 영문, 숫자, 언더바('_'), 하이픈('-')을 조합하여 사업자별로 중복되지 않도록 구성
    requestNum = ''

    begin
        @value = TutorialController::MSGService.sendSMS(
            corpNum,
            sender,
            senderName,
            receiver,
            receiverName,
            contents,
            reserveDT,
            adsYN,
            userID,
            requestNum,
        )
        @name = "receiptNum(접수번호)"
        render "home/response"
    rescue PopbillException => pe
        @Response = pe
        render "home/exception"
    end
end

4. 결과 확인

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