SmsController.php 2.75 KB
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Auth;
use Log;
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)
    	{
		//$users = $this->userarray;
		//if(in_array(Auth::user()->username , $users)){
			$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;
		Log::info($kstychCall['callnumber']);
		$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);
		       	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,3);	
			$response = curl_exec($ch); 
			Log::useFiles(storage_path().'/logs/SMS_Messages'.date("Y-m-d").'.log');
			Log::info("|".date('Y-m-d H:i:s', strtotime('+5 hours 30 minutes'))."|".Auth::user()->fullname."|".$kstychCall['callnumber']."|".$msgText."|".$response);
			//Log::info($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;
	}
}