cafe24 sms 호스팅의 sms 발송 관련 예제를 참조하여 해당 함수를 만들어보았다.
아래의 함수를 활용하여 운영중인 서비스에 좀더 편리하게 적용하리라 본다.
<?
function cafe24_send_msg($rnum, $send_num, $send_msg){
$imsi = explode('-',$rnum);
$sms_url = "cafe24 sms호스팅 발송주소";
$sms['user_id'] = base64_encode("아이디");
$sms['secure'] = base64_encode("인증키") ;
$sms['msg'] = base64_encode(stripslashes($send_msg));
$sms['rphone'] = base64_encode($send_num);
$sms['sphone1'] = base64_encode($imsi[0]);
$sms['sphone2'] = base64_encode($imsi[1]);
$sms['sphone3'] = base64_encode($imsi[2]);
$sms['mode'] = base64_encode("1");
$sms['smsType'] = base64_encode('S');
$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($host, 80);
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]; //잔여건수
}
return $Result;
}
?>