biztalk_send.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?
  2. /*
  3. * 발송예약 대상자들을 검색해 발송함
  4. * 실행시간
  5. * 매 1분 실행
  6. */
  7. // ini_set('max_execution_time', 600);
  8. include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
  9. include $_SERVER['DOCUMENT_ROOT'].'/common/lib/biztalk.php';
  10. exit;
  11. if($_SERVER['REMOTE_ADDR'] != '106.243.211.195') {
  12. // echo "no";
  13. // exit;
  14. }
  15. //status 0: 자료생성중, 1: 발송대기(자료수집완료), 2: 발송중, 3: 발송완료
  16. $sql = "select *
  17. from kakao_biztalk
  18. where status = '1' and send_date < now()";
  19. // $sql = "select *
  20. // from kakao_biztalk
  21. // where status = '1' and send_date < now() and cd_talk = 1";
  22. // exit;
  23. $res = mysql_query($sql);
  24. $biztalk = new Biztalk();
  25. $biztalk->getToken();
  26. //발송대기중인 데이터 읽어옴
  27. while($col = mysql_fetch_array($res)) {
  28. if($col['status'] != "1") continue;
  29. //발송중으로 변경
  30. $standby_sql = "update kakao_biztalk set
  31. status = 2
  32. where cd_talk = '".$col['cd_talk']."' ";
  33. // echo $standby_sql;
  34. // exit;
  35. $standby_res = mysql_query($standby_sql);
  36. //업데이트 됐다면
  37. if($standby_res) {
  38. //실제 발송 대상, 발송 데이터를 가져 온다
  39. $recipient_sql = "select *
  40. from kakao_biztalk_recipient
  41. where cd_talk = '".$col['cd_talk']."'
  42. and status = '0'";
  43. //and REPLACE(phone, '-', '') in ('01072393356', '01083845309', '01096690727')";
  44. //"-- and phone = '010-7239-3356' "; //테스트 확인 용
  45. // echo $recipient_sql;
  46. // exit;
  47. $recipient_res = mysql_query($recipient_sql);
  48. while($recipient_col = mysql_fetch_array($recipient_res)) {
  49. if($recipient_col['status'] != "0") continue;
  50. $SMS_DATA = array();
  51. $SMS_DATA['message'] = $recipient_col['contents']; //발신 메시지 내용 (공백 포함2345 1000자로 제한) 가변 영역이 있을 경우 해당 가변 영역의 내용도 실제 보낼 내용으로 치환 되어야 한다.
  52. $SMS_DATA['recipient'] = $recipient_col['phone']; // 수신자
  53. $SMS_DATA['senderKey'] = $col['senderKey']; // 카카오 발신 프로필 키
  54. $SMS_DATA['tmpltCode'] = $col['tmpltCode']; // 메시지 템플릿 코드
  55. $SMS_DATA['resMethod'] = $col['resMethod']; // 메시지 템플릿 코드
  56. // $SMS_DATA['debug'] = "Y"; // 디버그
  57. // print_r($SMS_DATA);
  58. // exit;
  59. $send_reuslt = $biztalk->sendSms($SMS_DATA);
  60. // print_r($send_reuslt);
  61. // exit;
  62. // $send_reuslt = array("responseCode" => '9191', "msg" => uniqid());
  63. $status_sql = "update kakao_biztalk_recipient set
  64. status = 2
  65. , send_date = now()
  66. , code = '".$send_reuslt['responseCode']."'
  67. , msg = '".$send_reuslt['msg']."'
  68. where cd_recipient = '".$recipient_col['cd_recipient']."'
  69. and status = '0' ";
  70. mysql_query($status_sql);
  71. //
  72. // print_r($send_reuslt);
  73. // exit;
  74. unset($SMS_DATA);
  75. }
  76. //발송완료로 변경
  77. $standby_sql = "update kakao_biztalk set
  78. status = 3
  79. where cd_talk = '".$col['cd_talk']."' ";
  80. mysql_query($standby_sql);
  81. // exit;
  82. }
  83. }