From e45959011db96bc375c3a0a8c55633c2e7a0c03a Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Wed, 8 Oct 2025 10:23:14 +0530 Subject: [PATCH] GWM : sms integration --- app/Config/Autoload.php | 2 +- app/Controllers/ICICILombardController.php | 69 ++++++++++++++----- .../RestAuthenticationController.php | 40 +++++++++-- app/Helpers/sms_helper.php | 40 +++++++++++ 4 files changed, 127 insertions(+), 24 deletions(-) create mode 100644 app/Helpers/sms_helper.php diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php index be0e2476..62b24b8d 100755 --- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -101,6 +101,6 @@ class Autoload extends AutoloadConfig * @phpstan-var list */ public $helpers = ['uuid','session','utility', 'form', 'url', 'oauth', 'fileupload', - 'excel_import_export', 'file', 'drive','ExcelSanitizeHelper', 'api_helper','exception' + 'excel_import_export', 'file', 'drive','ExcelSanitizeHelper', 'api_helper','exception','sms_helper' ]; } diff --git a/app/Controllers/ICICILombardController.php b/app/Controllers/ICICILombardController.php index 928fbc2f..5c5bc627 100644 --- a/app/Controllers/ICICILombardController.php +++ b/app/Controllers/ICICILombardController.php @@ -67,24 +67,57 @@ class ICICILombardController extends AdminController //Prepare body data - $db = \Config\Database::connect(); - $data = $db->table('employee_polices ep') - ->select('cp.policy_no as policyNumber, cp.cd_ac_no as CDBGAccountNumber, - e.id,e.emp_code as MemberEmpId, e.doj as DOJ, e.name as InsuredName, e.dob as DOB, e.relationship as Relationship, - e.gender as Gender, ep.date_coverage as DOC,ep.basic_cover_si as SumInsured, e.email_corporate as EmailId - ') - ->join('employees e', 'e.id = ep.employee_id') - ->join('client_policy cp', 'ep.client_policy_id = cp.id') - ->where('ep.client_policy_id', $policy_id) - ->where('ep.status', 'active') - ->where('ep.is_active', 1) - // ->where('ep.uhid', null) - ->get() - ->getResultArray(); + // $db = \Config\Database::connect(); + // $data = $db->table('employee_polices ep') + // ->select('cp.policy_no as policyNumber, cp.cd_ac_no as CDBGAccountNumber, + // e.id,e.emp_code as MemberEmpId, e.doj as DOJ, e.name as InsuredName, e.dob as DOB, e.relationship as Relationship, + // e.gender as Gender, ep.date_coverage as DOC,ep.basic_cover_si as SumInsured, e.email_corporate as EmailId + // ') + // ->join('employees e', 'e.id = ep.employee_id') + // ->join('client_policy cp', 'ep.client_policy_id = cp.id') + // ->where('ep.client_policy_id', $policy_id) + // ->where('ep.status', 'active') + // ->where('ep.is_active', 1) + // // ->where('ep.uhid', null) + // ->get() + // ->getResultArray(); - $body = $this->formatPolicyData($data); + // $body = $this->formatPolicyData($data); // dd($body); + + $body = [ + "PolicyNumber" => "4016/A/O/53130557/00/000", + "CDBGAccountNumber" => "CD-MUM-0026", + "CorrelationId" => "550e8400-e29b-41d4-a716-446655440010", + "MemberDetails" => [ + [ + "MemberEmpId" => "EMPID3625557", + "DOJ" => "21-MAR-2019", + "InsuredName" => "Kumar", + "DOB" => "7-JUL-1983", + "Relationship" => "SELF", + "Gender" => "MALE", + "DOC" => "05-SEP-2025", + "SumInsured" => "400000", + "EmailId" => "KUMAR@GMAIL.COM", + "FlagStatus" => "A" + ], + [ + "MemberEmpId" => "EMPID3625557", + "DOJ" => "21-MAR-2019", + "InsuredName" => "Saranya", + "DOB" => "8-AUG-1970", + "Relationship" => "MOTHER", + "Gender" => "FEMALE", + "DOC" => "05-SEP-2025", + "SumInsured" => "400000", + "EmailId" => "Saranya@GMAIL.COM", + "FlagStatus" => "A" + ], + ] + ]; + $response = call_third_party_api($url, 'POST', $headers, $body, true); // true = raw body mode // print_rr(json_encode($response));die(); return $this->response->setJSON($response); @@ -115,9 +148,9 @@ class ICICILombardController extends AdminController // dd($headers); $body = [ - "PolicyNumber" => "4016/A/O/53077718/00/000", - "BatchId" => "3646145", - "CorrelationId" => "550e8400-e29b-41d4-a716-446655440001" + "PolicyNumber" => "4016/A/O/53130557/00/000", + "BatchId" => "3658147", + "CorrelationId" => "550e8400-e29b-41d4-a716-446655440010" ]; $response = call_third_party_api($url, 'POST', $headers, $body, true); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 26c8aedc..aaa7c09e 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -112,12 +112,42 @@ class RestAuthenticationController extends AdminController if (isset($employeeData['employee_id'])) { - $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: Employee found: employee_id = " . $employeeData['employee_id']); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: Employee verified with ID = " . $employeeData['employee_id']); log_message('error', ' '); - log_message('error', ' ************************************* POST END **************************************** '); - log_message('error', ' '); - $result = ['user_verification' => true ,'message' => "Verified Successfully"]; - return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + log_message('error', '************************ PRE END ********************************'); + + $otp = random_int(100000, 999999); + $sql = " + UPDATE employees + INNER JOIN employee_polices ON employee_polices.employee_id = employees.id + SET employees.otp = ? + WHERE employees.id = ? + AND employees.relationship = 'self' + AND employees.is_active = 1 + AND employee_polices.is_active = 1 + AND employee_polices.status IN ('draft', 'enrolled') + "; + + $db = db_connect(); + $update = $db->query($sql, [$otp, $employeeData['employee_id']]); + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: OTP update query executed. SQL = " . $db->getLastQuery()); + + if($update) + { + //send sms + $SMSResult = sendOtpSms($mobile_number, $otp); + if ($SMSResult['status'] == 'success') + { + $result = ['user_verification' => true ,'message' => "Verified Successfully" ]; + return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + }else{ + $result = ['user_verification' => false, 'message' => "SMS sending failed , try again"]; + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); + } + + } + } else { $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: No matching employee found"); log_message('error', ' '); diff --git a/app/Helpers/sms_helper.php b/app/Helpers/sms_helper.php new file mode 100644 index 00000000..c4fa87aa --- /dev/null +++ b/app/Helpers/sms_helper.php @@ -0,0 +1,40 @@ + $apiKey, + 'MobileNo' => $mobile, + 'SenderID' => $senderId, + 'Message' => $message, + 'ServiceName' => $serviceName, + 'DLTTemplateID' => $templateId, + ]); + + // Send request + $response = @file_get_contents($url); + + // If response failed + if ($response === FALSE) { + return ['status' => 'failed', 'message' => 'Failed to send SMS.']; + } + + + return ['status' => 'success', 'message' => 'OTP sent successfully', 'api_response' => $response]; + } +}