관리 메뉴

웹개발자의 기지개

[PHP] Cafe24 문자 발송 SMS 예제소스 본문

PHP

[PHP] Cafe24 문자 발송 SMS 예제소스

웹개발자 워니 2025. 9. 11. 23:32

 

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?
function send_sms22($phone_no$send_msg$send_subject)
{
    // 숫자 이외의 문자 제거
 
//    $phone_no=eregi_replace("[^0-9]", "", $phone_no);
    $phone_no = preg_replace("/[^0-9]/"""$phone_no);
 
    if(strlen($phone_no)>10)
    {
 
        $phone_1=substr($phone_no,0,3);
        $phone_2=substr($phone_no,3,4);
        $phone_3=substr($phone_no,7);
 
    }
    else
    {
        $phone_1=substr($phone_no,0,3);
        $phone_2=substr($phone_no,3,3);
        $phone_3=substr($phone_no,6);
    } 
 
    $phone=$phone_1."-".$phone_2."-".$phone_3;
 
       /******************** 인증정보 ********************/
 
    $sms_url = "http://sslsms.cafe24.com/sms_sender.php"// 전송요청 URL
    $sms['user_id'= base64_encode("아이디"); //SMS 아이디. 
    $sms['secure'= base64_encode("키값") ;//인증키
    $sms['msg'= base64_encode(stripslashes($send_msg));//보낼메세지
//    $sms['subject'] = base64_encode($send_subject); // L 장문일때
 
    $sms['rphone'= base64_encode($phone);
    $sms['sphone1'= base64_encode('053');
    $sms['sphone2'= base64_encode('1234');
    $sms['sphone3'= base64_encode('5678');
    $sms['mode'= base64_encode("1"); // base64 사용시 반드시 모드값을 1로 주셔야 합니다.
 
 
    //생략가능 시작
 
    $sms['rdate'= base64_encode($_POST['rdate']);//예약일
    $sms['rtime'= base64_encode($_POST['rtime']);//예약시간
    $sms['returnurl'= base64_encode($_POST['returnurl']);//되돌아갈주소
    $sms['testflag'= base64_encode($_POST['testflag']);
    $sms['destination'= base64_encode($_POST['destination']);
    $returnurl = $_POST['returnurl'];
    $sms['repeatFlag'= base64_encode($_POST['repeatFlag']);
    $sms['repeatNum'= base64_encode($_POST['repeatNum']);
    $sms['repeatTime'= base64_encode($_POST['repeatTime']);
//    $sms['smsType'] = base64_encode("L");        // LMS일경우 L
    $nointeractive = $_POST['nointeractive']; //사용할 경우 : 1, 성공시 대화상자(alert)를 생략
    //생략가능 끝
 
 
    $host_info = explode("/"$sms_url);
    $host = $host_info[2];
    $path = $host_info[3]."/".$host_info[4];
    srand((double)microtime()*1000000);
    $boundary = "---------------------".substr(md5(rand(0,32000)),0,10);
 
    // 헤더 생성
    $header = "POST /".$path ." HTTP/1.0\r\n";
    $header .= "Host: ".$host."\r\n";
    $header .= "Content-type: multipart/form-data, boundary=".$boundary."\r\n";
 
    // 본문 생성
    foreach($sms AS $index => $value){
    $data .="--$boundary\r\n";
    $data .= "Content-Disposition: form-data; name=\"".$index."\"\r\n";
    $data .= "\r\n".$value."\r\n";
    $data .="--$boundary\r\n";
    }
 
    $header .= "Content-length: " . strlen($data) . "\r\n\r\n";
 
    $fp = fsockopen($host80);
 
    if ($fp) {
    fputs($fp$header.$data);
    $rsp = '';
    while(!feof($fp)) {
 
        $rsp .= fgets($fp,8192);
 
    }
 
    fclose($fp);
 
    $msg = explode("\r\n\r\n",trim($rsp));
 
    $rMsg = explode(","$msg[1]);
 
    $Result$rMsg[0]; //발송결과
 
    $Count$rMsg[1]; //잔여건수
 
 
 
 
    //발송결과 알림
 
    if($Result=="success") {
 
        $alert = "성공";
    }
    else if($Result=="3205") {
 
        $alert = $phone."은 잘못된 번호형식입니다.";
    
    }
    else if($Result=="0044") {
 
        $alert = "스팸문자는발송되지 않습니다.";
 
    }
    else {
 
        $alert = "[Error]".$Result;
 
    }
 
    }
 
    else {
 
        $alert = "Connection Failed";
 
    }
 
    return $Result;
 
}
 
$phone_no = "010-1234-5678";
$send_msg = "[홍길동] 테스트합니다. 감사합니다.";
echo send_sms22($phone_no$send_msg"");
 
 
?>
cs

 

 

Comments