コード例 #1
0
 /**
  * Sends out email via Mandrill
  *
  * @return array Return the Mandrill
  */
 public function send(CakeEmail $email)
 {
     // CakeEmail
     $this->_cakeEmail = $email;
     $this->_config = $this->_cakeEmail->config();
     $this->_headers = $this->_cakeEmail->getHeaders(array('from', 'to', 'cc', 'bcc', 'replyTo', 'subject'));
     // Setup connection
     $this->__mandrillConnection =& new HttpSocket();
     // Build message
     $message = $this->__buildMessage();
     // Build request
     $request = $this->__buildRequest();
     if (isset($this->_config['mandrillTemplate']) && !empty($this->_config['mandrillTemplate'])) {
         $message_send_uri = $this->_config['uri'] . "messages/send-template.json";
     } else {
         $message_send_uri = $this->_config['uri'] . "messages/send.json";
     }
     // Send message
     try {
         $returnMandrill = $this->__mandrillConnection->post($message_send_uri, json_encode($message), $request);
         // Return data
         $result = json_decode($returnMandrill, true);
         $headers = $this->_headersToString($this->_headers);
         return array_merge(array('Mandrill' => $result), array('headers' => $headers, 'message' => $message));
     } catch (Exception $e) {
         return false;
     }
 }
コード例 #2
0
 /**
  * Method of API
  *
  * @return HttpSocketResponse
  */
 public function api()
 {
     $args = func_get_args();
     $url = implode('/', array(self::URL, 'api', array_shift($args))) . ".json";
     do {
         $data = array_merge($this->settings, array_shift($args));
     } while ($args);
     return $this->http->post($url, $data);
 }
 public function wpp_hash($method = null, $nvp = null)
 {
     $HttpSocket = new HttpSocket();
     $required_nvp = 'METHOD=' . $method;
     $required_nvp .= '&VERSION=' . Configure::read('Paypal.version');
     $required_nvp .= '&USER='******'Paypal.username');
     $required_nvp .= '&PWD=' . Configure::read('Paypal.password');
     $required_nvp .= '&SIGNATURE=' . Configure::read('Paypal.signature');
     debug($required_nvp);
     die;
     $http_responder = $HttpSocket->post(Configure::read('Paypal.endpoint'), $required_nvp . $nvp);
     if (!$http_responder) {
         throw new BadRequestException($method . 'failed: ' . $http_responder['reasonPhrase']);
     }
     $responder = explode('&', $http_responder);
     $parsed_response = array();
     foreach ($responder as $response) {
         $response_array = explode('=', $response);
         if (count($response_array) >= 1) {
             $parsed_response[$response_array[0]] = urldecode($response_array[1]);
         }
     }
     if (count($parsed_response) < 1 || !array_key_exists('ACK', $parsed_response)) {
         throw new BadRequestException('Invalid HTTP Response for POST request (' . $required_nvp . $nvp . ') to ' . Configure::read('Paypal.endpoint'));
     }
     return $parsed_response;
 }
コード例 #4
0
 function sendSMS($phone, $message)
 {
     App::uses('HttpSocket', 'Network/Http');
     $HttpSocket = new HttpSocket();
     $results = $HttpSocket->post('http://www.mobileautomatedsystems.com/components/com_spc/smsapi.php', array('username' => 'noibilism', 'password' => 'noheeb', 'sender' => 'ZEO Ifo', 'recipient' => $phone, 'message' => $message));
     return $results;
 }
コード例 #5
0
ファイル: google_translate.php プロジェクト: real34/i18n
 /**
  * Wrapper for calling the remote API
  * 
  * @throws RuntimeException When an error is returned by Google
  * @return HttpSocket instance
  */
 protected function _doCall($uri, $query)
 {
     $result = false;
     if (!is_a($this->Http, 'HttpSocket')) {
         App::import('Core', 'HttpSocket');
         $this->Http = new HttpSocket();
     }
     $query['v'] = $this->__version;
     if ($this->useUserIp) {
         App::import('Component', 'RequestHandler');
         $RequestHandler = new RequestHandlerComponent();
         $query['userip'] = $RequestHandler->getClientIP();
     }
     if (!is_null($this->key)) {
         $query['key'] = $this->key;
     }
     $response = $this->Http->post($uri, $query);
     if ($this->Http->response['status']['code'] == 200) {
         $response = json_decode($response, true);
         if ($response['responseStatus'] != 200) {
             throw new RuntimeException($response['responseDetails']);
         }
         $result = $response['responseData'];
     }
     return $result;
 }
