API 호출 예제 코드
각 언어별 예제입니다. Host와 API Key 정보를 실제 환경에 맞게 수정하여 적용하세요.
PHP (cURL)
POST https://munjassada.com/api/send.php HTTP/1.1
$url = ;
$identifier = ;
$secret_key = ;
$timestamp = time();
$nonce = uniqid(, true);
$data = [
=> $identifier,
=> ,
=> ,
=> ,
=> $timestamp,
=> $nonce
];
ksort($data);
$base = http_build_query($data);
$signature = hash_hmac(, $base, $secret_key);
$data[] = $signature;
JSP (HttpURLConnection)
String url = ;
String identifier = ;
String secretKey = ;
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
String nonce = + System.currentTimeMillis();
Map<String, String> params = new TreeMap<>();
params.put(, identifier);
params.put(, );
params.put(, );
params.put(, );
params.put(, timestamp);
params.put(, nonce);
StringBuilder base = new StringBuilder();
for (Map.Entry<String,String> e : params.entrySet()) {
if (base.length() > 0) base.append();
base.append(e.getKey()).append().append(e.getValue());
}
String signature = hmacSha256(base.toString(), secretKey);
params.put(, signature);
Node.js (Axios)
POST /api/send.php HTTP/1.1
axios = require();
const crypto = require();
const identifier = ;
const secretKey = ;
const timestamp = Math.floor(Date.now()/1000);
const nonce = + Date.now();
const data = { identifier, sender: , receiver: , msg: , timestamp, nonce };
const base = Object.keys(data).sort().map(k => `${k}=${data[k]}`).join();
data.signature = crypto.createHmac(, secretKey).update(base).digest();
axios.post(, new URLSearchParams(data))
.then(res => console.log(res.data));
Python (Requests)
POST /api/send.php HTTP/1.1
import requests, time, hmac, hashlib
url =
identifier =
secret_key =
timestamp = int(time.time())
nonce =
data = {
: identifier,
: ,
: ,
: ,
: timestamp,
: nonce
}
base = .join([f"{k}={data[k]}" for k in sorted(data.keys())])
signature = hmac.new(secret_key.encode(), base.encode(), hashlib.sha256).hexdigest()
data[] = signature
res = requests.post(url, data=data)
print(res.text)