FEAT_MEDI_BUDDY

This commit is contained in:
VENKATESHWARAN 2026-03-13 15:59:47 +05:30
parent d253ce0bed
commit 8d5f6a9e89
5 changed files with 150 additions and 2 deletions

View File

@ -138,3 +138,11 @@ LEAD_CLIENT_FROM_MAIL_ID =
# BDS Daily Report Emails Configuration
bds.dailyReportEmails =
#--------------------------------------------------------------------
# MEDI ASSIST WELLNESS SSO Configuration
#--------------------------------------------------------------------
MEDIASSIST_WELLNESS_KEY =
MEDIASSIST_WELLNESS_IV =
MEDIASSIST_WELLNESS_LOGIN_URL =

View File

@ -451,6 +451,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
$routes->get('croneDailyActivityReport', 'DashboardController::croneDailyActivityReport');
$routes->get('insertSampleTpaApiData/(:any)', 'TestingController::insertSampleTpaApiData/$1');
$routes->get('listEmployeeCountByClientPolicy', 'TestingController::listEmployeeCountByClientPolicy');
$routes->get('testMediAssistWellness','TestingController::testMediAssistWellness');
});
$routes->post("policy_tranction/sendInstallmentRemainderMail","PolicyTransactionController::sendInstallmentRemainderMail");

View File

