SmsController.php
3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?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;
}
}