TWLIO API

This commit is contained in:
Velz2020 2020-09-15 23:54:11 +05:30
parent 0c6893de6f
commit c69f3d9068
6 changed files with 131 additions and 19 deletions

View File

@ -94,6 +94,7 @@ defined('ROUTE_LOGIN_W') OR define('ROUTE_LOGIN_W', 'saveSalesPDImage');
defined('ROUTE_LOGIN_V') OR define('ROUTE_LOGIN_V', 'generateSatelliteImg'); // no errors
defined('ROUTE_LOGIN_A') OR define('ROUTE_LOGIN_A', 'getAuditedImages'); // no errors
defined('TURN_SERVER_API') OR define('TURN_SERVER_API', 'getServerInfo'); // no errors
defined('VIDEO_CHAT_ACCESS_KEY_API') OR define('VIDEO_CHAT_ACCESS_KEY_API', 'getVideoChatAccessKey'); // no errors
//defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN','getFullPDDetails'); // no errors
/*********************AWS resources Constants*************************************************/
@ -142,6 +143,12 @@ else if(ENVIRONMENT == 'production')
/*********************END of AWS resources Constants*************************************************/
/*************************TWILO CONSTANTS************************************************************/
defined('TWLIO_SID') OR define('TWLIO_SID','AC01bf87391506e1df7e05cbe3d015bf81');
defined('TWLIO_AUTH_TOKEN') OR define('TWLIO_AUTH_TOKEN','470de1016b533c390703c40c7fea474b');
/*************************END OF TWILO CONSTANTS************************************************************/
defined('PROCESSJSON') OR define('PROCESSJSON',1);

View File

@ -85,6 +85,7 @@ $route['getCustomerSegment'] = 'Common_Masters_Controller/getCustomerSegment';
$route['(checkAppVersion/:any)'] = 'Common_Masters_Controller/checkAppVersion';
$route['getCommonConfig'] = 'Common_Masters_Controller/getCommonConfig';
$route['getServerInfo'] = 'Common_Masters_Controller/getServerInfo';
$route['getVideoChatAccessKey'] = 'Common_Masters_Controller/getVideoChatAccessKey';

View File