コード例 #6
0
 function sendSMS($phone, $message)
 {
     App::uses('HttpSocket', 'Network/Http');
     $HttpSocket = new HttpSocket();
     $results = $HttpSocket->post('http://mobileautomatedsystems.com/index.php?option=com_spc&comm=spc_api', array('username' => 'noibilism', 'password' => 'noheeb', 'sender' => 'NASFAT', 'recipient' => $phone, 'message' => $message));
     return $results;
 }
コード例 #7
0
ファイル: correios.php プロジェクト: n0n3br/SGD
 function endereco(&$model, $cep)
 {
     if (!$this->_validaCep($cep, '-')) {
         return ERRO_CORREIOS_PARAMETROS_INVALIDOS;
     }
     // Requisição
     $HttpSocket = new HttpSocket();
     $uri = array('scheme' => 'http', 'host' => 'www.correios.com.br', 'port' => 80, 'path' => '/encomendas/prazo/prazo.cfm');
     $data = array('resposta' => 'paginaCorreios', 'servico' => CORREIOS_SEDEX, 'cepOrigem' => $cep, 'cepDestino' => $cep, 'peso' => 1, 'MaoPropria' => 'N', 'valorDeclarado' => 0, 'avisoRecebimento' => 'N', 'Altura' => '', 'Comprimento' => '', 'Diametro' => '', 'Formato' => 1, 'Largura' => '', 'embalagem' => 116600055, 'valorD' => '');
     $retornoCorreios = $HttpSocket->post($uri, $data);
     if ($HttpSocket->response['status']['code'] != 200) {
         return ERRO_CORREIOS_FALHA_COMUNICACAO;
     }
     // Convertendo para o encoding da aplicação. Isto só funciona se a extensão multibyte estiver ativa
     $encoding = Configure::read('App.encoding');
     if (function_exists('mb_convert_encoding') && $encoding != null && strcasecmp($encoding, 'iso-8859-1') != 0) {
         $retornoCorreios = mb_convert_encoding($retornoCorreios, $encoding, 'ISO-8859-1');
     }
     // Checar se o conteúdo está lá e reduzir o escopo de busca dos valores
     if (!preg_match('/\\<b\\>CEP:\\<\\/b\\>(.*)\\<b\\>Prazo de Entrega/', $retornoCorreios, $matches)) {
         return ERRO_CORREIOS_CONTEUDO_INVALIDO;
     }
     $escopoReduzido = $matches[1];
     // Logradouro
     preg_match('/\\<b\\>Endere&ccedil;o:\\<\\/b\\>\\s*\\<\\/td\\>\\s*\\<td[^\\>]*>([^\\<]*)\\</', $escopoReduzido, $matches);
     $logradouro = $matches[1];
     // Bairro
     preg_match('/\\<b\\>Bairro:\\<\\/b\\>\\s*\\<\\/td\\>\\s*\\<td[^\\>]*>([^\\<]*)\\</', $escopoReduzido, $matches);
     $bairro = $matches[1];
     // Cidade e Estado
     preg_match('/\\<b\\>Cidade\\/UF:\\<\\/b\\>\\s*\\<\\/td\\>\\s*\\<td[^\\>]*>([^\\<]*)\\</', $escopoReduzido, $matches);
     list($cidade, $uf) = explode('/', $matches[1]);
     return compact('logradouro', 'bairro', 'cidade', 'uf');
 }
