diff --git a/adm/config_form.php b/adm/config_form.php index 6535f2272..a89ef011b 100644 --- a/adm/config_form.php +++ b/adm/config_form.php @@ -180,6 +180,12 @@ if(!isset($config['cf_kakao_js_apikey'])) { ADD `cf_kakao_js_apikey` varchar(255) NOT NULL DEFAULT '' AFTER `cf_googl_shorturl_apikey` ", true); } +// SMS 전송유형 필드 추가 +if(!isset($config['cf_sms_type'])) { + sql_query(" ALTER TABLE `{$g5['config_table']}` + ADD `cf_sms_type` varchar(10) NOT NULL DEFAULT '' AFTER `cf_sms_use` ", true); +} + if(!$config['cf_faq_skin']) $config['cf_faq_skin'] = "basic"; if(!$config['cf_mobile_faq_skin']) $config['cf_mobile_faq_skin'] = "basic"; @@ -1034,6 +1040,16 @@ if ($config['cf_sms_use'] && $config['cf_icode_id'] && $config['cf_icode_pw']) { + + + + LMS로 선택하시면 90바이트 이하는 SMS로, 그 이상은 1500바이트까지 LMS로 전송됩니다.
요금은 건당 SMS는 16원, LMS는 50원입니다."); ?> + + + @@ -1069,7 +1085,6 @@ if ($config['cf_sms_use'] && $config['cf_icode_id'] && $config['cf_icode_pw']) { 아이코드 SMS 신청
회원가입 - 아이코드 회원가입 @@ -1081,12 +1096,6 @@ if ($config['cf_sms_use'] && $config['cf_icode_id'] && $config['cf_icode_pw']) { 충전하기 - - 건수별 금액 - - 원. - - diff --git a/adm/config_form_update.php b/adm/config_form_update.php index 7c2c7891b..2c1279df4 100644 --- a/adm/config_form_update.php +++ b/adm/config_form_update.php @@ -124,6 +124,7 @@ $sql = " update {$g5['config_table']} cf_cert_limit = '{$_POST['cf_cert_limit']}', cf_cert_req = '{$_POST['cf_cert_req']}', cf_sms_use = '{$_POST['cf_sms_use']}', + cf_sms_type = '{$_POST['cf_sms_type']}', cf_icode_id = '{$_POST['cf_icode_id']}', cf_icode_pw = '{$_POST['cf_icode_pw']}', cf_icode_server_ip = '{$_POST['cf_icode_server_ip']}', diff --git a/bbs/qawrite_update.php b/bbs/qawrite_update.php index 3671cfcfd..af44406d4 100644 --- a/bbs/qawrite_update.php +++ b/bbs/qawrite_update.php @@ -300,33 +300,100 @@ if($w == '' || $w == 'a' || $w == 'r') { // SMS 알림 if($config['cf_sms_use'] == 'icode' && $qaconfig['qa_use_sms']) { - include_once(G5_LIB_PATH.'/icode.sms.lib.php'); + if($config['cf_sms_type'] == 'LMS') { + include_once(G5_LIB_PATH.'/icode.lms.lib.php'); - // 답변글은 질문 등록자에게 전송 - if($w == 'a' && $write['qa_sms_recv'] && trim($write['qa_hp'])) { - $sms_content = $config['cf_title'].' '.$qaconfig['qa_title'].'에 답변이 등록되었습니다.'; - $send_number = preg_replace('/[^0-9]/', '', $qaconfig['qa_send_number']); - $recv_number = preg_replace('/[^0-9]/', '', $write['qa_hp']); + $port_setting = get_icode_port_type($config['cf_icode_id'], $config['cf_icode_pw']); - if($recv_number) { - $SMS = new SMS; // SMS 연결 - $SMS->SMS_con($config['cf_icode_server_ip'], $config['cf_icode_id'], $config['cf_icode_pw'], $config['cf_icode_server_port']); - $SMS->Add($recv_number, $send_number, $config['cf_icode_id'], iconv("utf-8", "euc-kr", stripslashes($sms_content)), ""); - $SMS->Send(); + // SMS 모듈 클래스 생성 + if($port_setting !== false) { + // 답변글은 질문 등록자에게 전송 + if($w == 'a' && $write['qa_sms_recv'] && trim($write['qa_hp'])) { + $sms_content = $config['cf_title'].' '.$qaconfig['qa_title'].'에 답변이 등록되었습니다.'; + $send_number = preg_replace('/[^0-9]/', '', $qaconfig['qa_send_number']); + $recv_number = preg_replace('/[^0-9]/', '', $write['qa_hp']); + + if($recv_number) { + $strDest = array(); + $strDest[] = $recv_number; + $strCallBack = $send_number; + $strCaller = iconv_euckr(trim($config['cf_title'])); + $strSubject = ''; + $strURL = ''; + $strData = iconv_euckr($sms_content); + $strDate = ''; + $nCount = count($strDest); + + $LMS = new LMS; + $LMS->SMS_con($config['cf_icode_server_ip'], $config['cf_icode_id'], $config['cf_icode_pw'], $port_setting); + $res = $LMS->Add($strDest, $strCallBack, $strCaller, $strSubject, $strURL, $strData, $strDate, $nCount); + + if($res) { + $LMS->Send(); + } + + $LMS->Init(); // 보관하고 있던 결과값을 지웁니다. + } + } + + // 문의글 등록시 관리자에게 전송 + if(($w == '' || $w == 'r') && trim($qaconfig['qa_admin_hp'])) { + $sms_content = $config['cf_title'].' '.$qaconfig['qa_title'].'에 문의글이 등록되었습니다.'; + $send_number = preg_replace('/[^0-9]/', '', $qa_hp); + $recv_number = preg_replace('/[^0-9]/', '', $qaconfig['qa_admin_hp']); + + if($recv_number) { + $strDest = array(); + $strDest[] = $recv_number; + $strCallBack = $send_number; + $strCaller = iconv_euckr(trim($config['cf_title']));; + $strSubject = ''; + $strURL = ''; + $strData = iconv_euckr($sms_content); + $strDate = ''; + $nCount = count($strDest); + + $LMS = new LMS; + $LMS->SMS_con($config['cf_icode_server_ip'], $config['cf_icode_id'], $config['cf_icode_pw'], $port_setting); + $res = $LMS->Add($strDest, $strCallBack, $strCaller, $strSubject, $strURL, $strData, $strDate, $nCount); + + if($res) { + $LMS->Send(); + } + + $LMS->Init(); // 보관하고 있던 결과값을 지웁니다. + } + } } - } + } else { + include_once(G5_LIB_PATH.'/icode.sms.lib.php'); - // 문의글 등록시 관리자에게 전송 - if(($w == '' || $w == 'r') && trim($qaconfig['qa_admin_hp'])) { - $sms_content = $config['cf_title'].' '.$qaconfig['qa_title'].'에 문의글이 등록되었습니다.'; - $send_number = preg_replace('/[^0-9]/', '', $qa_hp); - $recv_number = preg_replace('/[^0-9]/', '', $qaconfig['qa_admin_hp']); + // 답변글은 질문 등록자에게 전송 + if($w == 'a' && $write['qa_sms_recv'] && trim($write['qa_hp'])) { + $sms_content = $config['cf_title'].' '.$qaconfig['qa_title'].'에 답변이 등록되었습니다.'; + $send_number = preg_replace('/[^0-9]/', '', $qaconfig['qa_send_number']); + $recv_number = preg_replace('/[^0-9]/', '', $write['qa_hp']); - if($recv_number) { - $SMS = new SMS; // SMS 연결 - $SMS->SMS_con($config['cf_icode_server_ip'], $config['cf_icode_id'], $config['cf_icode_pw'], $config['cf_icode_server_port']); - $SMS->Add($recv_number, $send_number, $config['cf_icode_id'], iconv("utf-8", "euc-kr", stripslashes($sms_content)), ""); - $SMS->Send(); + if($recv_number) { + $SMS = new SMS; // SMS 연결 + $SMS->SMS_con($config['cf_icode_server_ip'], $config['cf_icode_id'], $config['cf_icode_pw'], $config['cf_icode_server_port']); + $SMS->Add($recv_number, $send_number, $config['cf_icode_id'], iconv("utf-8", "euc-kr", stripslashes($sms_content)), ""); + $SMS->Send(); + } + } + + // 문의글 등록시 관리자에게 전송 + if(($w == '' || $w == 'r') && trim($qaconfig['qa_admin_hp'])) { + $sms_content = $config['cf_title'].' '.$qaconfig['qa_title'].'에 문의글이 등록되었습니다.'; + $send_number = preg_replace('/[^0-9]/', '', $qa_hp); + $recv_number = preg_replace('/[^0-9]/', '', $qaconfig['qa_admin_hp']); + + if($recv_number) { + $SMS = new SMS; // SMS 연결 + $SMS->SMS_con($config['cf_icode_server_ip'], $config['cf_icode_id'], $config['cf_icode_pw'], $config['cf_icode_server_port']); + $SMS->Add($recv_number, $send_number, $config['cf_icode_id'], iconv("utf-8", "euc-kr", stripslashes($sms_content)), ""); + $SMS->Send(); + } } } } diff --git a/install/gnuboard5.sql b/install/gnuboard5.sql index b960a9326..a3add4f4e 100644 --- a/install/gnuboard5.sql +++ b/install/gnuboard5.sql @@ -285,8 +285,9 @@ CREATE TABLE IF NOT EXISTS `g5_config` ( `cf_cert_limit` int(11) NOT NULL DEFAULT '0', `cf_cert_req` tinyint(4) NOT NULL DEFAULT '0', `cf_sms_use` varchar(255) NOT NULL DEFAULT '', + `cf_sms_type` varchar(10) NOT NULL DEFAULT '', `cf_icode_id` varchar(255) NOT NULL DEFAULT '', - `cf_icode_pw` varchar(255) NOT NULL DEFAULT '', + `cf_icode_pw` varchar(255) NOT NULL DEFAULT '', `cf_icode_server_ip` varchar(255) NOT NULL DEFAULT '', `cf_icode_server_port` varchar(255) NOT NULL DEFAULT '', `cf_googl_shorturl_apikey` varchar(255) NOT NULL DEFAULT '', diff --git a/lib/icode.lms.lib.php b/lib/icode.lms.lib.php new file mode 100644 index 000000000..29cc8877a --- /dev/null +++ b/lib/icode.lms.lib.php @@ -0,0 +1,249 @@ +socket_host = $host; + $this->socket_portcode = $portcode; + $this->icode_id = FillSpace($id, 10); + $this->icode_pw = FillSpace($pw, 10); + } + + function Init() { + $this->Data = ""; // 발송하기 위한 패킷내용이 배열로 들어간다. + $this->Result = ""; // 발송결과값이 배열로 들어간다. + } + + function Add($strDest, $strCallBack, $strCaller, $strSubject, $strURL, $strData, $strDate="", $nCount) { + + // 문자 타입별 Port 설정. + $sendType = strlen($strData) > 90 ? 1 : 0; // 0: SMS / 1: LMS + + /* 개발 완료 후 아래 포트를 rand 함수를 이용하는 라인으로 변경 바랍니다.*/ + + // 충전식 + if ($this->socket_portcode == 1) { + if($sendType && $sendType == 1) { + $this->socket_port = 8200; // LMS + //$this->socket_port=(int)rand(8200,8201); // LMS + } else { + $this->socket_port = 6295; // SMS + //$this->socket_port=(int)rand(6295,6297); // SMS + } + } + // 정액제 + else { + if($sendType && $sendType == 1) { + $this->socket_port = 8300; // LMS + //$this->socket_port=(int)rand(8300,8301); // LMS + } else { + $this->socket_port = 6291; // SMS + //$this->socket_port=(int)rand(6291,6293); // SMS + } + } + + $strCallBack = FillSpace($strCallBack, 11); // 회신번호 + $strDate = FillSpace($strDate, 12); // 즉시(12byte 공백), 예약전송(YmdHi) + + if ($sendType && $sendType == 1) { + + /** LMS 제목 **/ + /* + 제목필드의 값이 없을 경우 단말기 기종및 설정에 따라 표기 방법이 다름 + 1.설정에서 제목필드보기 설정 Disable -> 제목필드값을 넣어도 미표기 + 2.설정에서 제목필드보기 설정 Enable -> 제목을 넣지 않을 경우 제목없음으로 자동표시 + + 제목의 첫글자에 "<",">", 개행문자가 있을경우 단말기종류 및 통신사에 따라 메세지 전송실패 -> 글자를 체크하거나 취환처리요망 + $strSubject = str_replace("\r\n", " ", $strSubject); + $strSubject = str_replace("<", "[", $strSubject); + $strSubject = str_replace(">", "]", $strSubject); + */ + + $strSubject = FillSpace($strSubject,30); + $strData = FillSpace(CutChar($strData,1500),1500); + } else if (!$strURL) { + $strData = FillSpace(CutChar($strData,90),90); + $strCaller = FillSpace($strCaller,10); + } else { + $strURL = FillSpace($strURL,50); + } + + $Error = CheckCommonTypeDest($strDest, $nCount); + $Error = is_vaild_callback($strCallBack); + $Error = CheckCommonTypeDate($strDate); + + for ($i=0; $i<$nCount; $i++) { + + $strDest[$i] = FillSpace($strDest[$i],11); + if ($sendType && $sendType == 1) { + $this->Data[$i] = '01144 '.$this->icode_id.$this->icode_pw.$strDest[$i].$strCallBack.$strSubject.$strDate.$strData; + } else if (!$strURL) { + $this->Data[$i] = '01144 '.$this->icode_id.$this->icode_pw.$strDest[$i].$strCallBack.$strCaller.$strDate.$strData; + } else { + $strData = FillSpace(CheckCallCenter($strURL, $strDest[$i], $strData),80); + $this->Data[$i] = '05173 '.$this->icode_id.$this->icode_pw.$strDest[$i].$strCallBack.$strURL.$strDate.$strData; + } + } + return true; + } + + + function Send() { + $fsocket = fsockopen($this->socket_host,$this->socket_port, $errno, $errstr, 2); + if (!$fsocket) return false; + set_time_limit(300); + + foreach($this->Data as $puts) { + fputs($fsocket, $puts); + while(!$gets) { $gets = fgets($fsocket,30); } + $dest = substr($puts,26,11); + if (substr($gets,0,19) == "0223 00".$dest) { + $this->Result[] = $dest.":".substr($gets,19,10); + } else { + $this->Result[$dest] = $dest.":Error(".substr($gets,6,2).")"; + } + $gets = ""; + } + + fclose($fsocket); + $this->Data = ""; + return true; + } +} + +/** + * 원하는 문자열의 길이를 원하는 길이만큼 공백을 넣어 맞추도록 합니다. + * + * @param text 원하는 문자열입니다. + * size 원하는 길이입니다. + * @return 변경된 문자열을 넘깁니다. + */ +function FillSpace($text,$size) { + for ($i=0; $i<$size; $i++) $text.= " "; + $text = substr($text,0,$size); + return $text; +} + +/** + * 원하는 문자열을 원하는 길에 맞는지 확인해서 조정하는 기능을 합니다. + * + * @param word 원하는 문자열입니다. + * cut 원하는 길이입니다. + * @return 변경된 문자열입니다. + */ +function CutChar($word, $cut) { + $word=substr($word,0,$cut); // 필요한 길이만큼 취함. + for ($k = $cut-1; $k > 1; $k--) { + if (ord(substr($word,$k,1))<128) break; // 한글값은 160 이상. + } + $word = substr($word, 0, $cut-($cut-$k+1)%2); + return $word; +} + +/** +* 수신번호의 값이 정확한 값인지 확인합니다. +* +* @param strDest 발송번호 배열입니다. +* nCount 배열의 크기입니다. +* @return 처리결과입니다. +*/ +function CheckCommonTypeDest($strDest, $nCount) { + for ($i=0; $i<$nCount; $i++) { + $strDest[$i] = preg_replace("/[^0-9]/","",$strDest[$i]); + if(!preg_match("/^01[0-9]{8,9}$/", $strDest[$i])) + return "수신번호오류"; + } +} + + +/** +* 회신번호 유효성 여부조회 * +* @param string callback 회신번호 +* @return 처리결과입니다 +* 한국인터넷진흥원 권고 +*/ +function is_vaild_callback($callback){ + + $_callback = preg_replace('/[^0-9]/', '', $callback); + + if (!preg_match("/^(02|0[3-6]\d|01(0|1|3|5|6|7|8|9)|070|080|007)\-?\d{3,4}\-?\d{4,5}$/", $_callback) && + !preg_match("/^(15|16|18)\d{2}\-?\d{4,5}$/", $_callback)){ + return "회신번호오류"; + } + + if (preg_match("/^(02|0[3-6]\d|01(0|1|3|5|6|7|8|9)|070|080)\-?0{3,4}\-?\d{4}$/", $_callback)){ + return "회신번호오류"; + } +} + + +/** +* 예약날짜의 값이 정확한 값인지 확인합니다. +* +* @param string strDate (예약시간) +* @return 처리결과입니다 +*/ +function CheckCommonTypeDate($strDate) { + $strDate = preg_replace("/[^0-9]/", "", $strDate); + if ($strDate){ + if (!checkdate(substr($strDate,4,2),substr($strDate,6,2),substr($rsvTime,0,4))) + return "예약날짜오류"; + if (substr($strDate,8,2)>23 || substr($strDate,10,2)>59) return false; + return "예약날짜오류"; + } +} + +/** +* URL콜백용으로 메세지 크기를 수정합니다. +* +* @param url URL 내용입니다. +* msg 결과메시지입니다. +* desk 문자내용입니다. +*/ +function CheckCallCenter($url, $dest, $data) { + switch (substr($dest,0,3)) { + case '010': //20바이트 + return CutChar($data,20); break; + case '011': //80바이트 + return CutChar($data,80); break; + case '016': // 80바이트 + return CutChar($data,80); break; + case '017': // URL 포함 80바이트 + return CutChar($data,80 - strlen($url)); break; + case '018': // 20바이트 + return CutChar($data,20); break; + case '019': // 20바이트 + return CutChar($data,20); break; + default: + return CutChar($data,80); break; + } +} +?> \ No newline at end of file