GWM : sms integration
This commit is contained in:
parent
9d5dbbcfb7
commit
e45959011d
@ -101,6 +101,6 @@ class Autoload extends AutoloadConfig
|
||||
* @phpstan-var list<string>
|
||||
*/
|
||||
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'
|
||||
];
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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', ' ');
|
||||
|
||||
40
app/Helpers/sms_helper.php
Normal file
40
app/Helpers/sms_helper.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use CodeIgniter\Database\BaseConnection;
|
||||
|
||||
if (!function_exists('sendOtpSms')) {
|
||||
|
||||
|
||||
function sendOtpSms(string $mobile, string $otp)
|
||||
{
|
||||
$apiKey = env('SMS_API_KEY');
|
||||
$senderId = env('SMS_SENDER_ID');
|
||||
$templateId = env('SMS_TEMPLATE_ID');
|
||||
$serviceName = env('SMS_SERVICE_NAME');
|
||||
$appName = env('SMS_APP_NAME');
|
||||
|
||||
// Replace variables {#var#}
|
||||
$message = "Hi, Your One Time Code for logging into Nhance {$appName} App is {$otp}. Valid for 3 minutes. Please do not share this with anyone. -NHANCE";
|
||||
|
||||
// Build the API URL
|
||||
$url = "https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?" . http_build_query([
|
||||
'APIKEY' => $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];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user