[Delphi] 팝빌 문자 SDK 튜토리얼
Delphi 개발환경에서 팝빌 Delphi SDK를 적용하여 단문 문자 메시지 전송(SendSMS) 함수를 구현하는 예시입니다.
1. Popbill SDK 추가
① 팝빌 연동자료실에서 Delphi SDK 예제코드 다운로드 후 압축을 해제합니다.
② 압축해제한 SDK 예제코드에서 Linkhub/ Popbill/ PopbillMessaging/ 각 폴더의 pas파일 3개를 프로젝트 유닛으로 추가합니다.
③ 아래 코드를 참조하여 Form 파일을 수정합니다.
1) use 참조유닛 추가
2) 인증정보 변수와 서비스 클래스를 선언
3) FormCreate 프로시저에 문자 서비스 클래스 인스턴스 생성 및 초기화
연동신청시 발급받은 인증정보로 링크아이디(LinkID)와 비밀키(SecretKey) 값을 변경하시기 바랍니다.
unit Example;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, TypInfo, shellapi, ExtCtrls,
Popbill, PopbillMessaging;
const
// 링크아이디, 연동신청시 발급받은 정보로 변경
LinkID = 'TESTER';
// 비밀키, 연동신청시 발급받은 정보로 변경
SecretKey = 'SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=';
// 생략
// ...
// ...
var
// 클래스 선언 추가
messagingService : TMessagingService;
// 생략
// ...
// ...
procedure TfrmExample.FormCreate(Sender: TObject);
begin
// 문자 서비스 클래스 인스턴스 생성
messagingService := TMessagingService.Create(LinkID,SecretKey);
// true - 개발용(테스트베드), false - 상업용(실서비스)
messagingService.IsTest := true;
// API 오류 Exception 처리여부
messagingService.IsThrowException := true;
// 인증토큰 IP제한기능 사용여부, true(권장)
messagingService.IPRestrictOnOff := true;
end;
2. 단문 문자 메시지 전송(SendSMS) 함수 구현
① Form에 버튼을 생성하고 버튼의 Click Event 코드에 단문 문자 메시지 전송(SendSMS) 함수를 추가합니다.
procedure TfrmExample.btnSendSMS_SingleClick(Sender: TObject);
var
receiptNum : String;
sendNum : String;
sendName : String;
receiver : String;
receiverName : String;
contents : String;
adsYN : Boolean;
requestNum : String;
corpNum : String;
reserveDT : String;
userID : String;
begin
// 팝빌회원 사업자번호
corpNum := '1234567890';
// 팝빌회원 아이디
userID := 'testkorea';
// 발신번호 (팝빌에 등록된 발신번호)
sendNum := '07043042991';
// 발신자명
sendName := '발신자명';
// 수신번호
receiver := '010-1234-4567';
// 수신자명
receiverName := '수신자명';
//메시지 내용 (90Byte 초과된 내용은 삭제되어 전송됨)
contents := '단문메시지 입니다.';
// 전송요청번호
// 파트너가 전송 건에 대해 관리번호를 구성하여 관리하는 경우 사용.
// 1~36자리로 구성. 영문, 숫자, 하이픈(-), 언더바(_)를 조합하여 팝빌 회원별로 중복되지 않도록 할당.
requestNum := '';
// 예약일시
reserveDT := '';
// 광고문자 전송여부
adsYN := false;
try
receiptNum := messagingService.SendSMS(corpNum, sendNum,
sendName, receiver,
receiverName, contents,
reserveDT, adsYN,
userID,requestNum);
except
on le : EPopbillException do begin
ShowMessage('응답코드 : ' + IntToStr(le.code) + #10#13 +'응답메시지 : '+ le.Message);
Exit;
end;
end;
if messagingService.LastErrCode <> 0 then
begin
ShowMessage('응답코드 : ' + IntToStr(messagingService.LastErrCode) + #10#13 +'응답메시지 : '+ messagingService.LastErrMessage);
end
else
begin
txtReceiptNum.Text := receiptNum;
ShowMessage('접수번호 (receiptNum) : '+ receiptNum);
end;
end;
② 버튼 클릭으로 함수호출 결과를 확인합니다.
