CHANGE_ visit login api creation : GWM

This commit is contained in:
Gowtham M 2025-09-20 17:51:44 +05:30
parent 6de8dd9449
commit e5ffcd1ae4
3 changed files with 203 additions and 70 deletions

View File

@ -3810,24 +3810,147 @@ class EmployeeRestController extends AdminController
public function getWellnessUrl() public function getWellnessUrl()
{ {
// $url = NhanceWelnessSsoHelper::generateSSOUrl();
// echo $url;die();
// $url = "https://aam.mohfw.gov.in/home/login";
$url = "";
if (!empty($url)) { $emp_id = $this->request->getGet('emp_id');
return $this->respond([ $db = \Config\Database::connect();
'status' => 'success', $data = $db->table('employees e')
'data' => $url ->select('pt.policy_type,
], 200); e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation,
cp.policy_no as policyNumber, cp.policy_no as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate')
->join('employee_polices ep', 'e.id = ep.employee_id')
->join('client_policy cp', 'ep.client_policy_id = cp.id')
->join('policy_type pt', 'cp.policy_type_id = pt.id')
->where('e.id', $emp_id)
->where('e.emp_status', 'active')
->where('ep.status', 'active')
->where('e.is_active', 1)
->where('ep.is_active', 1)
->get()
->getResultArray();
// Loop through $data and check for policy_type = GMC
$userParams = [];
foreach ($data as $row) {
if ($row['policy_type'] === 'GMC') {
$userParams['name'] = $row['name'];
$userParams['email'] = $row['email'];
$userParams['phone'] = $row['phone'];
$userParams['memberId'] = $row['memberId'];
$userParams['gender'] = $row['gender'];
$userParams['dob'] = $row['dob'];
$userParams['relation'] = $row['relation'];
$userParams['policyNumber'] = $row['policyNumber'];
$userParams['employeeId'] = $row['employeeId'];
$userParams['policyStartDate']= $row['policyStartDate'];
$userParams['policyEndDate'] = $row['policyEndDate'];
$userParams['policyName'] = 'Nhance ' . $row['policy_type'];
$userParams['planId'] = 'NHANCE-PLAN-' . $row['policy_type'];
$userParams['moduleName'] = 'home';
break; // stop after first GMC match
}
}
if (empty($userParams)) {
return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200);
}
// Derive 32-byte key from SHA256
$derivedKey = hash('sha256', env('VISIT_SECRET_KEY'), true);
// Build query string like Node.js
$plainText = '';
foreach ($userParams as $k => $v) {
$plainText .= "&{$k}={$v}";
}
$plainText = ltrim($plainText, '&');
// Encrypt
$algorithm = "aes-256-cbc";
$encrypted = openssl_encrypt($plainText, $algorithm, $derivedKey, OPENSSL_RAW_DATA, env('VISIT_IV'));
// Base64URL encode (same as Node.js output)
$output = rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '=');
$baseURL = env('VISIT_BASE_URL');
$clientId = env('VISIT_CLIENT_ID');
$finalUrl = $baseURL . '/sso?userParams=' . $output . '&clientId=' . $clientId;
if (!empty($finalUrl)) {
return $this->respond(['status' => 'success','data' => $finalUrl], 200);
} else { } else {
return $this->respond([ return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200);
'status' => 'failed',
'message' => 'Coming soon........!'
], 200);
} }
} }
// not in use did for testing
function encrypt_for_sso(): string {
$key = "32D1D5535157AF3D4667ADAB0CC795D77D022BB281AD3272EB134C72BD0B185E";
$userParams = [
"name" => "John Doe 3",
"email" => "john.doe3@email.com",
"memberId" => "TEST-REL-01",
"gender" => "Male",
"dob" => "1997-01-01",
"policyName" => "Nhance DEMO",
"phone" => "6676126763",
"employeeId" => "EMP-NHANCE-TEST-03",
"policyNumber" => "EMP-NHANCE-TEST-03",
"policyStartDate" => "2025-09-08",
"policyEndDate" => "2026-09-08",
"moduleName" => "home",
"relation" => "self",
"planId" => "NHANCE-PLAN-1"
];
$algorithm = "aes-256-cbc";
// Derive 32-byte key from SHA256
$derivedKey = hash('sha256', $key, true);
// Fixed IV (must be 16 bytes)
$iv = "getvisitappdocom";
// Build query string like Node.js
$plainText = '';
foreach ($userParams as $k => $v) {
$plainText .= "&{$k}={$v}";
}
$plainText = ltrim($plainText, '&');
// echo ($plainText); die;
// Encrypt
$encrypted = openssl_encrypt($plainText, $algorithm, $derivedKey, OPENSSL_RAW_DATA, $iv);
// Base64URL encode (same as Node.js output)
$output = rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '=');
// return $output;
$baseURL = 'https://web.getvisitapp.net';
$clientId = 'nhance-gt-2tx7';
$finalUrl = $baseURL . '/sso?userParams=' . $output . '&clientId=' . $clientId;
return $finalUrl;
}
public function getEmployeePolicyCount() public function getEmployeePolicyCount()
{ {
$db2 = \Config\Database::connect('preDB'); $db2 = \Config\Database::connect('preDB');

View File

@ -10,7 +10,6 @@ class ICICILombardController extends AdminController
public function generateAuthToken($scope = 'esbhealth') public function generateAuthToken($scope = 'esbhealth')
{ {
helper('api'); helper('api');
// dd($scope);
$url = 'https://ilesbapigee.insurancearticlez.com/generate-jwt-token'; $url = 'https://ilesbapigee.insurancearticlez.com/generate-jwt-token';
$method = 'POST'; $method = 'POST';
$headers = [ $headers = [
@ -24,10 +23,10 @@ class ICICILombardController extends AdminController
'client_id' => 'Nhanceins', 'client_id' => 'Nhanceins',
'client_secret' => 'P4W0G6TAYMa0MV8bbVSx4pTAqbCcUIg48kCWa6PJykAhGWzPmpPr0iLuNWtz5wqN' 'client_secret' => 'P4W0G6TAYMa0MV8bbVSx4pTAqbCcUIg48kCWa6PJykAhGWzPmpPr0iLuNWtz5wqN'
]; ];
print_rr(json_encode($body));//die;
$response = call_third_party_api($url, $method, $headers, $body); $response = call_third_party_api($url, $method, $headers, $body);
print_rr(json_encode($response));//die;
if($response['status'] != true){ if($response['status'] != true){
return $this->response->setJSON([ return $this->response->setJSON([
'status' => false, 'status' => false,
@ -73,54 +72,39 @@ class ICICILombardController extends AdminController
$body = [ $body = [
"PolicyNumber" => "4016/A/O/53077718/00/000", "PolicyNumber" => "4016/A/O/53077718/00/000",
"CDBGAccountNumber" => "CD-MUM-0026", "CDBGAccountNumber" => "CD-MUM-0026",
"CorrelationId" => "86383c78-4c67-4e4d-9aa0-8f926fb0d55f", "CorrelationId" => "550e8400-e29b-41d4-a716-446655440001",
"MemberDetails" => [ "MemberDetails" => [
[ [
"MemberEmpId" => "EMPID3625556", "MemberEmpId" => "EMPID3625557",
"DOJ" => "21-MAR-2019", "DOJ" => "21-MAR-2019",
"InsuredName" => "ABC28144", "InsuredName" => "Kumar",
"DOB" => "7-JUL-1983", "DOB" => "7-JUL-1983",
"Relationship" => "SELF", "Relationship" => "SELF",
"Gender" => "MALE", "Gender" => "MALE",
"DOC" => "08-JUL-2025", "DOC" => "08-JUL-2025",
"SumInsured" => "400000", "SumInsured" => "400000",
"EmailId" => "ABC@GMAIL.COM", "EmailId" => "KUMAR@GMAIL.COM",
"FlagStatus" => "A" "FlagStatus" => "A"
], ],
[ [
"MemberEmpId" => "EMPID3625556", "MemberEmpId" => "EMPID3625557",
"DOJ" => "21-MAR-2019", "DOJ" => "21-MAR-2019",
"InsuredName" => "ABC28146", "InsuredName" => "Saranya",
"DOB" => "8-AUG-1970", "DOB" => "8-AUG-1970",
"Relationship" => "MOTHER", "Relationship" => "MOTHER",
"Gender" => "FEMALE", "Gender" => "FEMALE",
"DOC" => "08-JUL-2025", "DOC" => "08-JUL-2025",
"SumInsured" => "400000", "SumInsured" => "400000",
"EmailId" => "ABC@GMAIL.COM", "EmailId" => "Saranya@GMAIL.COM",
"FlagStatus" => "A" "FlagStatus" => "A"
], ],
[
"MemberEmpId" => "EMPID0502220011",
"UHID" => "IL00688842553",
"InsuredName" => "ABC28142",
"DOB" => "8-SEP-1970",
"Gender" => "MALE",
"SumInsured" => "400000",
"EmailId" => "ABC@GMAIL.COM",
"FlagStatus" => "M"
],
// [
// "UHID" => "IL00688842552",
// "DOL" => "08-JUL-2025",
// "FlagStatus" => "D"
// ]
] ]
]; ];
// Kint::dump($body); // Kint::dump($body);
print_rr(json_encode($body)); // print_rr(json_encode($body));
// dd(); // dd();
$response = call_third_party_api($url, 'POST', $headers, ($body),true); // true = raw body mode $response = call_third_party_api($url, 'POST', $headers, ($body),true); // true = raw body mode
print_rr(json_encode($response));die(); // print_rr(json_encode($response));die();
return $this->response->setJSON($response); return $this->response->setJSON($response);
} }
@ -129,7 +113,7 @@ class ICICILombardController extends AdminController
helper('api'); helper('api');
//fetch token //fetch token
$tokenResponse = $this->generateAuthToken('esbgpabatchstatus'); $tokenResponse = $this->generateAuthToken();
if (!$tokenResponse || empty($tokenResponse['data']['access_token'])) { if (!$tokenResponse || empty($tokenResponse['data']['access_token'])) {
return $this->response->setJSON([ return $this->response->setJSON([
'status' => false, 'status' => false,
@ -146,21 +130,15 @@ class ICICILombardController extends AdminController
'Content-Type: application/json' 'Content-Type: application/json'
]; ];
// $body = [ // dd($headers);
// "PolicyNumber" => "4016/A/51974976/00/000",
// "BatchId" => "2345617878",
// "CorrelationId" => "86383c78-4c67-4e4d-9aa0-8f926fb0d55f"
// ];
$body = [ $body = [
"PolicyNumber" => "4016/A/O/53077718/00/000", "PolicyNumber" => "4016/A/O/53077718/00/000",
// "BatchId" => "3642146", "BatchId" => "3646145",
"BatchId" => "3642149", "CorrelationId" => "550e8400-e29b-41d4-a716-446655440001"
"CorrelationId" => "86383c78-4c67-4e4d-9aa0-8f926fb0d55f"
]; ];
// $response = call_third_party_api($url, 'POST', $headers, json_encode($body), true); $response = call_third_party_api($url, 'POST', $headers, $body, true);
$response = call_third_party_api($url, 'POST', $headers, ($body), true);
return $this->response->setJSON($response); return $this->response->setJSON($response);
} }
@ -180,6 +158,8 @@ class ICICILombardController extends AdminController
} }
$token = $tokenResponse['data']['access_token']; $token = $tokenResponse['data']['access_token'];
// print_rr($token);
$url = 'https://ilesbapigee.insurancearticlez.com/health/ilservices/health/v1/enrollment/fetchuhid'; $url = 'https://ilesbapigee.insurancearticlez.com/health/ilservices/health/v1/enrollment/fetchuhid';
$headers = [ $headers = [
'Authorization: Bearer ' . $token, 'Authorization: Bearer ' . $token,
@ -189,10 +169,10 @@ class ICICILombardController extends AdminController
$body = [ $body = [
"PolicyNumber" => "4016/A/51974976/00/000", "PolicyNumber" => "4016/A/51974976/00/000",
"IMID" => "2345617878", "IMID" => "2345617878",
"CorrelationId" => "86383c78-4c67-4e4d-9aa0-8f926fb0d55f" "CorrelationId" => "86383c78-4c67-4e4d-9aa0-9f926fb0d55e"
]; ];
$response = call_third_party_api($url, 'POST', $headers, json_encode($body), true); $response = call_third_party_api($url, 'POST', $headers, $body, true);
return $this->response->setJSON($response); return $this->response->setJSON($response);
} }

View File

@ -99,28 +99,58 @@ class NhanceWelnessSsoHelper {
*/ */
private static function encryptUserParams($userParams) { private static function encryptUserParams($userParams) {
try { try {
$jsonData = json_encode($userParams); // $jsonData = json_encode($userParams);
// Generate a random IV // // Generate a random IV
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(SELF::$algorithm)); // $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(SELF::$algorithm));
// $iv = 'getvisitappdotcom'; // // $iv = 'getvisitappdotcom';
// Convert hex key to binary // // Convert hex key to binary
$key = hex2bin(SELF::$encryptionKey); // $key = hex2bin(SELF::$encryptionKey);
// $key = (SELF::$encryptionKey); // // $key = (SELF::$encryptionKey);
// Encrypt the data // // Encrypt the data
$encrypted = openssl_encrypt($jsonData, SELF::$algorithm, $key, 0, $iv); // $encrypted = openssl_encrypt($jsonData, SELF::$algorithm, $key, 0, $iv);
if ($encrypted === false) { // if ($encrypted === false) {
throw new Exception("Encryption failed"); // throw new Exception("Encryption failed");
// }
// // Combine IV and encrypted data, then encode
// $encryptedData = base64_encode($iv . base64_decode($encrypted));
// // Make URL safe
// return str_replace(['+', '/', '='], ['-', '_', ''], $encryptedData);
$key = "getvisitappdotcom";
// Step 1: Build plaintext exactly like Node (raw join with '&')
$str = '';
foreach ($userParams as $k => $v) {
$str .= '&' . $k . '=' . $v;
} }
$plainText = substr($str, 1); // remove leading &
// Combine IV and encrypted data, then encode
$encryptedData = base64_encode($iv . base64_decode($encrypted)); // Step 2: Derive 32-byte key with SHA256
$sha256Key = hash('sha256', $key, true);
// Make URL safe
return str_replace(['+', '/', '='], ['-', '_', ''], $encryptedData); // Step 3: Fixed IV
$iv = "getvisitappdocom"; // 16 bytes
// Step 4: Encrypt
$cipherRaw = openssl_encrypt(
$plainText,
'aes-256-cbc',
$sha256Key,
OPENSSL_RAW_DATA,
$iv
);
// Step 5: base64url encode
return rtrim(strtr(base64_encode($cipherRaw), '+/', '-_'), '=');
} catch (Exception $e) { } catch (Exception $e) {
log_message('error', 'Nhance SSO Encryption Error: ' . $e->getMessage()); log_message('error', 'Nhance SSO Encryption Error: ' . $e->getMessage());