コード例 #8
0
ファイル: MetatagShell.php プロジェクト: luizjam/docs
 /**
  * Reads all the files in a directory and process them to extract the description terms
  *
  * @return void
  */
 public function main()
 {
     $url = 'http://search.yahooapis.com/ContentAnalysisService/V1/termExtraction';
     $dir = $this->in('Please input the full path to the documentation folder (including the language directory)');
     if (!is_dir($dir) && !is_file($dir . DS . 'index.rst')) {
         throw new Exception('Invalid directory, please input the full path to one of the language directories for the docs repo');
     }
     $files = new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)), '/\\.rst$/');
     foreach ($files as $item) {
         if ($item->isDir()) {
             continue;
         }
         $request = new HttpSocket();
         $content = file($item->getRealPath());
         $data = array('appid' => 'rrLaMQjV34HtIOsgPxf597DEP9KFoUzWybkmb4USJMPA89aCMWjjPFlnF3lD5ys-', 'query' => 'cakephp ' . $content[0], 'output' => 'json', 'context' => file_get_contents($item->getRealPath()));
         $result = $request->post('http://search.yahooapis.com/ContentAnalysisService/V1/termExtraction', $data);
         $keywords = json_decode($result->body);
         $keywords = $keywords->ResultSet->Result;
         $meta = $this->generateMeta($keywords, str_replace("\n", '', $content[0]));
         $fh = fopen($item->getRealPath(), 'a');
         fwrite($fh, "\n\n" . $meta);
         fclose($fh);
         $this->out('<success>Processed</success> ' . $item->getRealPath());
     }
 }
コード例 #9
0
 public function testPostViaSocket()
 {
     $url = 'https://www.sofort.com/payment/notAvailable';
     $SofortLibHttpSocket = new HttpSocket($url);
     $SofortLibHttpSocket->post('test');
     $httpCode = $SofortLibHttpSocket->getHttpCode();
     $this->assertTrue($httpCode['code'] === 404);
     $this->assertTrue($httpCode['message'] === '<errors><error><code>0404</code><message>URL not found ' . $url . '</message></error></errors>');
 }
コード例 #10
0
 /**
  * Makes an HTTP request using HttpSocket.
  *
  * @param string $url The URL to make the request to
  * @param array $params The parameters to use for the POST body
  * @param CurlHandler $ch Initialized curl handle. (Hopefully this is never used...)
  *
  * @return string The response text
  */
 protected function makeRequest($url, $params, $ch = null)
 {
     App::import('Core', 'HttpSocket');
     $HttpSocket = new HttpSocket();
     $result = $HttpSocket->post($url, $params);
     if ($result === false || $HttpSocket->response['status']['code'] != '200') {
         $execption = new FacebookApiException(array('error_code' => $HttpSocket->response['status']['code'], 'error' => array('message' => $HttpSocket->response['status']['reason-phrase'], 'type' => 'HttpSocketException')));
         throw $execption;
     }
     return $result;
 }
コード例 #11
0
ファイル: ClientController.php プロジェクト: trice4/BlogTest
 public function request_add()
 {
     $link = Router::url('/', true) . 'rest_posts.json';
     $data = null;
     $httpSocket = new HttpSocket();
     $data['Post']['title'] = 'New Post Title';
     $data['Post']['body'] = 'New Post Body';
     $response = $httpSocket->post($link, $data);
     $this->set('response_code', $response->code);
     $this->set('response_body', $response->body);
     $this->render('/Client/request_response');
 }
コード例 #12
0
 /**
  * Posts the data to the postmark API endpoint
  *
  * @return array
  * @throws CakeException
  */
 protected function _postageappSend()
 {
     $this->_generateSocket();
     $request = array('header' => array('Accept' => 'application/json', 'Content-Type' => 'application/json'));
     $data = array('api_key' => $this->_config['apiKey'], 'uid' => String::uuid(), 'arguments' => $this->_data);
     $return = $this->_socket->post($this->_apiUri, json_encode($data), $request);
     $response = json_decode($return);
     if ($this->_socket->response->code != '200') {
         throw new CakeException($response->response->message);
     }
     $this->_content = array('headers' => array(), 'message' => $this->_data, 'response' => $response);
 }
