Inbound SMS
Inbound SMS
Prerequisites
- Inbound SMS 서비스를 사용하기 위해서는 ToBeText 가입이 필요합니다.
- TobeText 의 Prefix 번호 및 Designate 번호를 보유 하셔야 합니다.
- 회원 가입 시 제공되는 소량의 Credit 으로 Inbound SMS 서비스를 테스트 할 수 있습니다.
- Inbound SMS 웹 응용프로그램을 사용 할 수 있는 웹 호스트가 필요합니다.
Post Method
- ToBeText 의 연동 API 는 POST 방식을 사용하여 메시지를 전달 합니다.
Register URL
- Inbound SMS 서비스 번호로 수신된 데이터를 전송하기 위한 고객사 URL 을 사전 별도 등록 하셔야 합니다.
- 해당 URL 로 정보 전송 후 전송 상태 확인 (확인 불가 시 결과 값 재전송 – 최대 3회 재시도)
Required Parameters
| Name | Description | Remarks |
|---|---|---|
| SendNum | Inbound SMS 수신 된 송신자 전화번호 | |
| RecvNum | Inbound SMS 수신 전화번호 (고객사에 사전 할당된 전화번호) | |
| Body | ToBeText 에서 구매한 Prefix 번호와 Inbound SMS 수신된 메시지 내용 | Prefix + 메시지 |
Inbound SMS Sample Codes
Java
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class ToBeText {
public static void main(String[] args) throws Exception {
ToBeText tobe = new ToBeText();
tobe.sendMO();
}
private void sendMO() throws Exception {
String USER_AGENT = "Mozilla/5.0";
String url = "http://api-dev.tbnws.com/mo";
URL obj = new URL(url);
HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
// HttpsURLConnection conn = (HttpsURLConnection) obj.openConnection();// SSL connection
conn.setRequestMethod("POST");
conn.setRequestProperty("User-Agent", USER_AGENT);
conn.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
StringBuffer urlParameters = new StringBuffer();
urlParameters.append("RecvNum=ToBeText에서 구매한 수신전화번호");
urlParameters.append("&SendNum=발신전화번호");
urlParameters.append("&Body=ToBeText에서 구매한 Prefix 및 메시지 내용");
System.out.println("Request to URL : " + url);
System.out.println("\n\nParameters : " + urlParameters);
// Send post request
conn.setDoOutput(true);
DataOutputStream ostream = new DataOutputStream(conn.getOutputStream());
ostream.writeBytes(urlParameters.toString());
ostream.flush();
ostream.close();
int responseCode = conn.getResponseCode();
System.out.println("nnResponse Code : " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println("\n\nResponse : " + response.toString());
}
}
curl
curl -X POST http://api-dev.tbnws.com/mo -d 'RecvNum=ToBeText 에서 구매한 수신전화번호' -d 'SendNum=발신전화번호' -d 'Body=ToBeText 에서 구매한 Prefix 및 메시지 내용'
php
<?php $url = 'http://api-dev.tbnws.com/mo'; $post_data["Ckey"] = "메시지ID"; $post_data["RecvNum"] = "수신전화번호"; $post_data["SendNum"] = "발신전화번호"; $post_data["Body"] = "메시지본문"; $post_data["Cid"] = "ToBeText에서 지급한 고객님의 Cid"; $post_data["token"] = "ToBeText 에서 지급한 고객님의 token"; $post_data["callback"] = "상태 값 Callback URL"; $curlsession = curl_init (); curl_setopt ($curlsession, CURLOPT_URL, $url); curl_setopt ($curlsession, CURLOPT_POST, 1); curl_setopt ($curlsession, CURLOPT_POSTFIELDS, $post_data); curl_setopt ($curlsession, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec ($curlsession); var_dump($res); //결과값 출력 curl_close($curlsession); ?>
Error Codes
| Error Code | Description | Remarks |
|---|---|---|
| 200 | Success | 전송성공 |
| 2001 | CKey 값 오류 | 전송실패 |
| 2002 | CCode 값 오류 | 전송실패 |
| 2004 | SendNum 값 오류 | 전송실패 |
| 2005 | Body field 값 오류 | 전송실패 |
Response Sample
<ToBeTextResult> <Status>Success</Status> <MsgId>41aa33709703dea382c10a057823ffdc</MsgId> <SendNum>821012341234</SendNum> <RecvNum>821012341234</RecvNum> <ErrorCode>200</ErrorCode> <ErrorMsg>Message successfully sent</ErrorMsg> </ToBeTextResult> |
Status Callback
- SMS 전송 결과를 주기적으로 전송. (전송후 약 3분 ~ 30분 이내)
- 메시지 전송 시 입력한 Callback URL 로 회신
Status Callback URL
- SMS 전송 시 callback Parameter로 전달되는 URL.
예) http://yourdomain.com/recv/
※ http:// 를 포함한 Full Address
Parameters
| Name | Description | Remarks |
|---|---|---|
| CKey | 고객의 메시지 ID (고객사 메시지 ID 고유번호), 결과값 전송시 해당 메시지의 식별 값으로 전달 되는 값 (CKey, MsgId) | |
| Status | 전송 결과 값 | |
| MsgId | ToBe Networks 고유 메시지 ID 값 | |
| SendNum | 송신자 전화 번호 / 해외 경우 지정된 번호로 자동 변경, 국내 경우 전달된 번호로 전송 | |
| RecvNum | 수신자 전화 번호 | |
| ErrorCode | 고객사 전달용 에러 코드 | |
| ErrorMsg | 고객사 전달용 에러 메시지 |
Error Codes
| Error Code | Description | Remarks |
|---|---|---|
| 200 | Success | 전송성공 |
| 400 | Failed | 전송실패 |
| 411 | 내부 오류 | 전송실패 |
| 412 | 기타 | 전송실패 |