-
Notifications
You must be signed in to change notification settings - Fork 0
/
CallstatusAction.php
executable file
·111 lines (81 loc) · 3.18 KB
/
CallstatusAction.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/*
* Callstatus Action calss.
* @author Sunil
* To check the status of the call.
*/
class CallstatusAction extends CAction{
public $response_array = array();
public $curl_call_result;
public $curl_call_http_code;
public $curl_call_error_code;
private $listingid;
public function run(){
try{
Yii::app()->session->open();
$controller = $this->getController();
if(isset($_POST['listingid'])){
$this->listingid = $_POST['listingid'];
}
if(isset($_POST['userid'])){
$responseid = $_POST['sid'];
$userid = $_POST['userid'];
$mobileno = $_POST['mobileno'];
$userRedis = new UserRedis();
$listingInfo = $userRedis->getListingDetails($this->listingid,'sellerinfo');
$listing_array = json_decode($listingInfo,TRUE);
$userInfo = $userRedis->getUserinfo($userid);
$user_array = json_decode($userInfo,TRUE);
//$user_array['mobile'] = $mobileno;
$exotel_url = "https://". Yii::app()->params['exotel_sid'] .":". Yii::app()->params['exotel_token'] ."@twilix.exotel.in/v1/Accounts/". Yii::app()->params['exotel_sid'] ."/Calls/".$responseid;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $exotel_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$curl_call_result = curl_exec($ch);
$curl_call_error_code = curl_error($ch);
$curl_call_http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE);
curl_close($ch);
if ($curl_call_error_code) {
$html = $controller->renderPartial('_call_disconnected_form',array(),TRUE);
$response_array = array ('status' => 'Failure',
'http_code' => $curl_call_http_code,
'error_code'=> $curl_call_error_code,
'html' => $html
);
return json_encode ( $response_array );
}else{
if($curl_call_http_code == '200'){
$call_details = simplexml_load_string ( $curl_call_result );
$call_details = json_encode($call_details);
$call_details = json_decode($call_details,TRUE);
$call_status = $call_details['Call']['Status'];
$call_sid = $call_details['Call']['Sid'];
$call_from = $call_details['Call']['From'];
$call_to = $call_details['Call']['To'];
if(isset(Yii::app()->request->cookies['cookie_id'])){
$cookieid = Yii::app()->request->cookies['cookie_id'];
$userRedis->setUserContacted($cookieid,$this->listingid);
}
$html = $controller->renderPartial('_call_disconnected_form',array('listing_array'=>$listing_array,'user'=>$user_array,'mobileno'=>$mobileno),TRUE);
$response_array = array ('status' => 'Sucess',
'call_Status' => $call_status,
'call_Sid' => $call_sid,
'html' => $html,
'url' => $controller->createUrl('contactseller/sendemail'),
'listingid' => $this->listingid,
'userid' => $userid,
'mobileno' => $mobileno
);
echo json_encode($response_array);
}
}
}
}catch ( Exception $e ) {
echo 'Caught exception: ', $e->getMessage (), "\n";
exit();
}
}
}
?>