コード例 #13
0
ファイル: Feedback.php プロジェクト: port80labs/Boxmeup
 /**
  * Creates a github issue with title and body in configured project.
  *
  * @param string $title
  * @param string $body
  * @throws BadRequestException
  */
 public function githubIssue($type, $title, $body)
 {
     $socket = new HttpSocket();
     $url = static::GITHUB_URL . '/repos/' . Configure::read('Feedback.github.project') . '/issues';
     $data = json_encode(array('title' => $title, 'body' => $body, 'labels' => array_merge(array($type), Configure::read('Feedback.github.labels'))));
     $result = $socket->post($url, $data, array('header' => array('Authorization' => 'token ' . Configure::read('Feedback.github.auth_token'))));
     if (!in_array((int) $result->code, array(200, 201, 202, 203, 204, 205, 206))) {
         throw new BadRequestException('Error entering feedback.');
     }
     $body = json_decode($result->body, true);
     return $body['html_url'];
 }
コード例 #14
0
 public function request_login()
 {
     // remotely post the information to the server
     $link = "http://" . $_SERVER['HTTP_HOST'] . $this->webroot . 'users.json';
     $data = null;
     $httpSocket = new HttpSocket();
     $data['User']['username'] = '******';
     $data['User']['password'] = '******';
     $response = $httpSocket->post($link, $data);
     $this->set('response_code', $response->code);
     $this->set('response_body', $response->body);
     $this->render('/Client/request_response');
 }
コード例 #15
0
 /**
  * Sends out email via Mandrill
  *
  * @param $email
  * @return array Return the Mandrill
  */
 public function send(CakeEmail $email)
 {
     //todo:check restricted_emails
     $this->_cakeEmail = $email;
     $this->_config = $this->_cakeEmail->config();
     $this->_headers = $this->_cakeEmail->getHeaders(array('from', 'to', 'cc', 'bcc', 'replyTo', 'subject'));
     // Setup connection
     $this->__mandrillConnection =& new HttpSocket();
     $message = $this->__buildMessage();
     $request = array('header' => array('Accept' => 'application/json', 'Content-Type' => 'application/json'));
     if ($this->_cakeEmail->template()['template']) {
         $message_send_uri = $this->_config['uri'] . "messages/send-template.json";
     } else {
         $message_send_uri = $this->_config['uri'] . "messages/send.json";
     }
     //perform the http connection
     $returnMandrill = $this->__mandrillConnection->post($message_send_uri, json_encode($message), $request);
     //parse mandrill results
     $result = json_decode($returnMandrill, true);
     $headers = $this->_headersToString($this->_headers);
     return array_merge(array('Mandrill' => $result), array('headers' => $headers, 'message' => $message));
 }
コード例 #16
0
 public function add()
 {
     // remotely post the information to the server
     $link = "http://" . $_SERVER['HTTP_HOST'] . $this->webroot . 'posts.json';
     $data = null;
     $data['Post']['title'] = "this is new title";
     $data['Post']['content'] = "this is new content";
     $httpSocket = new HttpSocket();
     $response = $httpSocket->post($link, $data);
     $this->set('response_code', $response->code);
     $this->set('response_body', $response->body);
     $this->set('link', $link);
     $this->render('/client/request_response');
 }
コード例 #17
0
 /**
  * HTTP上で要求の送信
  * @param string $url
  * @param array $data
  * @param string $type
  */
 private function sendRequest($url, $data, $type = 'post')
 {
     $http = new HttpSocket();
     if ($type == 'post') {
         $response = $http->post($url, $data);
     } else {
         if ($type == 'get') {
             $response = $http->get($url, $data);
         } elseif ($type == 'delete') {
             $response = $http->delete($url, $data);
         }
     }
     return json_decode($response->body);
 }
コード例 #18
0
 public function request_add()
 {
     // remotely post the information to the server
     $link = "http://" . $_SERVER['HTTP_HOST'] . $this->webroot . 'rest_tasks.json';
     $data = null;
     $httpSocket = new HttpSocket();
     $data['Task']['name'] = 'New Phone';
     $data['Task']['priority'] = '10';
     $data['Task']['description'] = 'New Phone Description';
     $response = $httpSocket->post($link, $data);
     $this->set('response_code', $response->code);
     $this->set('response_body', $response->body);
     $this->render('/Client/request_response');
 }
