| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?
- /*
- * 발송예약 대상자들을 검색해 발송함
- * 실행시간
- * 매 1분 실행
- */
- // ini_set('max_execution_time', 600);
- include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
- include $_SERVER['DOCUMENT_ROOT'].'/common/lib/biztalk.php';
- exit;
- if($_SERVER['REMOTE_ADDR'] != '106.243.211.195') {
- // echo "no";
- // exit;
- }
- //status 0: 자료생성중, 1: 발송대기(자료수집완료), 2: 발송중, 3: 발송완료
- $sql = "select *
- from kakao_biztalk
- where status = '1' and send_date < now()";
- // $sql = "select *
- // from kakao_biztalk
- // where status = '1' and send_date < now() and cd_talk = 1";
- // exit;
- $res = mysql_query($sql);
- $biztalk = new Biztalk();
- $biztalk->getToken();
- //발송대기중인 데이터 읽어옴
- while($col = mysql_fetch_array($res)) {
- if($col['status'] != "1") continue;
- //발송중으로 변경
- $standby_sql = "update kakao_biztalk set
- status = 2
- where cd_talk = '".$col['cd_talk']."' ";
- // echo $standby_sql;
- // exit;
- $standby_res = mysql_query($standby_sql);
- //업데이트 됐다면
- if($standby_res) {
- //실제 발송 대상, 발송 데이터를 가져 온다
- $recipient_sql = "select *
- from kakao_biztalk_recipient
- where cd_talk = '".$col['cd_talk']."'
- and status = '0'";
- //and REPLACE(phone, '-', '') in ('01072393356', '01083845309', '01096690727')";
- //"-- and phone = '010-7239-3356' "; //테스트 확인 용
- // echo $recipient_sql;
- // exit;
- $recipient_res = mysql_query($recipient_sql);
- while($recipient_col = mysql_fetch_array($recipient_res)) {
- if($recipient_col['status'] != "0") continue;
- $SMS_DATA = array();
- $SMS_DATA['message'] = $recipient_col['contents']; //발신 메시지 내용 (공백 포함2345 1000자로 제한) 가변 영역이 있을 경우 해당 가변 영역의 내용도 실제 보낼 내용으로 치환 되어야 한다.
- $SMS_DATA['recipient'] = $recipient_col['phone']; // 수신자
- $SMS_DATA['senderKey'] = $col['senderKey']; // 카카오 발신 프로필 키
- $SMS_DATA['tmpltCode'] = $col['tmpltCode']; // 메시지 템플릿 코드
- $SMS_DATA['resMethod'] = $col['resMethod']; // 메시지 템플릿 코드
- // $SMS_DATA['debug'] = "Y"; // 디버그
- // print_r($SMS_DATA);
- // exit;
- $send_reuslt = $biztalk->sendSms($SMS_DATA);
- // print_r($send_reuslt);
- // exit;
- // $send_reuslt = array("responseCode" => '9191', "msg" => uniqid());
- $status_sql = "update kakao_biztalk_recipient set
- status = 2
- , send_date = now()
- , code = '".$send_reuslt['responseCode']."'
- , msg = '".$send_reuslt['msg']."'
- where cd_recipient = '".$recipient_col['cd_recipient']."'
- and status = '0' ";
- mysql_query($status_sql);
- //
- // print_r($send_reuslt);
- // exit;
- unset($SMS_DATA);
- }
- //발송완료로 변경
- $standby_sql = "update kakao_biztalk set
- status = 3
- where cd_talk = '".$col['cd_talk']."' ";
- mysql_query($standby_sql);
- // exit;
- }
- }
|