1. view.jsp 구현 ( javascript 포함)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
$(function(){
//휴대폰 번호 인증var code2 = "";
$("#phoneChk").click(function(){
alert('인증번호 발송이 완료되었습니다.\n휴대폰에서 인증번호 확인을 해주십시오.');
var phone = $("#phoneNumber").val();
$.ajax({
type:"POST", // post 형식으로 발송
url:"/shop/member/sendSMS1.do", // controller 위치
data: {phoneNumber:phone}, // 전송할 ㅔ이터값
cache : false,
success:function(data){
if(data == "error"){ //실패시
alert("휴대폰 번호가 올바르지 않습니다.")
}else{ //성공시
alert("휴대폰 전송이 됨.")
code2 = data; // 성공하면 데이터저장
}
}
});
});
//휴대폰 인증번호 대조
$("#phoneChk2").click(function(){
if($("#phone2").val() == code2){ // 위에서 저장한값을 ㅣ교함
alert('인증성공')
}else{
alert('인증실패')
}
});
<div class="input_text">
<input class="signin_pass" id="phoneNumber" type="text" name="phoneNumber" title="전화번호 입력" placeholder="전화번호 입력해주세요">
<input class="signin_pass" type="button" value="입력" id="phoneChk"> // phoneChk 클릭시 함수 발동
<input class="signin_pass" id="phone2" type="text" name="phone" title="전화번호 입력" placeholder="인증번호 입력해주세요">
<input class="signin_pass" type="button" value="인증확인" id="phoneChk2"> // phoneChk 클릭시 함수 발동
|
cs |
2. Controller 구현하기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
@RequestMapping("/sendSMS1.do") //jsp 페이지 넘긴 mapping 값
@ResponseBody
public String sendSMS(String phoneNumber) {
Random rand = new Random(); //랜덤숫자 생성하기 !!
String numStr = "";
for(int i=0; i<4; i++) {
String ran = Integer.toString(rand.nextInt(10));
numStr+=ran;
}
certifiedPhoneNumber.certifiedPhoneNumber(phoneNumber, numStr); //휴대폰 api 쪽으로 가기 !!
// // 밑에 자세한 설명나옴
return numStr;
}
|
cs |
3. Service 구현하기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
public void certifiedPhoneNumber(String phoneNumber, String numStr) {
String api_key = "###발급받은키";
String api_secret = "##발급받은키입력";
Message coolsms = new Message(api_key, api_secret);
HashMap<String, String> params = new HashMap<String, String>();
params.put("to", phoneNumber);
params.put("from", "###본인의 휴대폰번호####");
params.put("type", "SMS");
params.put("text", " + 작성할내용 "["+numStr+"]" +내용 ");
params.put("app_version", "test app 1.2"); // application name and version
try {
JSONObject obj = (JSONObject) coolsms.send(params);
System.out.println(obj.toString());
} catch (CoolsmsException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
}
}
|
cs |
4. view.jsp 가서 휴대폰 인증하기누르면 !! 끝!!
![](https://blog.kakaocdn.net/dn/czE75N/btrHpoFhgJ7/kaykKP0C2C975yApCS8FK1/img.png)
이상으로 마치겠습니다 ~ 감사합니다