コード例 #19
0
 /**
  * Sends out email via Postmark
  *
  * @return array Return the Postmark
  */
 public function send(CakeEmail $email)
 {
     // CakeEmail
     $this->_cakeEmail = $email;
     $this->_config = $this->_cakeEmail->config();
     $this->_headers = $this->_cakeEmail->getHeaders(array('from', 'to', 'cc', 'bcc', 'replyTo', 'subject'));
     // Setup connection
     $this->__postmarkConnection =& new HttpSocket();
     // Build message
     $message = $this->__buildMessage();
     // Build request
     $request = $this->__buildRequest();
     // Send message
     $returnPostmark = $this->__postmarkConnection->post($this->_config['uri'], json_encode($message), $request);
     // Return data
     $result = json_decode($returnPostmark, true);
     $headers = $this->_headersToString($this->_headers);
     if ($this->_cakeEmail->emailFormat() === 'html') {
         $message = $message['HtmlBody'];
     } else {
         $message = $message['TextBody'];
     }
     return array_merge(array('Postmark' => $result), array('headers' => $headers, 'message' => $message));
 }
コード例 #20
0
 public function callEndpoint(&$Model, $path = null, $type = 'POST', $data = array(), $options = array())
 {
     $db = ConnectionManager::getDataSource($Model->useDbConfig);
     $this->endpointHost = $db->config['host'];
     $this->http = !empty($db->config['https']) ? 'https://' : 'http://';
     $fullPath = $this->http . $this->endpointHost . $path;
     //debug($Model->useDbConfig);
     //debug($fullPath);
     //$request = new CakeRequest($fullPath);
     $http = new HttpSocket();
     if ($type == 'POST') {
         $request = $http->post($fullPath, $data, $options);
     } else {
         $request = $http->get($fullPath, $data, $options);
     }
     return $request;
 }
コード例 #21
0
ファイル: Akismet.php プロジェクト: atkrad/akismet
 protected static function postRequest($data, $key = null, $type = null)
 {
     $HttpSocket = new HttpSocket();
     switch ($type) {
         case 'verify-key':
             $requestURI = self::SCHEMA . self::HOST . '/' . self::API_VERSION . "/{$type}";
             break;
         case 'comment-check':
         case 'submit-spam':
         case 'submit-ham':
             $requestURI = self::SCHEMA . $key . '.' . self::HOST . '/' . self::API_VERSION . "/{$type}";
             break;
         default:
             $requestURI = '';
             break;
     }
     return $HttpSocket->post($requestURI, $data);
 }
コード例 #22
0
 public function send($text, $channel = null, $username = null, $icon_emoji = null, $url = null)
 {
     App::uses('HttpSocket', 'Network/Http');
     $HttpSocket = new HttpSocket();
     $url = $url ? $url : $this->webhook_url;
     $payload = array();
     $payload['text'] = $text;
     if ($channel) {
         $payload['channel'] = $channel;
     }
     if ($username) {
         $payload['username'] = $username;
     }
     if ($icon_emoji) {
         $payload['icon_emoji'] = $icon_emoji;
     }
     $results = $HttpSocket->post($url, json_encode($payload));
     return $results;
 }
