튜토리얼
Ruby 개발환경에서 팝빌 SDK를 추가하고, 단문 문자 메시지 전송 (SendSMS) API를 호출하는 기본 과정을 단계별로 따라 해볼 수 있도록 구성된 가이드 입니다.
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에 연동신청시 발급받은 API Key 를 변수로 선언하고 아래의 코드를 참조하여 문자 서비스 객체를 생성 합니다.
require 'popbill/message'
class MessageController < ApplicationController
# 링크아이디
LinkID = "LinkID"
# 비밀키
SecretKey = "SwWxqU+0TExEXy/9TVjKPExI2VTUMMSLZtJf3Ed8q3I="
# 문자 서비스 객체 초기화
MSGService = MessageService.instance(
MessageController::LinkID,
MessageController::SecretKey
)
# 연동환경 설정, true-테스트, false-운영(Production), (기본값:false)
MSGService.setIsTest(true)
# 인증토큰 IP 검증 설정, true-사용, false-미사용, (기본값:true)
MSGService.setIpRestrictOnOff(true)
# 통신 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. API 응답결과 확인
API 호출 응답결과는 다음과 같습니다.
| 구분 | 응답 |
| 성공 | ReceiptNum(접수번호) : 18자리 문자열 |
| 실패 |
code : 오류코드 (8자리 음의 정수) [오류코드] message : 오류메시지 |












