SmsController.php 3.02 KB
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Auth;
use Log;
use DB;
class SmsController extends Controller
{
	public $smsUrl = 'https://10.2.55.165:443/servlet/com.aclwireless.pushconnectivity.listeners.TextListener?';
	//public $userarray = array("A21568","admin");
    	public function sendSmsBasedOnSubDisposition($kstychCall)
    	{
			$msgText = $this->getSmsTemplate($kstychCall);
			if( !empty($msgText) ) {
	  			$msgText = $this->fillValuesInTemplate($msgText);
			//Log::info($msgText);
	  			$this->sendSmsRequest($kstychCall, $msgText);
			}
	//}
		return;
	}
	public function sendSmsRequest($kstychCall, $msgText)
	{
		$url = $this->smsUrl;
		$inputArray = [
			'userId'=>'hdfcbalrt',
			"pass"=>'hdfcbalrt25',
			"appid"=>"hdfcbalrt",
			"subappid"=>"hdfcbalrt",
			"contenttype"=>"1",
			"to"=>$kstychCall['callnumber'],
			"from"=>"HDFCBK",
			"text"=>$msgText,
			"selfid"=>"true",
			"alert"=>"1",
			"dlrreq"=>"true",
			"intflag"=>"false"
		];
		$query = http_build_query($inputArray);
		$url .= $query;
		try{
			$ch = curl_init(); 
			curl_setopt($ch, CURLOPT_URL, $url); 
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
			$response = curl_exec($ch);

            $number=$kstychCall['callnumber'];
            $callid=intval($kstychCall['callid'])+0;
            $serverip=env(app_ip);
            $rmname=Auth::user()->fullname;
            $subdispo=$kstychCall["usersubstatus"];

            DB::insert(DB::raw("insert into sms_log set server_ip='$serverip',call_id='$callid',rm_name='$rmname',subdispo='$subdispo',number='$number',message='$msgText',response='$response'"));

            Log::useFiles(storage_path().'/logs/SMS_Messages_'.date("Y-m-d").'.log');
            Log::info('|'.env(app_ip).'|'.date('Y-m-d H:i:s', strtotime('+5 hours 30 minutes')).'|'.Auth::user()->fullname.'|'.$kstychCall['callnumber'].'|"'.$msgText.'"|'.$response.'|');

            curl_close($ch);
		} catch(Exception $e) {
			Log::info($e->getMessage());
		}
	}
	public function getSmsTemplate($kstychCall)
	{
		$msgText = "";
		include( app_path() . '/Constants/SmsTemplate.php');
		if( in_array( $kstychCall["usersubstatus"] , $smsContactedSubdispositionsArr) ) {
			$msgText = $smsTemplatesArr[SMS_THANKYOU];
		} else if( in_array( $kstychCall["usersubstatus"] , $smsNotContactedSubdispositionsArr) ) {
			$msgText = $smsTemplatesArr[SMS_NOTCONTACTED];
		}
  		return $msgText;
	}
	public function fillValuesInTemplate($msgText)
	{
		if( !empty($msgText) )
  		{
  			$msgText = str_replace("#name#", Auth::user()->fullname, $msgText);
  			//$msgText = str_replace("#number#", explode(":", Auth::user()->exten)[0], $msgText);
			$exten = '';
  			$extension = Auth::user()->exten;
  			if(!empty($extension))
  			{
  				$extenArr = explode(":", $extension);
  				$exten = $extenArr[0];
  			}
  			//Log::info($exten);

  			$msgText = str_replace("#number#", $exten, $msgText);
  			$msgText = str_replace("#date#", date('d-m-Y'), $msgText);
  		}
		return $msgText;
	}
}