💻 사전작업(인증키 발급)
https://www.ncloud.com/product/applicationService/sens
👉 사전작업으로 Simple & Easy Notification Service -> SMS -> Calling Number 메뉴에서 발송할 때 사용할 번호를 등록해주면 됩니다.
const axios = require("axios");
const CryptoJS = require("crypto-js");
//기본 헤더 설정
const date = new Date().getTime().toString();
const serviceId = "serviceId";
const secretKey = "secret";
const accessKey = "access";
const method = "POST";
const space = " ";
const newLine = "\n";
const url = `https://sens.apigw.ntruss.com/sms/v2/services/${serviceId}/messages`;
const url2 = `/sms/v2/services/${serviceId}/messages`;
const hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, secretKey);
hmac.update(method);
hmac.update(space);
hmac.update(url2);
hmac.update(newLine);
hmac.update(date);
hmac.update(newLine);
hmac.update(accessKey);
const hash = hmac.finalize();
const signature = hash.toString(CryptoJS.enc.Base64);
시그니쳐 키를 해쉬해서 전송해야한다..
const result = await axios.post(url, data, {
headers: {
"Content-Type": "application/json; charset=utf-8",
"x-ncp-iam-access-key": accessKey,
"x-ncp-apigw-timestamp": date,
"x-ncp-apigw-signature-v2": signature,
},
});