-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3d7c75
commit 0cdb4b6
Showing
1 changed file
with
78 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php | ||
/** | ||
* @package: oracleSoapApi | ||
* @link: https://github.com/feltkamptv/oraclechatapi/ | ||
* @developer: Feltkamp.tv Multimedia Productions | ||
* @email: [email protected] | ||
* @tel: +31 (0) 20 785 4487 | ||
|
@@ -32,6 +33,9 @@ public function __construct($wsdl, $username, $password, $appId, $sessionId, $in | |
$this->interfaceId = $interfaceId; | ||
$this->interfaceName = $interfaceName; | ||
$this->error = false; | ||
$this->error_curl = false; | ||
$this->httpcode = false; | ||
$this->retry = false; | ||
$this->clientTransactionID = 0; | ||
$this->chatSessionToken = false; | ||
$this->sitename = false; | ||
|
@@ -151,7 +155,25 @@ public function requestChat($phonenumber, $data){ | |
$this->setChatSessionToken($chat_soap['chat_token']); | ||
$request_chat = $this->call('RequestChat', $data); | ||
if($this->error){ | ||
//echo $this->error; | ||
return false; | ||
}else{ | ||
$request_chat = $this->parseResult('RequestChat', $request_chat); | ||
return $request_chat['session_id']; | ||
} | ||
}// end function | ||
|
||
/** | ||
* REQUEST CHAT ONLY | ||
* | ||
* This function will only perform the RequestChat SOAP API call. | ||
* | ||
* @param string $phonenumber, array $data | ||
* | ||
* @return: string $session_id on success, false on failure | ||
**/ | ||
public function requestChatOnly($phonenumber, $data){ | ||
$request_chat = $this->call('RequestChat', $data); | ||
if($this->error){ | ||
return false; | ||
}else{ | ||
$request_chat = $this->parseResult('RequestChat', $request_chat); | ||
|
@@ -186,11 +208,32 @@ public function resumeChat($phonenumber, $data){ | |
* | ||
* @param string $msg | ||
* | ||
* @return: true | ||
* @return: boolean | ||
**/ | ||
public function sendMsg($msg){ | ||
$post_message = $this->call('PostChatMessage', array('Body'=>$msg)); | ||
return true; | ||
if(!$post_message){ | ||
return false; | ||
}else{ | ||
return true; | ||
} | ||
}// end function | ||
|
||
/** | ||
* CHECK ACTIVE CHAT | ||
* | ||
* This function will check if a chat is still active and available. | ||
* | ||
* @return: boolean | ||
**/ | ||
public function checkActiveChat(){ | ||
$post = array('Mode'=>'LISTENING'); | ||
$post_message = $this->call('SendActivityChange', $post); | ||
if(!$post_message){ | ||
return false; | ||
}else{ | ||
return true; | ||
} | ||
}// end function | ||
|
||
/** | ||
|
@@ -200,7 +243,7 @@ public function sendMsg($msg){ | |
* | ||
* @param boolean $typing | ||
* | ||
* @return: true | ||
* @return: boolean | ||
**/ | ||
public function setTypingMessage($typing){ | ||
if($typing){ | ||
|
@@ -209,7 +252,11 @@ public function setTypingMessage($typing){ | |
$post = array('Mode'=>'LISTENING'); | ||
} | ||
$post_message = $this->call('SendActivityChange', $post); | ||
return true; | ||
if(!$post_message){ | ||
return false; | ||
}else{ | ||
return true; | ||
} | ||
}// end function | ||
|
||
/** | ||
|
@@ -292,6 +339,9 @@ public function getSoapRequest($action, $params){ | |
} | ||
if(array_key_exists('LastName', $params['CustomerInformation'])){ | ||
$raw_xml .= '<v1:LastName>'.$params['CustomerInformation']['LastName'].'</v1:LastName>'; | ||
} | ||
if(array_key_exists('ContactID', $params['CustomerInformation'])){ | ||
$raw_xml .= '<v1:ContactID id="'.$params['CustomerInformation']['ContactID'].'"/>'; | ||
} | ||
$raw_xml .= '<v1:InterfaceID><v1:ID id="'.$this->interfaceId.'"/><v1:Name>'.$this->interfaceName.'</v1:Name></v1:InterfaceID>'; | ||
$raw_xml .= '</v11:CustomerInformation>'; | ||
|
@@ -320,7 +370,7 @@ public function getSoapRequest($action, $params){ | |
|
||
case 'SendActivityChange': | ||
$raw_xml .= '<v11:SendActivityChange>'.$this->getTransactionRequestData(); | ||
$raw_xml .= '<v11:Mode>'.$params['Mode'].'</v11:Body></v11:SendActivityChange>'; | ||
$raw_xml .= '<v11:Mode>'.$params['Mode'].'</v11:Mode></v11:SendActivityChange>'; | ||
break; | ||
|
||
case 'GetChatOperatingHours': | ||
|
@@ -427,6 +477,7 @@ public function parseResult($action, $response){ | |
**/ | ||
public function call($action, $params, $request = false){ | ||
$this->error = false; | ||
$this->error_curl = false; | ||
if(!$request){ | ||
$this->request = $this->getSoapRequest($action, $params); | ||
}else{ | ||
|
@@ -447,17 +498,27 @@ public function call($action, $params, $request = false){ | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($ch, CURLOPT_URL, $this->wsdl); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_TIMEOUT, 10); | ||
curl_setopt($ch, CURLOPT_TIMEOUT, 20); | ||
curl_setopt($ch, CURLOPT_POST, true); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | ||
|
||
$response = curl_exec($ch); | ||
if(!$response){ | ||
$this->error_curl = curl_error($ch); | ||
} | ||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | ||
curl_close($ch); | ||
if($http_code == 200){ | ||
$this->retry = false; | ||
return $this->decodeGzip($response); | ||
}elseif(empty($http_code) && !$this->retry){ | ||
$this->retry = true; | ||
sleep(500000); | ||
return $this->call($action, $params, $request); | ||
}else{ | ||
$this->retry = false; | ||
$this->httpcode = $http_code; | ||
$this->error = $this->decodeGzip($response); | ||
return false; | ||
} | ||
|
@@ -481,4 +542,14 @@ public function decodeGzip($response){ | |
} | ||
}// end function | ||
|
||
/** | ||
* GET ERROR | ||
* | ||
* This function will return the error output. | ||
* | ||
* @return: string | ||
**/ | ||
public function getError(){ | ||
return $this->error; | ||
}// end function | ||
}// end class |