@ -1228,4 +1228,48 @@ class Common_Masters_Controller extends REST_Controller {
}
}
public function getVideoChatAccessKey_post()
{
$pd_id = $this->post('pd_id');
$random_key = $this->post('random_key');
$user_type = $this->post('user_type');
//echo $pd_id,$random_key,$user_type;
$this->load->library('Twlio');
$apiKeySecret = $this->twlio->getAPIKey();
//echo $d;
//if get API key sucessfully from twlio
if($apiKeySecret)
{
$roomName = $random_key.$pd_id;
$officerName = $user_type == 'PDOFFICER' ? 'PDOFFICER' : 'CUTOMER';
$videoAccessToken = $this->twlio->getVideoAccessJWTToken($apiKeySecret,$roomName,$officerName);
if($videoAccessToken)
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['records'] = $videoAccessToken;
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_INTERNAL_SERVER_ERROR;
$data['msg'] = 'Couldn`t get access Token from Twlio ';
$this->response($data,REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
}
}
else
{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_INTERNAL_SERVER_ERROR;
$data['msg'] = ' Couldn`t get API secret Key from Twlio ';
$this->response($data,REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -72,7 +72,7 @@ class AUTHORIZATION
}
if( $routingName == ROUTE_LOGIN_X || $routingName == ROUTE_LOGIN_Y || $routingName == ROUTE_LOGIN_Z || $routingName == ROUTE_LOGIN_W || $routingName == ROUTE_LOGIN_V || $routingName == ROUTE_LOGIN_A || $routingName == TURN_SERVER_API)
if( $routingName == ROUTE_LOGIN_X || $routingName == ROUTE_LOGIN_Y || $routingName == ROUTE_LOGIN_Z || $routingName == ROUTE_LOGIN_W || $routingName == ROUTE_LOGIN_V || $routingName == ROUTE_LOGIN_A || $routingName == TURN_SERVER_API || $routingName == VIDEO_CHAT_ACCESS_KEY_API)
{
return true;
}

View File

@ -3,26 +3,15 @@
include_once APPPATH.'/vendor/autoload.php';
//define('DOMPDF_ENABLE_AUTOLOAD', false);
//include_once APPPATH.'/vendor/dompdf/dompdf/src/autoloader.php';
//require_once APPPATH.'/vendor/dompdf/dompdf/src/autoloader.php';
// require_once APPPATH.'/vendor/dompdf/dompdf/lib/html5lib/Parser.php';
// //require_once APPPATH.'/vendor/dompdf/dompdf/lib/php-font-lib/src/FontLib/Autoloader.php';
// //require_once APPPATH.'/vendor/dompdf/dompdf/lib/php-svg-lib/src/autoload.php';
// require_once APPPATH.'/vendor/dompdf/dompdf/src/Autoloader.php';
// require_once APPPATH.'/vendor/dompdf/dompdf/src/Dompdf.php';
// require_once APPPATH.'/vendor/dompdf/dompdf/src/Adapter/CPDF.php';
// Dompdf\Autoloader::register();
use Twilio\Rest\Client;
use Twilio\Jwt\AccessToken;
use Twilio\Jwt\Grants\VideoGrant;
class Twlio
{
function getServerInfo($print = false,$json = false)
{
$sid = "AC01bf87391506e1df7e05cbe3d015bf81";
$token = "470de1016b533c390703c40c7fea474b";
$twilio = new Client($sid, $token);
$twilio = new Client(TWLIO_SID, TWLIO_AUTH_TOKEN);
$token = $twilio->tokens
->create();
$response_data = array();
@ -44,7 +33,78 @@ class Twlio
return json_encode($response_data,true);
}
}
function getAPIKey($print = false,$json = false)
{
$twilio = new Client(TWLIO_SID, TWLIO_AUTH_TOKEN);
$new_key = $twilio->newKeys->create();
return $new_key->secret;
// print_r($new_key->dateCreated);
// print_r($new_key->secret);
// print_r($new_key->friendyName);
// try
// {
// if(is_object($new_key) && property_exists($new_key, 'secret'))
// {
// return $new_key->secret;
// }
// else
// {
// throw new Exception("Couldn't get API Key from Twlio", 1);
// }
// }
// catch(Exception $e)
// {
// // print_r($e->getMessage());
// $data['dataStatus'] = false;
// $data['status'] = REST_Controller::HTTP_INTERNAL_SERVER_ERROR;
// $data['msg'] = $e->getMessage();
// $this->response($data,REST_Controller::HTTP_OK);
// }
}
function getVideoAccessJWTToken($apiKeySecret,$roomName,$officerName)
{
// Required for all Twilio access tokens
$twilioAccountSid = TWLIO_SID;
$twilioApiKey = TWLIO_AUTH_TOKEN;
$twilioApiSecret = $apiKeySecret;
// Required for Video grant
$roomName = $roomName;
// An identifier for your app - can be anything you'd like
$identity = $officerName;
// Create access token, which we will serialize and send to the client
$token = new AccessToken(
$twilioAccountSid,
$twilioApiKey,
$twilioApiSecret,
3600,
$identity
);
// Create Video grant
$videoGrant = new VideoGrant();
$videoGrant->setRoom($roomName);
// Add grant to token
$token->addGrant($videoGrant);
// render token to string
return $token->toJWT();
}
}

View File

@ -653,7 +653,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
if(count($person_met_data))
{
echo '<p><strong>Person(s) Met:</strong> </p>';
echo '<p><strong>Person Contacted:</strong> </p>';
echo '<div style="border: 1px solid #0191ed;">';
foreach($person_met_data as $pk => $person)
@ -1158,7 +1158,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
echo $employeement_data['total_business_previous_experience'] ? ("<p>Previously, applicant ".$employeement_data['total_business_previous_experience']) : '';
//echo $employeement_data['was_met'] == 'no'? "<p>No one was met at the visited premises who could confirm the employment details of loan applicant. </p>":"<p>During PD visit, ".$employeement_data['name_person_met'].' ( '. ($employeement_data['others_person_met'] ? $employeement_data['others_person_met'] : $employeement_data['designation_person_met_master']) .' ) was met at the visited premises.';
echo $employeement_data['was_met'] == 'no'? "<p>No one was met at the visited premises who could confirm the employment details of loan applicant. </p>":"<p>During PD, ".$employeement_data['name_person_met'].' ( '. ($employeement_data['others_person_met'] ? $employeement_data['others_person_met'] : $employeement_data['designation_person_met_master']) .' ) was contacted for Tele PD.';
echo ($employeement_data['confirm_salary'] == 'no'? '<p>Salary amount was not confirmed because '.$employeement_data['sal_amount_was_not_confirmed'].' </p>' : '<p>Salary amount confirmed by person contacted is '.$rupee_symbol.' '.MYUTIL::customIndianNumberFormat($employeement_data['confirm_salary_amount']).'.</p>');
@ -1190,7 +1190,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
echo $employeement_data['check_validated'] == "not validated" ? "<p>The salary amount was not validated because ".$employeement_data['why_was_it_not_validated']."</p>": "<p>The salary amount was validated ".$employeement_data['how_was_it_validated']."</p>";
echo $employeement_data['any_delays'] == 'yes' ? '<p>As per person met, sometimes there is delay in salary payment.</p>' : '<p>Generally, there is no delay in salary payment.</p>';
echo $employeement_data['any_delays'] == 'yes' ? '<p>As per person contacted, sometimes there is delay in salary payment.</p>' : '<p>Generally, there is no delay in salary payment.</p>';
echo $employeement_data['bonus_incentive'] ? "<p>The applicant receives a bonus ( ".($employeement_data['bonus_type'] == 'others' ? $employeement_data['bonus_type_other']: $employeement_data['bonus_type']).") of ".$rupee_symbol." ".MYUTIL::customIndianNumberFormat($employeement_data['bonus_incentive'])." ".$employeement_data['bonus_frequency_master'].'.</p>': '<p>Applicant does not get any Bonus amount or Incentives.</p>';