email = service('email'); $this->logger = service('logger'); } public function sendSms($number, $name= '', $otp='', $url ='', $message_type_name, $client_full_data='') { $apiKey = getenv('API_KEY'); $mobileNumbers = $number; $DLTTemplateID = getenv('DLT_Template_ID'); $senderId = getenv('SENDER_ID'); if($message_type_name == 'doc_verify') { $client_name = $client_full_data['client_name']; $message = 'Dear '. substr($client_name, 0, 20) .', '. $otp .' is OTP to approve '. $client_full_data['group_name'] .' for '. $client_full_data['service_name'] .' purposes. -L D RAJ AND CO'; } $serviceName = getenv('SERVICE_NAME'); // Service name // URL encode the message $encodedMessage = urlencode($message); // Initialize cURL $ch = curl_init(); // Set cURL options curl_setopt($ch, CURLOPT_URL, "https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=$apiKey&MobileNo=$mobileNumbers&SenderID=$senderId&Message=$encodedMessage&ServiceName=$serviceName&DLTTemplateID=$DLTTemplateID"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Execute cURL request and get the response $output = curl_exec($ch); // Close cURL session curl_close($ch); // Output the response (for testing purposes) // return $this->response->setJSON(['response' => $output]); return json_encode(['response' => $output]); } public function send_whatsapp_message($to, $client_name , $business_name , $doc_url) { $url = 'https://graph.facebook.com/v20.0/355752820961010/messages'; $headers = [ 'Authorization: Bearer '.$_ENV['whatsAppToken'], 'Content-Type: application/json' ]; $templateName = 'bbsigndoc'; $languageCode = 'en'; $parsedUrl = parse_url($doc_url, PHP_URL_QUERY); $data = [ 'messaging_product' => 'whatsapp', 'to' => $to, 'type' => 'template', 'template' => [ 'name' => $templateName, 'language' => [ 'code' => $languageCode ], 'components' => [ [ 'type' => 'body', 'parameters' => [ [ 'type' => 'text', 'text' => $client_name ], [ 'type' => 'text', 'text' => $business_name ] ] ], [ 'type' => 'button', 'sub_type' => 'url', 'index' => 0, 'parameters' => [ [ 'type' => 'text', 'text' => $parsedUrl ] ] ] ] ] ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); $response = curl_exec($ch); $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return [ 'status_code' => $statusCode, 'response' => json_decode($response, true) ]; } } ?>