CHANGE_ visit login api creation : GWM
This commit is contained in:
parent
6de8dd9449
commit
e5ffcd1ae4
@ -3810,24 +3810,147 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
public function getWellnessUrl()
|
||||
{
|
||||
// $url = NhanceWelnessSsoHelper::generateSSOUrl();
|
||||
// echo $url;die();
|
||||
// $url = "https://aam.mohfw.gov.in/home/login";
|
||||
$url = "";
|
||||
|
||||
if (!empty($url)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $url
|
||||
], 200);
|
||||
$emp_id = $this->request->getGet('emp_id');
|
||||
$db = \Config\Database::connect();
|
||||
$data = $db->table('employees e')
|
||||
->select('pt.policy_type,
|
||||
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 {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Coming soon........!'
|
||||
], 200);
|
||||
return $this->respond(['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()
|
||||
{
|
||||
$db2 = \Config\Database::connect('preDB');
|
||||
|
||||
@ -10,7 +10,6 @@ class ICICILombardController extends AdminController
|
||||
public function generateAuthToken($scope = 'esbhealth')
|
||||
{
|
||||
helper('api');
|
||||
// dd($scope);
|
||||
$url = 'https://ilesbapigee.insurancearticlez.com/generate-jwt-token';
|
||||
$method = 'POST';
|
||||
$headers = [
|
||||
@ -24,10 +23,10 @@ class ICICILombardController extends AdminController
|
||||
'client_id' => 'Nhanceins',
|
||||
'client_secret' => 'P4W0G6TAYMa0MV8bbVSx4pTAqbCcUIg48kCWa6PJykAhGWzPmpPr0iLuNWtz5wqN'
|
||||
];
|
||||
print_rr(json_encode($body));//die;
|
||||
|
||||
$response = call_third_party_api($url, $method, $headers, $body);
|
||||
|
||||
print_rr(json_encode($response));//die;
|
||||
|
||||
if($response['status'] != true){
|
||||
return $this->response->setJSON([
|
||||
'status' => false,
|
||||
@ -73,54 +72,39 @@ class ICICILombardController extends AdminController
|
||||
$body = [
|
||||
"PolicyNumber" => "4016/A/O/53077718/00/000",
|
||||
"CDBGAccountNumber" => "CD-MUM-0026",
|
||||
"CorrelationId" => "86383c78-4c67-4e4d-9aa0-8f926fb0d55f",
|
||||
"CorrelationId" => "550e8400-e29b-41d4-a716-446655440001",
|
||||
"MemberDetails" => [
|
||||
[
|
||||
"MemberEmpId" => "EMPID3625556",
|
||||
"MemberEmpId" => "EMPID3625557",
|
||||
"DOJ" => "21-MAR-2019",
|
||||
"InsuredName" => "ABC28144",
|
||||
"InsuredName" => "Kumar",
|
||||
"DOB" => "7-JUL-1983",
|
||||
"Relationship" => "SELF",
|
||||
"Gender" => "MALE",
|
||||
"DOC" => "08-JUL-2025",
|
||||
"SumInsured" => "400000",
|
||||
"EmailId" => "ABC@GMAIL.COM",
|
||||
"EmailId" => "KUMAR@GMAIL.COM",
|
||||
"FlagStatus" => "A"
|
||||
],
|
||||
[
|
||||
"MemberEmpId" => "EMPID3625556",
|
||||
"MemberEmpId" => "EMPID3625557",
|
||||
"DOJ" => "21-MAR-2019",
|
||||
"InsuredName" => "ABC28146",
|
||||
"InsuredName" => "Saranya",
|
||||
"DOB" => "8-AUG-1970",
|
||||
"Relationship" => "MOTHER",
|
||||
"Gender" => "FEMALE",
|
||||
"DOC" => "08-JUL-2025",
|
||||
"SumInsured" => "400000",
|
||||
"EmailId" => "ABC@GMAIL.COM",
|
||||
"EmailId" => "Saranya@GMAIL.COM",
|
||||
"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);
|
||||
print_rr(json_encode($body));
|
||||
// print_rr(json_encode($body));
|
||||
// dd();
|
||||
$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);
|
||||
}
|
||||
|
||||
@ -129,7 +113,7 @@ class ICICILombardController extends AdminController
|
||||
helper('api');
|
||||
|
||||
//fetch token
|
||||
$tokenResponse = $this->generateAuthToken('esbgpabatchstatus');
|
||||
$tokenResponse = $this->generateAuthToken();
|
||||
if (!$tokenResponse || empty($tokenResponse['data']['access_token'])) {
|
||||
return $this->response->setJSON([
|
||||
'status' => false,
|
||||
@ -146,21 +130,15 @@ class ICICILombardController extends AdminController
|
||||
'Content-Type: application/json'
|
||||
];
|
||||
|
||||
// $body = [
|
||||
// "PolicyNumber" => "4016/A/51974976/00/000",
|
||||
// "BatchId" => "2345617878",
|
||||
// "CorrelationId" => "86383c78-4c67-4e4d-9aa0-8f926fb0d55f"
|
||||
// ];
|
||||
// dd($headers);
|
||||
|
||||
$body = [
|
||||
"PolicyNumber" => "4016/A/O/53077718/00/000",
|
||||
// "BatchId" => "3642146",
|
||||
"BatchId" => "3642149",
|
||||
"CorrelationId" => "86383c78-4c67-4e4d-9aa0-8f926fb0d55f"
|
||||
"BatchId" => "3646145",
|
||||
"CorrelationId" => "550e8400-e29b-41d4-a716-446655440001"
|
||||
];
|
||||
|
||||
// $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);
|
||||
}
|
||||
@ -180,6 +158,8 @@ class ICICILombardController extends AdminController
|
||||
}
|
||||
$token = $tokenResponse['data']['access_token'];
|
||||
|
||||
// print_rr($token);
|
||||
|
||||
$url = 'https://ilesbapigee.insurancearticlez.com/health/ilservices/health/v1/enrollment/fetchuhid';
|
||||
$headers = [
|
||||
'Authorization: Bearer ' . $token,
|
||||
@ -189,10 +169,10 @@ class ICICILombardController extends AdminController
|
||||
$body = [
|
||||
"PolicyNumber" => "4016/A/51974976/00/000",
|
||||
"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);
|
||||
}
|
||||
|
||||
@ -99,28 +99,58 @@ class NhanceWelnessSsoHelper {
|
||||
*/
|
||||
private static function encryptUserParams($userParams) {
|
||||
try {
|
||||
$jsonData = json_encode($userParams);
|
||||
// $jsonData = json_encode($userParams);
|
||||
|
||||
// Generate a random IV
|
||||
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(SELF::$algorithm));
|
||||
// $iv = 'getvisitappdotcom';
|
||||
// // Generate a random IV
|
||||
// $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(SELF::$algorithm));
|
||||
// // $iv = 'getvisitappdotcom';
|
||||
|
||||
// Convert hex key to binary
|
||||
$key = hex2bin(SELF::$encryptionKey);
|
||||
// $key = (SELF::$encryptionKey);
|
||||
// // Convert hex key to binary
|
||||
// $key = hex2bin(SELF::$encryptionKey);
|
||||
// // $key = (SELF::$encryptionKey);
|
||||
|
||||
// Encrypt the data
|
||||
$encrypted = openssl_encrypt($jsonData, SELF::$algorithm, $key, 0, $iv);
|
||||
// // Encrypt the data
|
||||
// $encrypted = openssl_encrypt($jsonData, SELF::$algorithm, $key, 0, $iv);
|
||||
|
||||
if ($encrypted === false) {
|
||||
throw new Exception("Encryption failed");
|
||||
// if ($encrypted === false) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Combine IV and encrypted data, then encode
|
||||
$encryptedData = base64_encode($iv . base64_decode($encrypted));
|
||||
|
||||
// Make URL safe
|
||||
return str_replace(['+', '/', '='], ['-', '_', ''], $encryptedData);
|
||||
$plainText = substr($str, 1); // remove leading &
|
||||
|
||||
// Step 2: Derive 32-byte key with SHA256
|
||||
$sha256Key = hash('sha256', $key, true);
|
||||
|
||||
// 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) {
|
||||
log_message('error', 'Nhance SSO Encryption Error: ' . $e->getMessage());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user