public function core_call($serialized_request) { $client = new HttpClient($this->domain); $client->setCookies($this->cookies); $client->post($this->location . "json/", $serialized_request); return $client->getContent(); }
function beacon_send_message($channel, $data) { $url = '/1.0.0/' . get_option('beacon_api_key') . '/channels/' . $channel; $client = new HttpClient('api.beaconpush.com'); $client->extra_request_headers = array('X-Beacon-Secret-Key: ' . get_option('beacon_secret_key')); $client->post($url, json_encode($data)); }
/** * Verifies a recaptcha * * @param $priv_key private recaptcha key * @return true on success */ public function verify() { $error = ErrorHandler::getInstance(); $conf = RecaptchaConfig::getInstance(); if (empty($_POST['recaptcha_challenge_field']) || empty($_POST['recaptcha_response_field'])) { $error->add('No captcha answer given.'); return false; } if (!$conf->getPublicKey() || !$conf->getPrivateKey()) { die('ERROR - Get Recaptcha API key at http://recaptcha.net/api/getkey'); } $params = array('privatekey' => $conf->getPrivateKey(), 'remoteip' => client_ip(), 'challenge' => $_POST['recaptcha_challenge_field'], 'response' => $_POST['recaptcha_response_field']); $http = new HttpClient($this->api_url_verify); $res = $http->post($params); $answers = explode("\n", $res); if (trim($answers[0]) == 'true') { return true; } switch ($answers[1]) { case 'incorrect-captcha-sol': $e = 'Incorrect captcha solution'; break; default: $e = 'untranslated error: ' . $answers[1]; } $error->add($e); return false; }
/** * to config content data and send to target * @param array $data - content data in array * (format like array( * "first"=>array("value"=>"","color"=>""), * "remark"=>array("value"=>"","color"=>"")) * ) * @return data received after posting */ public function send($data) { $this->body['data'] = $data; $json = json_encode($this->body); $client = new HttpClient("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$this->access_token}"); $client->setParameter($json); return $client->post(); }
function testJsonPost() { $http = new HttpClient('http://localhost/coredev_testserver/post_json.php'); $http->setContentType('application/json'); $http->setDebug(true); $res = $http->post(array('str' => 'abc 123')); $this->assertEquals($res, 'str=abc+123'); }
public function send($content) { $data = array("touser" => $this->openid, "msgtype" => "text", "text" => array("content" => urlencode($content))); $data = urldecode(json_encode($data)); $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$this->access_token}"; $client = new HttpClient($url); $client->setParameter($data); return $client->post(); }
function sendMessage($msgInfo) { $client = new HttpClient(FEYIN_HOST, FEYIN_PORT); if (!$client->post('/api/sendMsg', $msgInfo)) { //提交失败 return 'faild'; } else { return $client->getContent(); } }
public static final function sendSms($path, $apikey, $encoded_text, $mobile, $tpl_id = '', $encoded_tpl_value = '') { $client = new HttpClient(self::HOST); $client->setDebug(false); if (!$client->post($path, array('apikey' => $apikey, 'text' => $encoded_text, 'mobile' => $mobile, 'tpl_id' => $tpl_id, 'tpl_value' => $encoded_tpl_value))) { return '-10000'; } else { return self::__replyResult($client->getContent()); } }
function apiPost($baseData, $url, $parameters, $private) { $nonce = substr(md5(microtime()), 0, 6); $url = $baseData["path"] . $url; $msg = "{$url}:{$nonce}:{$private}"; $hash = $nonce . ":" . hash_hmac("sha256", $msg, $parameters["auth_token"]); $client = new HttpClient($baseData["host"]); $parameters["auth_hash"] = $hash; $client->post($url, $parameters); return $client; }
/** * @param RequestAbstract $request * @param string $endpointUrl * @return \Guzzle\Http\EntityBodyInterface|string * @throws Exception\ConnectionError */ private function sendRequest(RequestAbstract $request, $endpointUrl) { $client = new HttpClient(); $client->setConfig(array('curl.options' => array(CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false))); $httpRequest = $client->post($endpointUrl, null, $request->getRawData()); try { return $httpRequest->send()->getBody(); } catch (RequestException $e) { throw new ConnectionError($e->getMessage()); } }
public static final function sendSms($user, $password, $content, $mobiles) { $client = new HttpClient(self::HOST); $client->setDebug(false); date_default_timezone_set('PRC'); if (!$client->post('/sdk/send', array('accName' => $user, 'accPwd' => strtoupper($password), 'bizId' => date('YmdHis'), 'content' => mb_convert_encoding($content, 'UTF-8', 'UTF-8'), 'aimcodes' => $mobiles, 'dataType' => "xml"))) { return '-10000'; } else { return self::__replyResult($client->getContent()); } }
/** * to get the short url by transforming * @param string $url - long url * @return string - short url (or boolean false if fail) */ public function get($url) { if ($this->access_token) { $client = new HttpClient("https://api.weixin.qq.com/cgi-bin/shorturl?access_token={$this->access_token}"); $client->setParameter(array('action' => 'long2short', 'long_url' => $url)); $stream = json_decode($client->post()); if (isset($stream->short_url)) { return $stream->short_url; } } return false; }
public function queryOrderNumbersByTime($device_no, $date) { $msgInfo = array('clientCode' => $device_no, 'date' => $date); $client = new HttpClient(FEIE_HOST, FEIE_PORT); if (!$client->post('/FeieServer/queryorderinfo', $msgInfo)) { //提交失败 return 'faild'; } else { $result = $client->getContent(); return $result; } }
function wordpress_remote_auth($host, $uri, $login, $pass, $formId = "") { $client = new HttpClient($host); $client->setHandleRedirects(false); $client->setHeadersOnly(true); $res = $client->post($uri . "/wp-login.php", array("log" => $login, "pwd" => $pass, "wp-submit" => "Log In", "testcookie" => 1)); $newCookies = extractResponseCookies($client); if (isset($newCookies["AjaXplorer"])) { return $newCookies["AjaXplorer"]; } return ""; }
public function create($statement) { $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$this->access_token}"; if (is_array($statement)) { include dirname(__FILE__) . '/../util/arr_urlencode.php'; $statement = arr_urlencode($statement); $statement = urldecode(json_encode($statement)); } $client = new HttpClient($url); $client->setParameter($statement); return $client->post(); }
function getReplyMsg() { $timestamp=$this->getUnixTimeStamp(); $digest=md5("$this->appid".md5($this->appkey)."$timestamp"); $senddata="ac=fetchreply&appid=".$this->appid."×tamp=".$timestamp."&digest=".$digest."&scopetype=0"; $http=new HttpClient(); $ret=$http->post($this->apiurl,$senddata); if(!$ret) { return FALSE; } return $ret; }
static function shorten($input_url) { $temp = TempStore::getInstance(); $res = $temp->get('goo.gl/' . $input_url); if ($res) { return $res; } $api_key = ''; $http = new HttpClient('https://www.googleapis.com/urlshortener/v1/url'); $http->setContentType('application/json'); $res = $http->post(Json::encode(array('longUrl' => $input_url, 'key' => $api_key))); $res = Json::decode($res); if (isset($res->error)) { d($res->error->errors); throw new \Exception('Error code ' . $res->error->code . ': ' . $res->error->message); } $temp->set('goo.gl/' . $input_url, $res->id); return $res->id; }
/** * Executes a Twitter API function */ private function exec($url, $params = array()) { if (!$params) { $cache = new Cache(); $cache->setCacheTime(60 * 5); //5 min $key = 'twitter//' . sha1($url); $full = $cache->get($key); if ($full) { return $full; } } $http = new HttpClient($url); $res = $http->post($params); if (!$params) { $cache->set($key, $res); } return $res; }
/** * 获取校验结果 * @param $ssid * @param $result * @param int $diff * @return type */ public static function sendVerifyRemoteRequest($ssid, $result, $diff = 0) { $client = new HttpClient(App::getConfig('YUC_SERVICE_NAME'), App::getConfig('YUC_SERVICE_PORT')); $client->setTimeout(App::getConfig('YUC_CLIENT_TIMEOUT')); //设置超时 $client->post(App::getConfig('YUC_VERIFY_PATH'), array('site_key' => App::getConfig('YUC_SITE_KEY'), 'ssid' => $ssid, 'result' => $result, 'diffsec_client' => $diff)); $post_req = json_decode($client->getContent(), TRUE); Log::Write('远程验证完成,输入结果为:' . $result . ',返回状态 :' . $client->getStatus() . ';' . 'POST 验证码正确性请求返回的数据:' . $client->getContent(), Log::DEBUG); if ($client->getStatus() == 200 && is_array($post_req)) { //200状态 正常返回数据 且返回数据格式正常 self::$_yuc_code = $post_req['code']; self::$_yuc_details = $post_req['details']; self::$_yuc_result = $post_req['result']; } else { self::$_yuc_code = 'E_SEVERVALID_001'; self::$_yuc_details = '服务器请求失败!'; self::$_yuc_result = 0; } return array('code' => self::$_yuc_code, 'result' => self::$_yuc_result, 'details' => self::$_yuc_details); }
/** * Preferences are handled in _PassUser */ function checkPass($password) { $userid = $this->_userid; if (!loadPhpExtension('openssl')) { trigger_error(sprintf(_("The PECL %s extension cannot be loaded."), "openssl") . sprintf(_(" %s AUTH ignored."), 'Facebook'), E_USER_WARNING); return $this->_tryNextUser(); } $web = new HttpClient("www.facebook.com", 80); if (DEBUG & _DEBUG_LOGIN) { $web->setDebug(true); } // collect cookies from http://www.facebook.com/login.php $web->persist_cookies = true; $web->cookie_host = 'www.facebook.com'; $firstlogin = $web->get("/login.php"); if (!$firstlogin) { if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE)) { trigger_error(sprintf(_("Facebook connect failed with %d %s"), $web->status, $web->errormsg), E_USER_WARNING); } } // Switch from http to https://login.facebook.com/login.php $web->port = 443; $web->host = 'login.facebook.com'; if (!($retval = $web->post("/login.php", array('user' => $userid, 'pass' => $password)))) { if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE)) { trigger_error(sprintf(_("Facebook login failed with %d %s"), $web->status, $web->errormsg), E_USER_WARNING); } } $this->_authmethod = 'Facebook'; if (DEBUG & _DEBUG_LOGIN) { trigger_error(get_class($this) . "::checkPass => {$retval}", E_USER_WARNING); } if ($retval) { $this->_level = WIKIAUTH_USER; } else { $this->_level = WIKIAUTH_ANON; } return $this->_level; }
function _getMatches($word_list) { $xml = ""; // Setup HTTP Client $client = new HttpClient('www.google.com'); $client->setUserAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR'); $client->setHandleRedirects(false); $client->setDebug(false); // Setup XML request $xml .= '<?xml version="1.0" encoding="utf-8" ?>'; $xml .= '<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1">'; $xml .= '<text>' . htmlentities($word_list) . '</text></spellrequest>'; // Execute HTTP Post to Google if (!$client->post('/tbproxy/spell?lang=' . $this->lang, $xml)) { $this->errorMsg[] = 'An error occurred: ' . $client->getError(); return array(); } // Grab and parse content $xml = $client->getContent(); preg_match_all('/<c o="([^"]*)" l="([^"]*)" s="([^"]*)">([^<]*)<\\/c>/', $xml, $matches, PREG_SET_ORDER); return $matches; }
/** * Try to refresh this access token * * @param string $id of the client/user * @param \OAuth2Yii\Provider\Provider $provider the auth provider * @return bool whether the token were successfully refreshed */ public function refresh($id, $provider) { if ($this->refreshToken) { $client = new HttpClient(); $url = $provider->getTokenUrl(); $storage = $provider->getStorage(); $data = array('grant_type' => 'refresh_token', 'refresh_token' => $this->refreshToken); YII_DEBUG && Yii::trace("Refreshing {$this->type} access token '{$this->token}'", 'oauth2.component.accesstoken'); $response = $client->post($url, $data, array(), $provider->clientId, $provider->clientSecret); $token = self::parseResponse($response, $provider); if ($token === null) { YII_DEBUG && Yii::trace('Access token refresh failed', 'oauth2.component.accesstoken'); $storage->deleteToken($id, $this->type, $provider->name); return false; } else { YII_DEBUG && Yii::trace('Access token refresh successful', 'oauth2.component.accesstoken'); $storage->updateToken($id, $this->type, $provider->name); return true; } } return false; }
/** * @return bool whether the client could be authenticated against the OAuth2 server */ public function authenticate() { $provider = $this->getProvider(); $client = new HttpClient(); $url = $provider->getTokenUrl(); $data = array('grant_type' => 'client_credentials'); if ($this->scope) { $data['scope'] = $this->scope; } YII_DEBUG && Yii::trace("Requesting access token for client from {$url}", 'oauth2.component.clientidentity'); $response = $client->post($url, $data, array(), $this->username, $this->password); $token = AccessToken::parseResponse($response, $provider, $this); if ($token === null) { YII_DEBUG && Yii::trace("Failed to receive client access token", 'oauth2.component.clientidentity'); return false; } else { YII_DEBUG && Yii::trace("Received access token '{$token->token}' for client", 'oauth2.component.clientidentity'); $this->errorCode = self::ERROR_NONE; $token->type = AccessToken::TYPE_CLIENT; $provider->getStorage()->saveToken($this->username, $token); return true; } }
/** * @return bool whether the user could be authenticated against the OAuth2 server */ public function authenticate() { $provider = $this->getProvider(); $client = new HttpClient(); $url = $provider->getTokenUrl(); $data = array('grant_type' => 'password', 'username' => $this->username, 'password' => $this->password); if ($this->scope) { $data['scope'] = $this->scope; } YII_DEBUG && Yii::trace("Requesting access token for user from {$url}", 'oauth2.component.useridentity'); $response = $client->post($url, $data, array(), $provider->clientId, $provider->clientSecret); $token = AccessToken::parseResponse($response, $provider, $this); if ($token === null) { YII_DEBUG && Yii::trace('Access token request for user failed: ' . $response, 'oauth2.component.useridentity'); return false; } else { YII_DEBUG && Yii::trace(sprintf("Received user access token: %s, scope: '%s', expires: %s", $token->token, $token->scope, date('Y-m-d H:i:s', $token->expires)), 'oauth2.component.useridentity'); $this->errorCode = self::ERROR_NONE; $token->type = AccessToken::TYPE_USER; $provider->getStorage()->saveToken($this->username, $token); return true; } }
function customHttpClient($SERVER, $PATH, $COOKIES, $PARAMS) { //return;//return '{"resHeader":{"backUrl":"","flag":"0","msg":"访问失败"}}'; //到远程服务器查询登录状态 include_once dirname(__FILE__) . '/httpclient.inc.php'; try { $client = new HttpClient($SERVER); $client->timeout = 10; $client->setCookies($COOKIES); $client->setPersistCookies(true); $postURL = $PATH; customCreateLogFile(dirname(__FILE__) . "/httpclient_log/" . date('Ymd') . ".txt", getHexDecode($client->buildQueryString($PARAMS))); if (!$client->post($postURL, $PARAMS)) { customCreateLogFile(dirname(__FILE__) . "/httpclient_log/" . date('Ymd') . ".txt", "\nPUT SERVER:" . $SERVER . "" . $PATH . "\nFAILD1"); return '{"resHeader":{"backUrl":"","flag":"0","msg":"访问失败1"}}'; } } catch (Exception $e) { customCreateLogFile(dirname(__FILE__) . "/httpclient_log/" . date('Ymd') . ".txt", "\nPUT SERVER:" . $SERVER . "" . $PATH . "\nFAILD2"); return '{"resHeader":{"backUrl":"","flag":"0","msg":"访问失败2"}}'; } $response = $client->getContent(); customCreateLogFile(dirname(__FILE__) . "/httpclient_log/" . date('Ymd') . ".txt", "\nPUT SERVER:" . $SERVER . "" . $PATH . "\nPUT COOKIES:" . (is_array($COOKIES) ? var_export($COOKIES, true) : '') . "\nPUT DATA:" . (is_array($PARAMS) ? var_export($PARAMS, true) : $PARAMS) . "\nGET DATA:" . iconv('GBK', 'UTF-8', $response)); return iconv('GBK', 'UTF-8', $response); }
public static function error($content, $sessionId) { \HttpClient::post(self::getRemoteLogUrl($sessionId), ['data' => self::getFormattedLog($content, 'error')]); }
/** * 发起请求 * @param string $serviceName 接口serviceName * @param string $bizParams 业务级参数数组 * @return mixed * @throws Exception */ public function doRequest($serviceName, $bizParams) { try { $requestParams = array('serviceName' => $serviceName, 'appKey' => $this->_envConfig['appKey'], 'format' => 'json', 'signType' => 'RSA', 'charset' => 'UTF-8', 'version' => $this->_version, 'timestamp' => date('YmdHis') . mt_rand(100, 999), 'bizContent' => $this->_buildBizContent($bizParams)); $requestParams['sign'] = $this->_getRsa()->sign($requestParams); $http = new HttpClient(); $this->_addDebugInfo(array('requestParams' => $requestParams)); $res = $http->post($this->_envConfig['gateUrl'], $requestParams); $this->_addDebugInfo(array('response' => $res)); $data = json_decode($res['data'], true); $this->_addDebugInfo(array('data' => $data)); if (isset($data['sign']) && !$this->_verifySign($data)) { //如果返回数据验签失败 $this->_addDebugInfo(array('error' => '返回数据验签失败')); throw new Exception('返回数据验签失败!', self::SIGN_INVALID); } $this->_checkError($data); //检查系统级别的错误 if (isset($data['bizContent']) && strlen($data['bizContent'])) { //如果返回数据包含bizContent且不为空串,则解密 $this->_rawBizContent = $this->_getRsa()->decrypt($data['bizContent']); $bizContent = json_decode($this->_rawBizContent, true); $this->_addDebugInfo(array('bizContent' => $bizContent)); if (isset($bizContent['resultJson'])) { $bizContent = json_decode($bizContent['resultJson'], true); } $this->_checkError($bizContent); //检查业务级别的错误 return $bizContent; } else { throw new Exception('返回bizContent为空或不存在!', self::BIZCONTENT_INVALID); } } catch (Exception $e) { $errorCode = $e instanceof ZaException ? $this->_decodeErrorCode($e->getCode()) : $e->getCode(); return array('errorCode' => $errorCode, 'errorMsg' => $e->getMessage()); } }
static function quickPost($url, $data) { $bits = parse_url($url); $host = $bits['host']; $port = isset($bits['port']) ? $bits['port'] : 80; $path = isset($bits['path']) ? $bits['path'] : '/'; $client = new HttpClient($host, $port); if (!$client->post($path, $data)) { return false; } else { return $client->getContent(); } }
<?php include_once 'common.php'; require 'http_client.php'; $ticket = gp('ticket'); $room_id = gp('id'); $nick = gp('nick'); if (!empty($ticket)) { $data = array('ticket' => $ticket, 'nick' => $nick, 'domain' => $_IMC['domain'], 'apikey' => $_IMC['apikey'], 'room' => $room_id, 'endpoint' => $space['uid']); $client = new HttpClient($_IMC['imsvr'], $_IMC['impost']); $client->post('/room/leave', $data); $pageContents = $client->getContent(); echo $pageContents; }
//Login webim server. $nick = to_utf8($name); $setting = setting(); $block_list = is_array($setting->block_list) ? $setting->block_list : array(); $rooms = find_room(); $room_ids = array(); foreach ($rooms as $key => $value) { if (in_array($key, $block_list)) { $rooms[$key]['blocked'] = true; } else { array_push($room_ids, $key); } } $data = array('rooms' => join(',', $room_ids), 'buddies' => join(',', array_unique(array_merge($friend_ids, $buddy_ids, $stranger_ids))), 'domain' => $_IMC['domain'], 'apikey' => $_IMC['apikey'], 'endpoint' => $space['uid'], 'nick' => to_unicode($nick)); $client = new HttpClient($_IMC['imsvr'], $_IMC['impost']); $client->post('/presences/online', $data); $pageContents = $client->getContent(); //TODO: handle errors! $pageData = json_decode($pageContents); if ($client->status != "200" || empty($pageData->ticket)) { $ticket = ""; } else { $ticket = $pageData->ticket; } if (empty($ticket)) { //登录失败 echo '{status: "' . $client->status . '", "errorMsg":"' . $pageContents . '"}'; exit; } $buddy_online_ids = ids_array($pageData->buddies); //在线好友列表ids