コード例 #23
0
ファイル: Post.php プロジェクト: sarvesh123/elastic-cake
 public function listAll($keyword = false, $price_max = false, $price_min = false)
 {
     $HttpSocket = new HttpSocket();
     if ($keyword) {
         $str = $this->makeSearchString($keyword);
         $matchQuery = array('must' => array('match' => array('title' => $str)));
     } else {
         $matchQuery = array('must' => array('match_all' => array()));
     }
     $filter = array();
     $gte = array();
     $lte = array();
     if ($price_min) {
         $gte = array('gte' => $price_min);
     }
     if ($price_max) {
         $lte = array('lte' => $price_max);
     }
     if ($price_min || $price_max) {
         $filter = array('filter' => array('range' => array('price' => array_merge($gte, $lte))));
     }
     $query = array('query' => array('bool' => array_merge($matchQuery, $filter)));
     debug(json_encode($query));
     try {
         $resp = $HttpSocket->post(ES_BASE_URL . '/posts/_search?pretty', json_encode($query));
     } catch (Exception $e) {
     }
     if (isset($resp)) {
         $temp = json_decode($resp, true);
         if ($temp['hits']['total'] > 0) {
             $tArr = $temp['hits']['hits'];
             foreach ($tArr as $key => $value) {
                 $fArr[]['Post'] = $value['_source'];
             }
             return $fArr;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
コード例 #24
0
 public function charge($data, $payment)
 {
     $post_values = array('x_login' => $this->api_login, 'x_tran_key' => $this->api_transaction_key, 'x_version' => '3.1', 'x_delim_data' => 'TRUE', 'x_delim_char' => ',', 'x_encap_char' => '"', 'x_relay_response' => 'FALSE', 'x_type' => 'AUTH_CAPTURE', 'x_method' => 'CC', 'x_card_num' => $payment['creditcard_number'], 'x_exp_date' => $payment['creditcard_month'] . $payment['creditcard_year'], 'x_card_code' => $payment['creditcard_code'], 'x_invoice_num' => '', 'x_tax' => '0.00', 'x_amount' => $data['total'], 'x_description' => '', 'x_first_name' => $data['first_name'], 'x_last_name' => $data['last_name'], 'x_address' => $data['billing_address'], 'x_city' => $data['billing_city'], 'x_state' => $data['billing_state'], 'x_zip' => $data['billing_zip'], 'x_country' => 'United States', 'x_ship_to_first_name' => $data['first_name'], 'x_ship_to_last_name' => $data['last_name'], 'x_ship_to_address' => $data['billing_address'], 'x_ship_to_city' => $data['billing_city'], 'x_ship_to_state' => $data['billing_state'], 'x_ship_to_zip' => $data['billing_zip'], 'x_ship_to_country' => 'United States', 'x_cust_id' => '', 'x_phone' => $data['phone'], 'x_email' => $data['email'], 'x_customer_ip' => $_SERVER['REMOTE_ADDR']);
     //debug($post_values);
     //die('end');
     App::uses('HttpSocket', 'Network/Http');
     $httpSocket = new HttpSocket();
     $response = $httpSocket->post($this->api_url, $post_values);
     if (!empty($response['body'])) {
         $parsed = preg_split("/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/", $response['body']);
         foreach ($parsed as $key => $value) {
             $parsed[$key] = substr($value, 1, -1);
         }
     } else {
         $parsed = array('-1', '-1', '-1');
     }
     if ($parsed[0] == '1') {
         return $parsed;
     } else {
         switch ($parsed[2]) {
             case '7':
                 $error = 'invalid expiration date';
                 break;
             case '8':
                 $error = 'expired';
                 break;
             case '6':
             case '17':
             case '28':
                 $error = 'declined';
                 break;
             case '78':
                 $error = 'cvc';
                 break;
             default:
                 $error = 'general';
                 break;
         }
     }
     $this->log($parsed, 'authorizenet-errors');
     throw new Exception('Credit Card Processing Error: ' . $error);
 }
コード例 #25
0
 public function doDirectPayment()
 {
     $doDirectPaymentNvp = array('METHOD' => 'DoDirectPayment', 'VERSION' => '53.0', 'PAYMENTACTION' => 'Sale', 'IPADDRESS' => $this->ipAddress, 'RETURNFMFDETAILS' => 1, 'ACCT' => $this->creditCardNumber, 'EXPDATE' => $this->creditCardExpires, 'CVV2' => $this->creditCardCvv, 'CREDITCARDTYPE' => $this->creditCardType, 'FIRSTNAME' => $this->customerFirstName, 'LASTNAME' => $this->customerLastName, 'EMAIL' => $this->customerEmail, 'STREET' => $this->billingAddress1, 'STREET2' => $this->billingAddress2, 'CITY' => $this->billingCity, 'STATE' => $this->billingState, 'COUNTRYCODE' => $this->billingCountryCode, 'ZIP' => $this->billingZip, 'AMT' => $this->amount, 'CURRENCYCODE' => 'USD', 'USER' => $this->paypal_username, 'PWD' => $this->paypal_password, 'SIGNATURE' => $this->paypal_signature);
     App::uses('HttpSocket', 'Network/Http');
     $httpSocket = new HttpSocket();
     $response = $httpSocket->post($this->paypal_endpoint, $doDirectPaymentNvp);
     parse_str($response, $parsed);
     if (array_key_exists('ACK', $parsed) && $parsed['ACK'] == 'Success') {
         return $parsed;
     } elseif (array_key_exists('ACK', $parsed) && array_key_exists('L_LONGMESSAGE0', $parsed) && $parsed['ACK'] != 'Success') {
         $this->log($parsed, 'paypal');
         throw new Exception($parsed['ACK'] . ' : ' . $parsed['L_LONGMESSAGE0']);
     } elseif (array_key_exists('ACK', $parsed) && array_key_exists('L_ERRORCODE0', $parsed) && $parsed['ACK'] != 'Success') {
         $this->log($parsed, 'paypal');
         throw new Exception($parsed['ACK'] . ' : ' . $parsed['L_ERRORCODE0']);
     } else {
         $this->log($parsed, 'paypal');
         throw new Exception('There is a problem with the payment gateway. Please try again later.');
     }
 }
コード例 #26
0
 public function getRate($data = null)
 {
     if ($data['Weight'] < 0.1) {
         $data['Weight'] = 0.1;
     }
     if ($data['Weight'] > 70) {
         $data['Weight'] = 70;
     }
     $xml = $this->buildRequest($data);
     App::uses('HttpSocket', 'Network/Http');
     $httpSocket = new HttpSocket();
     $res = $httpSocket->post($this->url, $xml);
     App::uses('Xml', 'Utility');
     $response = Xml::toArray(Xml::build($res['body']));
     $formattedResponse = $this->formatResponse($response);
     if (!empty($formattedResponse)) {
         return $formattedResponse;
     }
     return false;
 }
コード例 #27
0
 /**
  * Send
  *
  * @param CakeEmail $email objeto mail
  * @return array
  * @throws SocketException
  */
 public function send(CakeEmail $email)
 {
     $http = new HttpSocket();
     $url = 'https://api.mailgun.net/v2/' . $this->_config['mailgun_domain'] . '/messages';
     $post = array();
     $postPreprocess = array_merge($email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject')), array('text' => $email->message(CakeEmail::MESSAGE_TEXT), 'html' => $email->message(CakeEmail::MESSAGE_HTML)));
     foreach ($postPreprocess as $k => $v) {
         if (!empty($v)) {
             $post[strtolower($k)] = $v;
         }
     }
     $request = array('auth' => array('method' => 'Basic', 'user' => 'api', 'pass' => $this->_config['api_key']));
     $response = $http->post($url, $post, $request);
     if ($response === false) {
         throw new SocketException("Mailgun BasicTransport error, no response", 500);
     }
     $httpStatus = $response->code;
     if ($httpStatus != 200) {
         throw new SocketException("Mailgun request failed.  Status: {$httpStatus}, Response: {$response->body}", 500);
     }
     return array('headers' => $this->_headersToString($email->getHeaders(), PHP_EOL), 'message' => implode(PHP_EOL, $email->message()));
 }
コード例 #28
0
ファイル: hq_sms.php プロジェクト: sandulungu/StarLight
 public function send($to, $message, $params = array())
 {
     $params += SlConfigure::read('Api.hqSms') + array('encoding' => 'utf-8', 'test' => false, 'details' => false);
     if (is_array($to)) {
         $multiple = true;
         foreach ($to as $i => &$phone) {
             $phone = $this->standartizePhoneNoMd($phone);
             if (empty($phone)) {
                 unset($to[$i]);
             }
         }
         $params['to'] = implode(',', $to);
     } else {
         $multiple = false;
         $params['to'] = $this->standartizePhoneNoMd($to);
     }
     if (empty($params['to'])) {
         return;
     }
     $protocol = $params['secure'] && SlConfigure::read('Sl.options.sslTransport') ? 'https' : 'http';
     unset($params['secure']);
     if (strlen($params['password']) != 32) {
         $params['password'] = md5($params['password']);
     }
     $params['message'] = $message;
     App::import('Core', 'HttpSocket');
     $socket = new HttpSocket();
     Sl::krumo($params);
     $result = $socket->post("{$protocol}://www.hqsms.com/api/send.do", $params);
     if ($multiple) {
         $result = explode(';', $result);
         foreach ($result as &$item) {
             $item = explode(':', $item);
         }
         return $result;
     } else {
         return explode(':', $result);
     }
 }
コード例 #29
0
 private function get_address($zipcode)
 {
     App::uses('Sanitize', 'Utility');
     $zipcode = Sanitize::paranoid($zipcode);
     App::uses('HttpSocket', 'Network/Http');
     $HttpSocket = new HttpSocket();
     $post['cepEntrada'] = $zipcode;
     $post['tipoCep'] = '';
     $post['cepTemp'] = '';
     $post['metodo'] = 'buscarCep';
     $resposta = $HttpSocket->post("http://m.correios.com.br/movel/buscaCepConfirma.do", $post);
     $resposta = str_replace("\n", "", $resposta);
     $resposta = str_replace("\r", "", $resposta);
     $resposta = str_replace("\t", "", $resposta);
     preg_match_all('/<span class="respostadestaque">([^<]+)<\\/span>/i', $resposta, $match);
     if (isset($match[1][0])) {
         $endereco = utf8_encode(trim($match[1][0]));
         if (stripos($endereco, '- até') !== false) {
             preg_match_all('/(.*)(- até)(.*)/i', $endereco, $matchRua);
             $endereco = $matchRua[1][0];
         } else {
             if (stripos($endereco, '- de') !== false) {
                 preg_match_all('/(.*)(- de)(.*)/i', $endereco, $matchRua);
                 $endereco = $matchRua[1][0];
             } else {
                 if (stripos($endereco, '- lado') !== false) {
                     preg_match_all('/(.*)(- lado)(.*)/i', $endereco, $matchRua);
                     $endereco = $matchRua[1][0];
                 }
             }
         }
         $this->request->data['Zipcode']['logradouro'] = trim($endereco);
         $this->request->data['Zipcode']['bairro'] = utf8_encode(trim($match[1][1]));
         $cidadeUF = explode('/', $match[1][2]);
         $this->request->data['Zipcode']['cidade'] = utf8_encode(trim($cidadeUF[0]));
         $this->request->data['Zipcode']['estado'] = trim($cidadeUF[1]);
     }
     return json_encode($this->request->data);
 }
コード例 #30
0
 /**
  * Posts the data to the postmark API endpoint
  *
  * @return array
  * @throws CakeException
  */
 protected function _postmarkSend()
 {
     $this->_generateSocket();
     $protocol = $this->_config['secure'] ? 'https' : 'http';
     $uri = $protocol . '://' . $this->_apiUri;
     $apiKey = $this->_config['debug'] === true ? 'POSTMARK_API_TEST' : $this->_config['apiKey'];
     if (is_string($this->_config['debug'])) {
         $this->_data['To'] = $this->_config['debug'];
         if (isset($this->_data['Cc'])) {
             unset($this->_data['Cc']);
         }
         if (isset($this->_data['Bcc'])) {
             unset($this->_data['Bcc']);
         }
     }
     $request = array('header' => array('Accept' => 'application/json', 'Content-Type' => 'application/json', 'X-Postmark-Server-Token' => $apiKey));
     $return = $this->_socket->post($uri, json_encode($this->_data), $request);
     $response = json_decode($return);
     if ($this->_socket->response->code != '200') {
         throw new CakeException($response->Message);
     }
     $this->_content = array('headers' => array(), 'message' => $this->_data, 'response' => $response);
 }