function verify($assertion) { $url = "https://verifier.login.persona.org/verify"; global $audience; $params = "assertion=" . urlencode($assertion) . "&audience=" . urlencode($audience); $data = httpRequest($url, $params); return $data; }
public function post($tweet) { $response = httpRequest(self::POST_URL, $this->generatePostParams($tweet)); $token = $this->m_oauth->getRefreshToken($this->m_token['refresh_token']); if (!empty($token['access_token']) && !empty($token['refresh_token'])) { Encryption::serializeToFile($token, tmpDir('renren.oauth')); } }
/** * 调用原厂API (虚宝 and 商城币) * * @param string $type 类型(item=虚宝,money=商城币) * @param string $api_url 原厂API url * @param array $params 参数(虚宝需要以下参数:transaction_id、item_id、item_num、reason、uid;商城币需要:transaction_id、game_money、reason、uid) * @param string $secret 私钥 * @return string json格式数据 */ function callGameApi($type, $api_url, $params, $secret) { try { if (!in_array($type, array('item', 'money'))) { throw new Exception("type error", -1); } if (!isset($secret)) { throw new Exception("secret error", -2); } switch ($type) { case 'item': if (!isset($params['transaction_id']) || !isset($params['item_id']) || !isset($params['item_num']) || !isset($params['reason']) || !isset($params['uid'])) { throw new Exception("params error", -3); } $p['transaction_id'] = $params['transaction_id']; $p['item_id'] = $params['item_id']; $p['item_num'] = $params['item_num']; $p['reason'] = $params['reason']; $p['time'] = time(); $p['uid'] = $params['uid']; $p['sig'] = MD5("item_id=" . $p['item_id'] . "item_num=" . $p['item_num'] . "reason=" . $p['reason'] . "time=" . $p['time'] . "uid=" . $p['uid'] . $secret); break; case 'money': if (!isset($params['transaction_id']) || !isset($params['game_money']) || !isset($params['reason']) || !isset($params['uid'])) { throw new Exception("params error", -3); } $p['transaction_id'] = $params['transaction_id']; $p['game_money'] = $params['game_money']; $p['reason'] = $params['reason']; $p['time'] = time(); $p['uid'] = $params['uid']; $p['sig'] = MD5("game_money=" . $p['game_money'] . "reason=" . $p['reason'] . "time=" . $p['time'] . "uid=" . $p['uid'] . $secret); break; } try { $response = httpRequest($api_url, $p); } catch (Exception $e) { throw new Exception('can not connect game server. ', -4); } $content = trim($response); $iResult = json_decode($content); if (isset($iResult->result) && is_numeric($iResult->result)) { return $content; } else { throw new Exception($content, -5); } } catch (Exception $e) { $code = $e->getCode(); $msg = $e->getMessage(); return '{"result":2,"message":"' . $msg . '"}'; } }
public function torequest($url, $args = array(), $method = null, $posts = null) { $method = empty($method) ? empty($args) ? "GET" : "POST" : $method; $request = OAuthRequest::from_consumer_and_token($this->m_oauthConsumer, $this->m_token, $method, $url, $args); $request->sign_request($this->m_signatureMethod, $this->m_oauthConsumer, $this->m_token); $response = null; switch ($method) { case 'GET': $response = httpRequest($request->to_url()); break; case 'POST': $response = $this->httpRequest($request->get_normalized_http_url(), $request->to_header(), $posts); break; } return $response; }
function ozekiSend($phone, $msg, $debug = false) { global $ozeki_user, $ozeki_password, $ozeki_url; $url = 'username='******'&password='******'&action=sendmessage'; $url .= '&messagetype=SMS:TEXT'; $url .= '&recipient=' . urlencode($phone); $url .= '&messagedata=' . urlencode($msg); $urltouse = $ozeki_url . $url; if ($debug) { echo "Request: <br>{$urltouse}<br><br>"; } //Open the URL to send the message $response = httpRequest($urltouse); if ($debug) { echo "Response: <br><pre>" . str_replace(array("<", ">"), array("<", ">"), $response) . "</pre><br>"; } return $response; }
function createShortUrl($url, $retry = 3) { /*{{{*/ if (empty($url)) { return $url; } while ($retry > 0) { //$dwz = "http://dwz.cn/create.php"; $dwz = "http://s.youzu.com/gen.php"; $data = array('url' => $url); $res = httpRequest($dwz, 'POST', $data); $result = json_decode($res, true); $shortUrl = $url; if (isset($result['tinyurl'])) { $shortUrl = $result['tinyurl']; break; } $retry--; } return $shortUrl; }
if (count(array_intersect_key(array_flip($required_params), $data)) === count($required_params)) { $ok = $db->delete('participants', array('id' => $data['participant_id'], 'conference_id' => $data['conference_id'])); if ($ok) { printResult(array("id" => $data['participant_id'], "status" => "DELETED")); } else { terminate("Couldn't remove participant"); } } else { terminate("Required params not specified"); } break; case 'get_numbers': $url = API_URL . "GetPhoneNumbers/?" . "account_name=" . ACCOUNT_NAME . "&api_key=" . API_KEY; $params = array(); $phone_numbers = array(); $result = httpRequest($url, $params); $res_obj = json_decode($result); foreach ($res_obj->result as $i => $val) { if (isset($val->application_name)) { if ($val->application_name == "conference.aylarov.voximplant.com") { $phone_numbers[] = array("id" => $val->phone_id, "number" => $val->phone_number); } } } if (isset($res_obj->error)) { terminate($result, true); } else { printResult($phone_numbers); } break; case 'get_participants':
$code = $_GET['code']; $appKey = '3212333708'; $appSecret = '8e2d7c321b6787329893023c82b38877'; $uri = 'http://xingwen1000.sinaapp.com/oauth.php'; if (!$code) { header('location:https://api.weibo.com/oauth2/authorize?client_id=' . $appKey . '&redirect_uri=' . $uri . '&response_type=code'); exit; } $url = 'https://api.weibo.com/oauth2/access_token?client_id=' . $appKey . '&client_secret=' . $appSecret . '&grant_type=authorization_code&code=' . $code . '&redirect_uri=' . $uri; $result = httpRequest($url, ''); $result = json_decode($result, true); $access_token = $result['access_token']; //返回最新的公共微博 if ($access_token) { $url = 'https://api.weibo.com/2/statuses/public_timeline.json?access_token=' . $access_token; $result = httpRequest($url); var_dump($result); exit; } else { echo '获取access_token失败'; exit; } function httpRequest($url, $data = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); if ($data !== null) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
} } if ($method == 'POST' && $body) { $reqsecond .= "content-type:application/x-www-form-urlencoded\n"; $reqsecond .= "content-length:" . $length . "\n"; } $reqsecond .= "connection:close\n\n"; $httprequest = $reqfirst . $reqsecond . $reqthree; $host = gethostbyname($uinf['host']); $port = isset($uinf['port']) ? $uinf['port'] : 80; if (!($sock = @fsockopen($host, $port, $errno, $errstr))) { echo $errno, ":", $errstr, "\n"; exit; } /* $out="HEAD / HTTP/1.1\n"; $out.="Host:192.168.11.120\n"; $out.="connection:close\n\n"; */ echo $httprequest, "\n", str_repeat("--", 10), "\n"; $count = fwrite($sock, $httprequest); $content = ""; while (!feof($sock)) { $content .= fgets($sock, 2048); //break; } echo $content; fclose($sock); } httpRequest($url, $method, $header, $data);
$token_secret = get_option_value('s', 'token_secret'); } if (empty($token)) { print "Please specify an access token.\n"; exit(1); } if (empty($token_secret)) { print "Please specify an access token secret.\n"; exit(1); } $ini = parse_ini_file("oauth.ini"); $test_consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']); $endpoint = $ini['apiroot'] . '/account/verify_credentials.xml'; print "{$endpoint}\n"; $at = new OAuthToken($token, $token_secret); $parsed = parse_url($endpoint); $params = array(); parse_str($parsed['query'], $params); $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); $req_req = OAuthRequest::from_consumer_and_token($test_consumer, $at, "GET", $endpoint, $params); $req_req->sign_request($hmac_method, $test_consumer, $at); $r = httpRequest($req_req->to_url()); $body = $r->getBody(); print "{$body}\n"; //print $req_req->to_url() . "\n\n"; function httpRequest($url) { $request = HTTPClient::start(); $request->setConfig(array('follow_redirects' => true, 'connect_timeout' => 120, 'timeout' => 120, 'ssl_verify_peer' => false, 'ssl_verify_host' => false)); return $request->get($url); }
<?php if (empty($_POST['convid'])) { echo ''; return; } sort($_POST['convid'], SORT_STRING); $_POST['convid'] = md5(implode(':', $_POST['convid'])); $header = array("X-AVOSCloud-Application-Id: 0s66p2ntvx0q56pk5mh8wxa7cuegr57w5abvb7nwv5dqymyo", "X-AVOSCloud-Application-Key: m4qivbjnn77tyox755169eslqtof174pq7tzaummnu3va9g4"); $res = httpRequest('https://leancloud.cn/1.1/rtm/messages/logs/', 'get', $_POST, $header); echo $res; function httpRequest($url, $method, $params = array(), $header = array()) { if (trim($url) == '' || !in_array($method, array('get', 'post')) || !is_array($params)) { return false; } $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); if (!empty($header)) { curl_setopt($curl, CURLOPT_HTTPHEADER, $header); } curl_setopt($curl, CURLOPT_HEADER, 0); switch ($method) { case 'get': $str = '?'; foreach ($params as $k => $v) { $str .= $k . '=' . $v . '&'; } $str = substr($str, 0, -1); $url .= $str; //$url=$url.$str;
function post_request($method, $params) { $post_string = $this->create_post_string($method, $params); $result = httpRequest($this->server_addr, $post_string); return $result; }
/** * Bind user to the application */ function bindUser($username) { $url = API_URL . "BindUser/?" . "account_name=" . ACCOUNT_NAME . "&api_key=" . API_KEY . "&user_name=" . $username . "&application_name=" . APP_NAME; $result = httpRequest($url); return array('api_result' => json_decode($result, true), 'username' => $username); }
function httpGET($url, $data = array(), $output) { return httpRequest('get', $url, $data, $output); }
/** * wechat::getAccessToken() * 获取access_token * @return string */ public function getAccessToken($config) { $request = httpRequest('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $config['appId'] . '&secret=' . $config['appSecret']); $requestArray = json_decode($request, true); if (isset($requestArray['errcode'])) { return false; } $accessToken = $requestArray['access_token']; return $accessToken; }
function sendMessage($message, $chatId) { httpRequest(API_URL . "sendMessage?chat_id=" . $chatId . "&text=" . $message); }
public function index() { echo U('Index/Index/handle', '', 'html', '', TRUE); $data = httpRequest(U('Index/Index/handle', '', '', '', TRUE), array('name' => 'caiknife', 'email' => '*****@*****.**')); print_r($data); }
public function getRefreshToken($refreshToken) { $request = array("refresh_token" => $refreshToken, "grant_type" => 'refresh_token', "client_id" => $this->m_key, "client_secret" => $this->m_secret); return httpRequest($this->accessTokenURL(), $request, 2); }
<p> <input type="text" name="query" /> <!--入力された文字にqueryという名前をつけて転送--> <input type="submit" value="送信" /> <!--送信ボタンを表示-->※制限100KB<br> <hr> 出現回数の多い単語トップ10 </p> </form> <hr> <!-----------------------------------------------------------------------------------------------> <?php $query = $_POST['query']; //転送されたデータ(全ての変数)に対して、'name'で指定した文字列を添字とした要素を変数へ代入 if (isset($query)) { //q_queryに値があったら表示 list($head, $data) = httpRequest($query); //(2)取得したページの文章だけを取り出す $data = strip_tags($data); //タグ除去 $hinshi = "名詞"; //(3)1リクエストにつき100KB制限 $start = 0; $size = 512; //100KB=1024*100/2=512文字だが、file_get_contents()制限の為 $end = mb_strlen($data); do { $data2 = mb_substr($data, $start - $end, $size); $tango = yahoo_mecab($data2, $hinshi, $query); $start += $size; foreach ($tango as $val) { //word配列に単語を格納
print "You forgot to specify a {$inikey} in your oauth.ini file.\n"; exit(1); } } $consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']); $endpoint = $ini['apiroot'] . $ini['request_token_url']; $parsed = parse_url($endpoint); $params = array(); parse_str($parsed['query'], $params); $params['oauth_callback'] = 'oob'; // out-of-band $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); try { $req = OAuthRequest::from_consumer_and_token($consumer, null, "POST", $endpoint, $params); $req->sign_request($hmac_method, $consumer, NULL); $r = httpRequest($endpoint, $req->to_postdata()); } catch (Exception $e) { // oh noez print $e->getMessage(); print "\nOAuth Request:\n"; var_dump($req); exit(1); } $body = $r->getBody(); $tokenStuff = array(); parse_str($body, $tokenStuff); $tok = $tokenStuff['oauth_token']; $confirmed = $tokenStuff['oauth_callback_confirmed']; if (empty($tokenStuff['oauth_token']) || empty($tokenStuff['oauth_token_secret']) || empty($confirmed) || $confirmed != 'true') { print "Error! HTTP response body: {$body}\n"; exit(1);
function user_list($group = 'editor') { global $settings; if (empty($group)) { return false; } $url = $settings['wikiroot'] . "/w/api.php?action=query&format=json"; $params = "action=query&list=allusers&aulimit=500&augroup=" . $group; $data = httpRequest($url, $params); if (empty($data)) { throw new Exception("No data received from server. Check that API is enabled."); } return json_decode($data, true); }
<?php include "config.php"; include "curl.php"; $response['status'] = "error"; $response['message'] = ""; try { $url = "https://api.github.com/gists"; if (empty($_POST['source'])) { throw new Exception("Source is empty"); } if (empty($_POST['extension'])) { throw new Exception("Extension is empty"); } $extension = isset($_POST['extension']) ? $_POST['extension'] : ''; $data['files']['source.' . $extension]['content'] = isset($_POST['source']) ? $_POST['source'] : ''; $data['description'] = isset($_POST['description']) ? $_POST['description'] : ''; $data['public'] = isset($_POST['public']) ? $_POST['public'] : ''; $params = json_encode($data); //var_dump($params); $response['status'] = 'OK'; $response['message'] = httpRequest($url, $params); } catch (Exception $e) { $response['status'] = 'error'; $response['message'] = $e->getMessage(); die(json_encode($response)); } echo json_encode($response);
exit(1); } if (empty($update)) { print "You forgot to update your status!\n"; exit(1); } $ini = parse_ini_file("oauth.ini"); $consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']); $endpoint = $ini['apiroot'] . '/statuses/update.xml'; $atok = new OAuthToken($token, $token_secret); $parsed = parse_url($endpoint); parse_str($parsed['query'], $params); $params['status'] = $update; $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); try { $oauthReq = OAuthRequest::from_consumer_and_token($consumer, $atok, 'POST', $endpoint, $params); $oauthReq->sign_request($hmac_method, $consumer, $atok); $httpReq = httpRequest($endpoint, $oauthReq->to_postdata()); print $httpReq->getBody(); } catch (Exception $e) { print "Error! . {$e->getMessage}() . 'HTTP reponse body: " . $httpReq->getBody(); exit(1); } function httpRequest($endpoint, $poststr) { $request = HTTPClient::start(); $request->setConfig(array('follow_redirects' => true, 'connect_timeout' => 120, 'timeout' => 120, 'ssl_verify_peer' => false, 'ssl_verify_host' => false)); // Turn signed request query string back into an array parse_str($poststr, $postdata); return $request->post($endpoint, null, $postdata); }
} if (empty($token)) { print "Please specify an access token (--help for help).\n"; exit(1); } if (empty($token_secret)) { print "Please specify an access token secret (--help for help).\n"; exit(1); } $ini = parse_ini_file("oauth.ini"); $consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']); $endpoint = $ini['apiroot'] . '/account/verify_credentials.xml'; $atok = new OAuthToken($token, $token_secret); $parsed = parse_url($endpoint); parse_str($parsed['query'], $params); try { $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); $oauthReq = OAuthRequest::from_consumer_and_token($consumer, $atok, "GET", $endpoint, $params); $oauthReq->sign_request($hmac_method, $consumer, $atok); $httpReq = httpRequest($oauthReq->to_url()); } catch (Exception $e) { print "Error! HTTP response body: " . $httpReq->getBody(); exit(1); } print $httpReq->getBody(); function httpRequest($url) { $request = HTTPClient::start(); $request->setConfig(array('follow_redirects' => true, 'connect_timeout' => 120, 'timeout' => 120, 'ssl_verify_peer' => false, 'ssl_verify_host' => false)); return $request->get($url); }
fputs($sock, "$method $path HTTP/1.1\r\n"); fputs($sock, "Host: $host\r\n"); fputs($sock, "Content-type: " . "application/x-www-form-urlencoded\r\n"); if ($method == "POST") { fputs($sock, "Content-length: " . strlen($paramStr) . "\r\n"); } fputs($sock, "Connection: close\r\n\r\n"); if ($method == "POST") { fputs($sock, $paramStr); } // Buffer the result $result = ""; while (!feof($sock)) { $result .= fgets($sock,1024); } //var_dump($result); fclose($sock); //echo $result; return $result; }*/ } //$resp = httpRequest("www.experienceplus.com", // 443, "GET", "/atlas/cake_2_0/RestUsers/index", //array("firstName" => "John", "lastName" => "Doe")); //echo phpinfo(); $resp = httpRequest("ssl://www.local.jasmun.com", 443, "GET", '/RestUsers/index', array('firstName' => 'John', 'lastName' => 'Doe')); //$resp = httpRequest("google.com",80, "GET", '/RestUsers/index', array('firstName' => 'John', 'lastName'=>'Doe'));
curl_close($proxyGet); return $responseBody; } function cantContinue($backupURL) { header("HTTP/1.1 302 Found"); header("Location: " . $backupURL); exit; } $place = $_GET['q']; if (!$place) { echo "Usage: http://" . $_SERVER["HTTP_HOST"] . "/?q=Unique+Name+of+Business"; exit; } $searchURL = PLACES_URL . urlencode($place); $searchResults = httpRequest($searchURL, 4, null, MOBILE_UA); // Parse results with DOM $dom = new DOMDocument(); if (!$dom->loadHTML($searchResults)) { cantContinue($searchURL); } $list = $dom->getElementById("universal"); // echo $dom->saveXML($list); exit; // debug if (!$list) { cantContinue($searchURL); } // Definitely have something to run with now... header("Cache-Control: max-age=300"); // cache 5 minutes echo '<' . '?xml version="1.0" encoding="UTF-8"?' . '>'; ?>