Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require_once('classes/class.smsquick.php');
- $username = "someuser";
- $password = "somepass";
- $api = new SmsQuick($username, $password);
- //uncommenting the line below returns undefined_index @ line 312 and 282
- //$available_credits = $api->checkBalance();
- //var_dump($api); //used for checking
- public function checkBalance() {
- $vars = array(
- 'username' => $this->api_username,
- 'password' => $this->api_password,
- 'action' => 'balance',
- );
- $retval = $this->executeApiRequest($vars);
- list(, $response) = array_values(reset($retval)); // line 282
- return (int) $response;
- }
- /**
- * Helper method to execute an API request.
- *
- * @param array $vars
- * Data to POST to SMS gateway API endpoint.
- *
- * @return array
- * Response from SMS gateway.
- */
- public function executeApiRequest($vars) {
- // Basic validation on the authentication details
- foreach ($vars as $key => $value) {
- switch ($key) {
- case 'username':
- case 'password':
- if (empty($value)) {
- throw new Exception('API username or password not specified.');
- }
- break;
- }
- }
- $data = $this->preparePostData($vars);
- $retval = $this->executePostRequest($data);
- list($status, $response) = explode(':', $retval); // line 312
- if ($status == 'ERROR') {
- throw new Exception(strtr('There was an error with this request: !error.', array('!error' => $response)));
- }
- $data = array();
- $lines = explode("n", $retval);
- foreach (array_filter($lines) as $i => $line) {
- $line = trim($line);
- $data[$i] = explode(':', $line);
- }
- return $data;
- }
- protected function preparePostData($data) {
- $post_data = array();
- foreach ($data as $key => $value) {
- switch ($key) {
- case 'to':
- // Support multiple phone numbers.
- $value = implode(',', array_unique($value));
- break;
- }
- $post_data[] = $key . '=' . rawurlencode($value);
- }
- return implode('&', $post_data);
- }
- protected function executePostRequest($data) {
- $ch = curl_init($this->api_endpoint);
- curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- $retval = curl_exec($ch);
- curl_close($ch);
- return $retval;
- }
- reset($retval);
- list(, $response) = array_values(reset($retval)); // line 282
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement