'01011112222', 'name' => '홍길동', // 아래 부분만 알림톡 템플릿 변수와 1:1 매칭! '이벤트 명' => '여름휴가 응모 이벤트', '상품명' => '스타벅스 기프티콘', '당첨일' => '2024-06-12', '고객센터번호' => '1544-1234' ] ]; // 기본 파라미터 $variables = [ 'apikey' => 'npb9ryvqh9439js2sfbhuji4lwfmdgqu', 'userid' => 'interscope', 'senderkey' => '846700656ab2c0b136e4433751d75018ea48b8ec', 'tpl_code' => 'UA_1201', 'sender' => '010-8384-5309', //'senddate' => date("YmdHis", strtotime("+10 minutes")), ]; // 수신자별 파라미터 추가 foreach ($receivers as $idx => $info) { $i = $idx + 1; $variables["receiver_{$i}"] = $info['phone']; $variables["recvname_{$i}"] = $info['name']; // 템플릿 변수값 매칭 $variables["subject_{$i}"] = ''; // 필요 없으면 공란 $variables["message_{$i}"] = "안녕하세요 고객님!\n" . "{$info['이벤트 명']}\n" . "{$info['상품명']} 당첨을 축하드립니다.\n" . "당첨일자 : {$info['당첨일']}\n\n" . "*이 메시지는 고객님이 참여한 이벤트 당첨으로 발송된 안내 메시지입니다.\n\n" . "문의 : 고객센터 {$info['고객센터번호']}\n" . "감사합니다."; // 버튼 필요시 추가 // $variables["button_{$i}"] = '...'; } $apiURL = 'https://kakaoapi.aligo.in/akv10/alimtalk/send/'; $hostInfo = parse_url($apiURL); $port = (strtolower($hostInfo['scheme']) == 'https') ? 443 : 80; // cURL 요청 $ch = curl_init(); curl_setopt($ch, CURLOPT_PORT, $port); curl_setopt($ch, CURLOPT_URL, $apiURL); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($variables)); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); $error_msg = curl_error($ch); curl_close($ch); // 결과 출력 (json) if ($error_msg) { return $this->response->setJSON(['error' => $error_msg]); } $result = json_decode($response, true); return $this->response->setJSON($result); } }