@ -425,13 +425,17 @@ class ApiServiceController extends BaseController
$userParams = [];
foreach ($data as $row) {
if($row['wellness_vendor_id'] != null)
if($row['wellness_vendor_id'] == $this->vidal_primary_key)
{
$vidalApiController = new VidalApiController();
return $vidalApiController->getWellnessSSORedirectUrl($row['email']);
}else if ($row['wellness_vendor_id'] == $this->medi_assist_primary_key)
{
$mediAssistController = new MediAssistApiController();
return $mediAssistController->getWellnessSSORedirectUrl($row['planId'], $row['memberId']);
}
else if ($row['planId'] != null) // VISIT
else if ($row['planId'] != null && empty($row['wellness_vendor_id'])) // VISIT
{
$userParams['name'] = $row['name'];
$userParams['email'] = $row['email'];

View File

@ -1349,7 +1349,72 @@ class MediAssistApiController extends BaseController
}
public function getWellnessSSORedirectUrl($planId, $emp_code)
{
log_message('error', 'MEDI_ASSIST - Wellness SSO URL generation | Plan ID: ' . $planId . ' | Employee code: ' . $emp_code);
if (empty($planId) || empty($emp_code)) {
log_message('error', 'MEDI_ASSIST - Wellness SSO URL generation | Plan ID and employee code are required.');
return [
'status' => 'failed',
'message' => 'Coming soon........!',
];
}
// Configuration prefer environment variables, fall back to demo values
$keyString = env('MEDIASSIST_WELLNESS_KEY');
$ivString = env('MEDIASSIST_WELLNESS_IV');
$loginUrlTemplate = env('MEDIASSIST_WELLNESS_LOGIN_URL');
$cipher_algorithm = 'AES-256-CBC';
if (empty($keyString) || empty($ivString) || empty($loginUrlTemplate)) {
log_message('error', 'MEDI_ASSIST - Wellness SSO URL generation | Key string, IV string and login URL are required.');
return [
'status' => 'failed',
'message' => 'Key string, IV string and login URL are required.',
];
}
// Plain SSO JSON payload, as per Medi Assist sample
$payload = [
'Id' => $emp_code,
'expiryTime' => time() + (10 * 60), // 10 minutes
'CPartnerId' => $planId,
];
$plainJson = json_encode($payload, JSON_UNESCAPED_SLASHES);
// Derive a 32byte key (AES256) and 16byte IV from the provided strings
// $key = substr(hash('sha256', $keyString, true), 0, 32);
// $iv = substr(hash('md5', $ivString, true), 0, 16);
// Encrypt with AES256CBC + PKCS7 padding (OpenSSL default)
$cipherTextRaw = openssl_encrypt($plainJson, $cipher_algorithm, $keyString, OPENSSL_RAW_DATA, $ivString);
if ($cipherTextRaw === false) {
log_message('error', 'MEDI_ASSIST - Wellness SSO URL generation | Encryption failed while generating Medi Assist wellness token.');
return [
'status' => 'failed',
'message' => 'Encryption failed while generating Medi Assist wellness token.',
];
}
// Base64 encode and URLencode for use as EncryptedSSO
$encryptedSSO = urlencode(base64_encode($cipherTextRaw));
// $encryptedSSO = rtrim(strtr(base64_encode($cipherTextRaw), '+/', '-_'), '=');
// Build the final login URL
$loginUrl = str_replace(['{0}', '{1}'], [$planId, $encryptedSSO], $loginUrlTemplate);
log_message('error', 'MEDI_ASSIST - Wellness SSO URL generation | Medi Assist wellness SSO URL generated successfully.');
return [
'status' => 'success',
'message' => 'Medi Assist wellness SSO URL generated successfully.',
'data' => $loginUrl
];
}

View File

@ -1304,4 +1304,74 @@ class TestingController extends BaseController
'data' => $list,
], 200);
}
/**
* Test Wellness SSO token generation for Medi Assist (MediBuddy).
*
* This uses the token-based authentication details shared by Medi Assist:
* - Cipher: AES-256-CBC
* - Padding: PKCS7 (OpenSSL default)
* - Login URL: https://login.mediassist.in/SSOLogon.aspx?PartnerCorpId={0}&EncryptedSSO={1}
*
* Environment variables (recommended):
* - MEDIASSIST_WELLNESS_KEY
* - MEDIASSIST_WELLNESS_IV
* - MEDIASSIST_WELLNESS_PARTNER_CORP_ID
* - MEDIASSIST_WELLNESS_LOGIN_URL
*
* If env values are not present, sensible dummy defaults are used so that
* the function can still be exercised.
*/
public function testMediAssistWellness()
{
// Configuration prefer environment variables, fall back to demo values
$keyString = env('MEDIASSIST_WELLNESS_KEY');
$ivString = env('MEDIASSIST_WELLNESS_IV');
$loginUrlTemplate = env('MEDIASSIST_WELLNESS_LOGIN_URL' );
$partnerCorpId = '15963';
$cipher_algorithm = 'AES-256-CBC';
// Plain SSO JSON payload, as per Medi Assist sample
$payload = [
'Id' => '15022',
'expiryTime' => time() + (10 * 60), // 10 minutes
'CPartnerId' => $partnerCorpId,
];
$plainJson = json_encode($payload, JSON_UNESCAPED_SLASHES);
// Derive a 32byte key (AES256) and 16byte IV from the provided strings
// $key = substr(hash('sha256', $keyString, true), 0, 32);
// $iv = substr(hash('md5', $ivString, true), 0, 16);
// Encrypt with AES256CBC + PKCS7 padding (OpenSSL default)
$cipherTextRaw = openssl_encrypt( $plainJson, $cipher_algorithm, $keyString, OPENSSL_RAW_DATA, $ivString);
if ($cipherTextRaw === false) {
return $this->respond([
'status' => false,
'message' => 'Encryption failed while generating Medi Assist wellness token.',
], 500);
}
// Base64 encode and URLencode for use as EncryptedSSO
$encryptedSSO = urlencode(base64_encode($cipherTextRaw));
// $encryptedSSO = rtrim(strtr(base64_encode($cipherTextRaw), '+/', '-_'), '=');
// Build the final login URL
$loginUrl = str_replace(['{0}', '{1}'], [$partnerCorpId, $encryptedSSO], $loginUrlTemplate);
return $this->respond([
'status' => true,
'message' => 'Medi Assist wellness test URL generated successfully.',
'data' => [
'loginUrl' => $loginUrl,
'encryptedSSO' => $encryptedSSO,
'plainPayload' => $payload,
],
], 200);
}
}