알림톡
검증된 비즈니스 채널, 신뢰도 높은 알림톡으로 비용을 절감하세요.
API를 연동하기 전, 관리툴에서 발송 IP와
발신번호 등록, 템플릿 ID 및 API Key를 먼저 설정하세요.
관리툴(sms.gabia.com) 설정 단계
1 .발송 IP 등록기본 설정 -> API 발송 IP 설정
2. 발신 번호 등록환경 설정 -> 발신 번호
3. 템플릿 등록환경 설정 -> 알림톡 템플릿
4. API Key 발급 관리자 -> 서비스 정보 -> 관리 중인 서비스 -> API 인증키 정보
가비아 알림톡 서비스는
OPEN API 연동 방식을 지원합니다.
OPEN API
제공 언어: PHP, JAVA, PYTHON,
NODE, RUBY, GO, cURL
사용자 인증
SMS ID와 API Key로 토큰을 발행해 사용자를 인증합니다.
POSThttps://sms.gabia.com/oauth/token
HEADERS
Content-Type | application/x-www-form-urlencoded |
---|---|
Authorization |
Basic base64encode(SMS_ID:API_KEY) (예) Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ= |
BODY
grant_type | client_credentials |
---|
RESPONSE
성공케이스 | {
access_token": "your_access_token", } |
---|---|
실패케이스 |
{"message": "SMS ID나 API KEY가 잘못되었습니다."} {"message": "unsupported_grant_type (grant_type 값을 확인해주세요.)"}
* Authorization 값 확인이 안 되는 경우, {"message": "client_id empty"} 또는 {"message": "client_secret
empty"}가 출력됩니다. |
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://sms.gabia.com/oauth/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=client_credentials",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded",
"Authorization: Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ="
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
import com.google.gson.Gson;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Objects;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
// 외부 라이브러리 다운로드가 필요합니다. (gradle 기준)
// implementation 'com.squareup.okhttp3:okhttp:4.9.3'
https://mvnrepository.com/artifact/com.squareup.okhttp/okhttp
// implementation 'com.google.code.gson:gson:2.9.0' https://github.com/google/gson
public class userAuth {
public static final String SMS_OAUTH_TOKEN_URL = "https://sms.gabia.com/oauth/token"; // ACCESS
TOKEN 발급 API URL 입니다.
public static void main(String[] args) throws IOException {
String smsId = "YOUR_SMS_ID"; // SMS ID 를 입력해 주세요.
String apiKey = "YOUR_API_KEY"; // SMS 관리툴에서 발급받은 API KEY 를 입력해 주세요.
String authValue =
Base64.getEncoder().encodeToString(String.format("%s:%s", smsId,
apiKey).getBytes(StandardCharsets.UTF_8)); // Authorization Header 에 입력할 값입니다.
// 사용자 인증 API 를 호출합니다.
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("grant_type", "client_credentials")
.build();
Request request = new Request.Builder()
.url(SMS_OAUTH_TOKEN_URL)
.post(requestBody)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.addHeader("Authorization", "Basic " + authValue)
.addHeader("cache-control", "no-cache")
.build();
// Response 를 key, value 로 확인하실 수 있습니다.
Response response = client.newCall(request).execute();
HashMap<String, String> result = new
Gson().fromJson(Objects.requireNonNull(response.body()).string(), HashMap.class);
for(String key : result.keySet()) {
System.out.printf("%s: %s%n", key, result.get(key));
}
}
}
import requests
url = 'https://sms.gabia.com/oauth/token'
payload = 'grant_type=client_credentials'
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ='
}
response = requests.request('POST', url, headers = headers, data = payload, allow_redirects=False,
timeout=undefined)
print(response.text)
var https = require('https');
var qs = require('querystring');
var postData = qs.stringify({
'grant_type': 'client_credentials'
});
var options = {
method: 'POST',
hostname: 'sms.gabia.com',
path: '/oauth/token',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData),
'Authorization': 'Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ='
}
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
req.write(postData);
req.end();
require "uri"
require "net/http"
url = URI("https://sms.gabia.com/oauth/token")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/x-www-form-urlencoded"
request["Authorization"] = "Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ="
request.body = "grant_type=client_credentials"
response = https.request(request)
puts response.read_body
curl --location --request POST
"https://sms.gabia.com/oauth/token" \
--header "Content-Type: application/x-www-form-urlencoded" \
--header "Authorization: Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ=" \
--data "grant_type=client_credentials"
package main
import (
"fmt"
"strings"
"os"
"path/filepath"
"net/http"
"io/ioutil"
)
func main() {
url := "https://sms.gabia.com/oauth/token"
method := "POST"
payload := strings.NewReader("grant_type=client_credentials")
client := &http.Client {
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ=")
res, err := client.Do(req)
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}