본문 바로가기

낙서장/Spring

Spring Sms Library(1)

 Java

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.toco.sms.exception.CertifiedTimeOutException;



@Controller
public class HomeController {
	
	@Value("${coolsms.key}")
	private String key;
	
	@Value("${coolsms.secret}")
	private String secret;

	@PostMapping("sendSMS.do")
	@ResponseBody
	public String sendSMS(String to, HttpSession session) {
		String flag = "true";
		int cer = (int)(Math.random()*9000)+1000;;

		try {
			Message coolsms = new Message(key, secret);
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("to", to); //수신자
			map.put("from", "010********"); //발신자
			map.put("text", "[YHCompany :0] 인증번호"+ cer +"를 입력하세요."); //내용
			map.put("type", "sms"); //문자타입
			
			coolsms.send(map);
		}catch(Exception e) {
			e.printStackTrace();
		}
		return flag;
	}

 

Maven 

쿨에스엠에스

<!-- https://mvnrepository.com/artifact/net.nurigo/javaSDK -->
		<dependency>
			<groupId>net.nurigo</groupId>
			<artifactId>javaSDK</artifactId>
			<version>2.2</version>
		</dependency>