public function shouquan($code, $openid, $openkey, $redirect_uri) { OAuth::init($this->client_id, $this->client_secret); Tencent::$debug = $this->debug; $callback = $redirect_uri; //回调url if ($code) { //已获得code //获取授权token $url = OAuth::getAccessToken($code, $callback); $r = Http::request($url); parse_str($r, $out); //存储授权数据 if (@$out['access_token']) { $_SESSION['t_access_token'] = $out['access_token']; $_SESSION['t_refresh_token'] = $out['refresh_token']; $_SESSION['t_expire_in'] = $out['expires_in']; $_SESSION['t_code'] = $code; $_SESSION['t_openid'] = $openid; $_SESSION['t_openkey'] = $openkey; //验证授权 $r = OAuth::checkOAuthValid(); if ($r) { //echo('<h3>授权成功!!!</h3><br>'); //print_r($r);exit; //header('Location: ' . $callback);//刷新页面 return $r; } else { exit('<h3>授权失败,请重试</h3>'); } } else { exit($r); } } }
/** * The general method for handling the communication with the service. */ public function request($resourceName, $getParams = [], $postData = [], $extraRequestOptions = []) { // Crash if we cannot make HTTP requests. \Wikia\Util\Assert::true(\MWHttpRequest::canMakeRequests()); // Add client_id and client_secret to the GET data. $getParams['client_id'] = $this->clientId; $getParams['client_secret'] = $this->clientSecret; // Request URI pre-processing. $uri = "{$this->baseUri}{$resourceName}?" . http_build_query($getParams); // Request options pre-processing. $options = ['method' => 'GET', 'timeout' => 5, 'postData' => $postData, 'noProxy' => true, 'followRedirects' => false, 'returnInstance' => true, 'internalRequest' => true]; $options = array_merge($options, $extraRequestOptions); /* * MediaWiki's MWHttpRequest class heavily relies on Messaging API * (wfMessage()) which happens to rely on the value of $wgLang. * $wgLang is set after $wgUser. On per-request authentication with * an access token we use MWHttpRequest before wgUser is created so * we need $wgLang to be present. With GlobalStateWrapper we can set * the global variable in the local, function's scope, so it is the * same as the already existing $wgContLang. */ global $wgContLang; $wrapper = new GlobalStateWrapper(['wgLang' => $wgContLang]); // Request execution. /** @var \MWHttpRequest $request */ $request = $wrapper->wrap(function () use($options, $uri) { return \Http::request($options['method'], $uri, $options); }); $this->status = $request->status; $output = json_decode($request->getContent()); if (!$output) { throw new ClientException('Invalid response.'); } return $output; }
public function testRequest_return_response_instance() { $requestMock = $this->getMock('PhpHttpRequest', ['execute', 'getContent'], [], '', false); $requestMock->expects($this->once())->method('execute')->will($this->returnValue($this->getStatusMock(self::HTTP_CONTENT))); $this->mockMWHttpRequestFactory($requestMock); $this->assertInstanceOf('MWHttpRequest', Http::request('GET', self::EXAMPLE_URL, ['returnInstance' => true])); }
public function checkUser($do) { // dump($_REQUEST); // dump($do); // exit; OAuth::init(QQ_KEY, QQ_SECRET); $callback = $this->getCallback('qq', $do); if ($_REQUEST['code']) { $code = $_REQUEST['code']; $openid = $_REQUEST['openid']; $openkey = $_REQUEST['openkey']; //获取授权token $url = OAuth::getAccessToken($code, $callback); $r = Http::request($url); parse_str($r, $out); //存储授权数据 if ($out['access_token']) { $_SESSION['t_access_token'] = $out['access_token']; $_SESSION['t_refresh_token'] = $out['refresh_token']; $_SESSION['t_expire_in'] = $out['expires_in']; $_SESSION['t_code'] = $code; $_SESSION['t_openid'] = $openid; $_SESSION['t_openkey'] = $openkey; $_SESSION['qq']['access_token'] = $out['access_token']; $_SESSION['qq']['refresh_token'] = $out['refresh_token']; $_SESSION['open_platform_type'] = 'qq'; //验证授权 $r = OAuth::checkOAuthValid(); if ($r) { // header('Location: ' . $callback);//刷新页面 return true; } else { // exit('<h3>授权失败,请重试</h3>'); return false; } } else { exit($r); } } else { //获取授权code if ($_GET['openid'] && $_GET['openkey']) { //应用频道 $_SESSION['t_openid'] = $_GET['openid']; $_SESSION['t_openkey'] = $_GET['openkey']; //验证授权 $r = OAuth::checkOAuthValid(); if ($r) { // header('Location: ' . $callback);//刷新页面 return true; } else { // exit('<h3>授权失败,请重试</h3>'); return false; } } else { $url = OAuth::getAuthorizeURL($callback); header('Location: ' . $url); } } }
protected function sendData($jsonFormattedData) { /* * We can't use Solarium Client for that. * It doesn't support "updating" (only "replacing" allowed) * @see: http://wiki.solarium-project.org/index.php/V2:Update_query */ $options = []; $options['headers'] = ['Content-type' => 'application/json']; $options['postData'] = $jsonFormattedData; $options['returnInstance'] = true; $response = Http::request("POST", $this->getCommitUrl(), $options); return $response; }
/** * 接口调用的统一封装 * @param string $url 接口地址 * @param unknown $post_data post参数 * @param string $type 请求类型 * @throws Exception * @return Ambigous <multitype:, mixed> * @author yuanxiaolin@dachuwang.com */ public static function DoApi($url = '', $post_data = array(), $type = "GET", $cookie = array()) { $response = array(); if (empty($url)) { throw new Exception('url required,but empty be given'); } else { $full_respose = Http::request($url, $post_data, $type, $cookie); $response = json_decode($full_respose, TRUE); if ($response === null) { $log = self::LogInit(); $log::ERROR(sprintf('api call error|api_url:%s|api_back:%s', $url, $full_respose)); } } return $response != null ? $response : array(); }
protected function doPairs() { $pairs = array(); // BC for MW <= 1.24 $json = Http::request('GET', $this->config['pairs'], array('timeout' => $this->config['timeout'])); $response = FormatJson::decode($json); if (!is_object($response)) { $error = 'Malformed reply from remote server: ' . strval($json); throw new TranslationWebServiceException($error); } foreach ($response->responseData as $pair) { $source = $pair->sourceLanguage; $target = $pair->targetLanguage; $pairs[$source][$target] = true; } return $pairs; }
public function getThumbnailUrl() { $thumb = LegacyVideoApiWrapper::$THUMBNAIL_URL; $url = str_replace('$2', 'streams', static::$API_URL); $url = str_replace('$1', $this->videoId, $url); $content = Http::request('GET', $url, array('noProxy' => true)); if (!empty($content)) { $result = json_decode($content, true); if (isset($result['stream']['preview']['large'])) { $thumb = $result['stream']['preview']['large']; } else { if (isset($this->interfaceObj['video_banner'])) { $thumb = $this->interfaceObj['video_banner']; } } } return $thumb; }
protected function doPairs() { if (!isset($this->config['key'])) { throw new TranslationWebServiceException('API key is not set'); } $pairs = array(); $params = array('key' => $this->config['key']); $url = $this->config['pairs'] . '?' . wfArrayToCgi($params); // BC MW <= 1.24 $json = Http::request('GET', $url, array('timeout' => $this->config['timeout'])); $response = FormatJson::decode($json); if (!is_object($response)) { $exception = 'Malformed reply from remote server: ' . strval($json); throw new TranslationWebServiceException($exception); } foreach ($response->dirs as $pair) { list($source, $target) = explode('-', $pair); $pairs[$source][$target] = true; } return $pairs; }
protected function doPairs() { if (!isset($this->config['host'])) { throw new TranslationWebServiceException('Cxserver host not set'); } $pairs = array(); $url = $this->config['host'] . '/v1/list/mt'; // BC for MW <= 1.24 $json = Http::request('GET', $url, array($this->config['timeout'])); $response = FormatJson::decode($json, true); if (!is_array($response)) { $exception = 'Malformed reply from remote server: ' . strval($json); throw new TranslationWebServiceException($exception); } foreach ($response['Apertium'] as $source => $targets) { foreach ($targets as $target) { $pairs[$source][$target] = true; } } return $pairs; }
function actionReturn() { if ($_GET['code']) { //已获得code $code = $_GET['code']; $openid = $_GET['openid']; $openkey = $_GET['openkey']; //获取授权token $url = \OAuth::getAccessToken($code, $this->url); $access_token = $_SESSION['t_access_token']; $r = \Http::request($url); parse_str($r, $out); //存储授权数据 if ($out['access_token']) { $_SESSION['t_access_token'] = $out['access_token']; $_SESSION['t_expire_in'] = $out['expire_in']; $_SESSION['t_code'] = $code; $_SESSION['t_openid'] = $openid; $_SESSION['t_openkey'] = $openkey; //验证授权 $ret = \OAuth::checkOAuthValid(); $ret = \Tencent::api('user/info'); $uid_get = json_decode($ret, true); try { $uid = $uid_get['data']['openid']; $me['id'] = $uid; $me['name'] = $uid_get['data']['name']; $me['email'] = $uid_get['data']['email']; $me['nickname'] = $uid_get['data']['nick']; $r = $this->member_get_third_set_user($me, $this->oauth_id, $access_token); flash('success', __('login success')); $this->redirect(return_url()); } catch (OAuthException $e) { flash('error', __('login error')); $this->redirect(return_url()); } } } exit; }
public function execute() { $this->test = $this->hasOption('test'); $this->verbose = $this->hasOption('verbose'); echo "Checking " . F::app()->wg->Server . "\n"; if ($this->test) { echo "== TEST MODE ==\n"; } $this->debug("(debugging output enabled)\n"); $startTime = time(); $videos = VideoInfoHelper::getLocalVideoTitles(); $this->debug("Found " . count($videos) . " video(s)\n"); foreach ($videos as $origTitle) { $title = preg_replace('/_/', ' ', $origTitle); $url = "https://api.dailymotion.com/videos?search=" . urlencode($title) . '&fields=title,ads'; $json = Http::request('GET', $url); if ($json) { $resp = json_decode($json, true); if (isset($resp['list'])) { // Reduce titles to just letters and numbers $normalTitle = preg_replace('/[^a-zA-Z0-9]+/', '', $title); $list = $resp['list']; foreach ($list as $info) { // Reduce the matched titles to just letters and numbers $normalMatch = preg_replace('/[^a-zA-Z0-9]+/', '', $info['title']); // See if the normalized versions match if ($normalMatch == $normalTitle) { echo "{$origTitle}\t" . $info['title'] . "\t" . $info['ads'] . "\n"; continue; } } } } } $delta = F::app()->wg->lang->formatTimePeriod(time() - $startTime); echo "Finished after {$delta}\n"; }
/** * Get thumbnail from IVA * @global integer $failed * @global string $msg * @param string $sourceId * @return string|false $thumbnail */ function getVideoThumbnailIva($sourceId) { global $failed, $msg; $apiUrl = 'http://api.internetvideoarchive.com/1.0/DataService/VideoAssets($1)?$expand=$2&developerid=$3&$format=json'; $expand = array('VideoAssetScreenCapture'); $url = str_replace('$1', $sourceId, $apiUrl); $url = str_replace('$2', implode(',', $expand), $url); $url = str_replace('$3', F::app()->wg->IvaApiConfig['DeveloperId'], $url); print "Connecting to {$url}...\n"; $resp = Http::request('GET', $url, array('noProxy' => true)); if ($resp === false) { $failed++; print "{$msg}...FAILED (Error: Problem getting thumbnail from IVA. url:{$url}).\n"; return false; } // parse response $response = json_decode($resp, true); if (empty($response['d']['VideoAssetScreenCapture']['URL'])) { $thumbnail = ''; } else { $thumbnail = $response['d']['VideoAssetScreenCapture']['URL']; } return $thumbnail; }
public function callback() { es_session::start(); require_once APP_ROOT_PATH . 'system/api_login/Tencent/Tencent.php'; OAuth::init($this->api['config']['app_key'], $this->api['config']['app_secret']); $code = strim($_REQUEST['code']); $openid = strim($_REQUEST['openid']); $openkey = strim($_REQUEST['openkey']); if ($this->api['config']['app_url'] == "") { $app_url = get_domain() . APP_ROOT . "/api_callback.php?c=Tencent"; } else { $app_url = $this->api['config']['app_url']; } $token_url = OAuth::getAccessToken($code, $app_url); $result = Http::request($token_url); $result = preg_replace('/[^\\x20-\\xff]*/', "", $result); //清除不可见字符 $result = iconv("utf-8", "utf-8//ignore", $result); //UTF-8转码 parse_str($result, $result_arr); $access_token = $result_arr['access_token']; $refresh_token = $result_arr['refresh_token']; $name = $result_arr['name']; $nick = $result_arr['nick']; es_session::set("t_access_token", $access_token); es_session::set("t_openid", $openid); es_session::set("t_openkey", $openkey); if (es_session::get("t_access_token") || es_session::get("t_openid") && es_session::get("t_openkey")) { $r = Tencent::api('user/info'); $r = json_decode($r, true); if ($r['errcode'] != 0) { showErr("腾讯微博返回出错"); } //name,url,province,city,avatar,token,field,token_field(授权的字段),sex,secret_field(授权密码的字段),scret,url_field(微博地址的字段) $api_data['name'] = $r['data']['name']; $api_data['url'] = "http://t.qq.com/" . $r['data']['name']; $location = $r['data']['location']; $location = explode(" ", $location); $api_data['province'] = $location[1]; $api_data['city'] = $location[2]; $api_data['avatar'] = $r['data']['head']; $api_data['field'] = 'tencent_id'; $api_data['token'] = $access_token; $api_data['token_field'] = "tencent_token"; $api_data['secret'] = $openkey; $api_data['secret_field'] = "tencent_secret"; $api_data['url_field'] = "tencent_url"; if ($r['data']['sex'] == '1') { $api_data['sex'] = 1; } else { if ($r['data']['sex'] == '2') { $api_data['sex'] = 0; } else { $api_data['sex'] = -1; } } if ($api_data['name'] != "") { es_session::set("api_user_info", $api_data); } $user_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where tencent_id = '" . $openid . "' and tencent_id <> ''"); if ($user_data) { es_session::delete("api_user_info"); $GLOBALS['db']->query("update " . DB_PREFIX . "user set tencent_token = '" . $api_data['token'] . "',tencent_secret = '" . $api_data['secret'] . "',login_ip = '" . get_client_ip() . "',login_time= " . get_gmtime() . ",tencent_url = '" . $api_data['url'] . "' where id =" . $user_data['id']); update_user_weibo($user_data['id'], $api_data['url']); //更新微博 es_session::set("user_info", $user_data); app_redirect_preview(); } else { if ($GLOBALS['user_info']) { update_user_weibo($GLOBALS['user_info']['id'], $api_data['url']); //更新微博 $GLOBALS['db']->query("update " . DB_PREFIX . "user set tencent_id = '" . $openid . "',tencent_token = '" . $api_data['token'] . "',tencent_secret = '" . $api_data['secret'] . "',tencent_url = '" . $api_data['url'] . "' where id =" . intval($GLOBALS['user_info']['id'])); app_redirect(url("settings#bind")); } else { app_redirect(url("user#api_register")); } } } }
/** * Call out to IVA for the video metadata from the URL passed as $url * @param $url - The IVA URL to pull video metadata from * @return array|bool */ private function requestData($url) { print "Connecting to {$url}...\n"; $resp = Http::request('GET', $url, ['noProxy' => true]); if ($resp === false) { $this->logger->videoErrors("ERROR: problem downloading content.\n"); return false; } // parse response $response = json_decode($resp, true); return empty($response['d']['results']) ? [] : $response['d']['results']; }
/** * @param string $url * @param string $queryString * @return string * @throws \Exception */ public function doRequest($url, $queryString) { return $this->http->request($url . '?' . $queryString); }
/** * @param $url * @param $options * @return string */ protected function getUrlContent($url, $options = []) { $options = array_merge($options, $this->defaultRequestOptions); return Http::request('GET', $url, $options); }
/** * Get monetization units * @param array $params * @return array|false $result */ public function getMonetizationUnits($params) { wfProfileIn(__METHOD__); $log = WikiaLogger::instance(); $loggingParams = ['method' => __METHOD__, 'params' => $params]; // get data from cache for non page specific module only if (!$this->isPageSpecificRequest($params)) { $cacheKey = $this->getMemcKey($params); $log->debug("MonetizationModule: lookup with cache key: {$cacheKey}", $loggingParams); $json_results = $this->wg->Memc->get($cacheKey); if (!empty($json_results)) { $log->info("MonetizationModule: memcache hit.", $loggingParams); wfProfileOut(__METHOD__); return $this->processData($json_results, $params, false); } $log->info("MonetizationModule: memcache miss.", $loggingParams); } $url = $this->wg->MonetizationServiceUrl; if (!endsWith($url, '/')) { $url .= '/'; } $url .= self::API_DISPLAY . self::API_VERSION . '?' . http_build_query($params); $options = ['noProxy' => true]; $timeout = WikiFactory::getVarValueByName(self::VAR_NAME_API_TIMEOUT, WikiFactory::COMMUNITY_CENTRAL); if (!empty($timeout)) { $options['curlOptions'] = [CURLOPT_TIMEOUT_MS => $timeout, CURLOPT_NOSIGNAL => true]; } $method = 'GET'; $result = Http::request($method, $url, $options); if ($result === false) { $loggingParams['request'] = ['url' => $url, 'method' => $method, 'options' => $options]; $log->debug("MonetizationModule: cannot get monetization units.", $loggingParams); } else { if (!empty($result)) { $result = $this->processData($result, $params); } } wfProfileOut(__METHOD__); return $result; }
static function post($url, $timeout = 'default') { return Http::request("POST", $url, $timeout); }
/** * Submit the CueCompletion data, though in production the method will block * any requests without an HTTP_REFERER. * * @param string $assignmentId The assigment ID * @param string $answerText The answer text * @param string $videoUrl The video URL * @param string $videoThumbnail The video thumbnail URL * @param string $imageUrl The image URL * @param boolean $isAnonymous Is the CueCompletion anonymous? * * @return object Request response, decoded JSON. */ public function submitCueCompletion($assignmentId, $answerText = '', $videoUrl = '', $videoThumbnail = '', $imageUrl = '', $isAnonymous = false) { $method = 'POST'; $resource = '/cues/complete/'; $data = array('AssignmentID' => $assignmentId, 'AnswerText' => $answerText, 'VideoURL' => $videoUrl, 'VideoThumbnailURL' => $videoThumbnail, 'ImageURL' => $imageUrl, 'IsAnonymous' => $isAnonymous); return Http::request($this, $resource, $method, $data); }
public function callback() { OAuth::init($this->api['config']['app_key'], $this->api['config']['app_secret']); Tencent::$debug = $debug; $callback = SITE_DOMAIN . APP_ROOT . "/api_callback.php?c=Tencent"; if (es_session::is_set('t_access_token') || es_session::is_set('t_openid') && es_session::is_set('t_openkey')) { //用户已授权 //echo '<pre><h3>已授权</h3>用户信息:<br>'; //获取用户信息 $r = Tencent::api('user/info'); $json_data = json_decode($r, true); //print_r($json_data); // echo '</pre>'; } else { if ($_GET['code']) { //已获得code $code = $_GET['code']; $openid = $_GET['openid']; $openkey = $_GET['openkey']; //获取授权token $url = OAuth::getAccessToken($code, $callback); $r = Http::request($url); parse_str($r, $out); //存储授权数据 if ($out['access_token']) { es_session::set('t_access_token', $out['access_token']); es_session::set('refresh_token', $out['refresh_token']); es_session::set('expires_in', $out['expires_in']); es_session::set('t_code', $code); es_session::set('t_openid', $openid); es_session::set('t_openkey', $openkey); //验证授权 $r = OAuth::checkOAuthValid(); if ($r) { app_redirect($callback); //刷新页面 } else { exit('<h3>授权失败,请重试</h3>'); } } else { exit($r); } } else { //获取授权code if ($_GET['openid'] && $_GET['openkey']) { //应用频道 s_session::set('t_openid', $_GET['openid']); es_session::set('t_openkey', $_GET['openkey']); //验证授权 $r = OAuth::checkOAuthValid(); if ($r) { app_redirect($callback); //刷新页面 } else { exit('<h3>授权失败,请重试</h3>'); } } else { $url = OAuth::getAuthorizeURL($callback); app_redirect($url); } } } if ($json_data['msg'] != "ok") { echo '<pre><h3>出错了</h3><pre>'; die; } $is_bind = intval($_REQUEST['is_bind']); $tencent_id = $json_data['data']['openid']; $msg['field'] = 'tencent_id'; $msg['id'] = $tencent_id; $msg['name'] = $json_data['data']['name']; es_session::set("api_user_info", $msg); $user_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where tencent_id = '" . $tencent_id . "' and tencent_id <> ''"); if ($user_data) { $user_current_group = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_group where id = " . intval($user_data['group_id'])); $user_group = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_group where score <=" . intval($user_data['score']) . " order by score desc"); if ($user_current_group['score'] < $user_group['score']) { $user_data['group_id'] = intval($user_group['id']); } //$GLOBALS['db']->query("update ".DB_PREFIX."user set tencent_app_key ='".$last_key['oauth_token']."',tencent_app_secret = '".$last_key['oauth_token_secret']."', login_ip = '".get_client_ip()."',login_time= ".TIME_UTC.",group_id=".intval($user_data['group_id'])." where id =".$user_data['id']); //$GLOBALS['db']->query("update ".DB_PREFIX."deal_cart set user_id = ".intval($user_data['id'])." where session_id = '".es_session::id()."'"); es_session::delete("api_user_info"); if ($is_bind) { if (intval($user_data['id']) != intval($GLOBALS['user_info']['id'])) { showErr("该帐号已经被别的会员绑定过,请直接用帐号登录", 0, url("shop", "uc_center#setweibo")); } else { es_session::set("user_info", $user_data); app_redirect(url("shop", "uc_center#setweibo")); } } else { es_session::set("user_info", $user_data); app_recirect_preview(); } } elseif ($is_bind == 1 && $GLOBALS['user_info']) { //当有用户身份且要求绑定时 $GLOBALS['db']->query("update " . DB_PREFIX . "user set tencent_id= '" . $tencent_id . "' where id =" . $GLOBALS['user_info']['id']); app_redirect(url("index", "uc_center#setweibo")); } else { $this->create_user(); //app_redirect(url("index","user#api_login")); app_recirect_preview(); } }
public function callback() { es_session::start(); require_once APP_ROOT_PATH . 'system/api_login/Tencent/Tencent.php'; OAuth::init($this->api['config']['app_key'], $this->api['config']['app_secret']); $code = trim(addslashes($_REQUEST['code'])); $openid = trim(addslashes($_REQUEST['openid'])); $openkey = trim(addslashes($_REQUEST['openkey'])); if ($this->api['config']['app_url'] == "") { $app_url = get_domain() . APP_ROOT . "/api_callback.php?c=Tencent"; } else { $app_url = $this->api['config']['app_url']; } $token_url = OAuth::getAccessToken($code, $app_url); $result = Http::request($token_url); $result = preg_replace('/[^\\x20-\\xff]*/', "", $result); //清除不可见字符 $result = iconv("utf-8", "utf-8//ignore", $result); //UTF-8转码 parse_str($result, $result_arr); $access_token = $result_arr['access_token']; $refresh_token = $result_arr['refresh_token']; $name = $result_arr['name']; $nick = $result_arr['nick']; $is_bind = intval(es_session::get("is_bind")); es_session::set("t_access_token", $access_token); es_session::set("t_openid", $openid); es_session::set("t_openkey", $openkey); if (es_session::get("t_access_token") || es_session::get("t_openid") && es_session::get("t_openkey")) { $msg['field'] = 'tencent_id'; $msg['id'] = $name; $msg['name'] = $name; $msg['t_access_token'] = $access_token; $msg['t_openid'] = $access_token; $msg['t_openkey'] = $openkey; es_session::set("api_user_info", $msg); if (!$msg['name']) { app_redirect(url("index")); } $user_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where tencent_id = '" . $name . "' and tencent_id <> ''"); if ($user_data) { $user_current_group = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_group where id = " . intval($user_data['group_id'])); $user_group = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_group where score <=" . intval($user_data['score']) . " order by score desc"); if ($user_current_group['score'] < $user_group['score']) { $user_data['group_id'] = intval($user_group['id']); } $GLOBALS['db']->query("update " . DB_PREFIX . "user set t_access_token ='" . $access_token . "',t_openkey = '" . $openkey . "',t_openid = '" . $openid . "', login_ip = '" . get_client_ip() . "',login_time= " . get_gmtime() . ",group_id=" . intval($user_data['group_id']) . " where id =" . $user_data['id']); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_cart set user_id = " . intval($user_data['id']) . " where session_id = '" . es_session::id() . "'"); require_once APP_ROOT_PATH . "system/libs/user.php"; auto_do_login_user($user_data['user_name'], $user_data['user_pwd'], $from_cookie = false); es_session::delete("api_user_info"); app_recirect_preview(); } else { $this->create_user(); app_redirect(url("shop", "user#stepone")); } } }
/** * Simple wrapper for Http::request( 'POST' ) * @see Http::request() * * @param $url * @param $options array * @return string */ public static function post( $url, $options = array() ) { return Http::request( 'POST', $url, $options ); }
/** * Simple wrapper for Http::request( 'POST' ) * @see Http::request() * * @param string $url * @param array $options * @param string $caller The method making this request, for profiling * @return string|bool false on error */ public static function post($url, $options = [], $caller = __METHOD__) { return Http::request('POST', $url, $options, $caller); }
function runHTTPRequests($proxy = null) { $opt = array(); if ($proxy) { $opt['proxy'] = $proxy; } elseif ($proxy === false) { $opt['noProxy'] = true; } /* no postData here because the only request I could find in code so far didn't have any */ foreach ($this->test_requesturl as $u) { $r = Http::request("POST", $u, $opt); $this->assertEquals(self::$content["POST {$u}"], "{$r}", "POST {$u} with " . Http::$httpEngine); } }
/** * * @param mixed $url * @param mixed $args * @param mixed $response * @return */ public static function handle_redirects($url, $args, $response) { static $nv_http; // If no redirects are present, or, redirects were not requested, perform no action. if (!isset($response['headers']['location']) or $args['redirection'] === 0) { return false; } // Only perform redirections on redirection http codes if ($response['response']['code'] > 399 or $response['response']['code'] < 300) { return false; } // Don't redirect if we've run out of redirects if ($args['redirection']-- <= 0) { $this->set_error(5); return false; } $redirect_location = $response['headers']['location']; // If there were multiple Location headers, use the last header specified if (is_array($redirect_location)) { $redirect_location = array_pop($redirect_location); } $redirect_location = Http::make_absolute_url($redirect_location, $url); // POST requests should not POST to a redirected location if ($args['method'] == 'POST') { if (in_array($response['response']['code'], array(302, 303))) { $args['method'] = 'GET'; } } // Include valid cookies in the redirect process if (!empty($response['cookies'])) { foreach ($response['cookies'] as $cookie) { if ($cookie->test($redirect_location)) { $args['cookies'][] = $cookie; } } } // Create object if null if (is_null($nv_http)) { $nv_http = new Http(); } return $nv_http->request($redirect_location, $args); }
private function doTestGetFileHttpUrl($source, $content) { $backendName = $this->backendClass(); $this->prepare(array('dir' => dirname($source))); $status = $this->backend->doOperation(array('op' => 'create', 'content' => $content, 'dst' => $source)); $this->assertGoodStatus($status, "Creation of file at {$source} succeeded ({$backendName})."); $url = $this->backend->getFileHttpUrl(array('src' => $source)); if ($url !== null) { // supported $data = Http::request("GET", $url); $this->assertEquals($content, $data, "HTTP GET of URL has right contents ({$backendName})."); } }
/** * 此为PHP-SDK 2.0 */ require_once BASE_DATA_PATH . DS . 'api' . DS . 'snsapi' . DS . 'qqweibo' . DS . 'tencent.php'; require_once BASE_DATA_PATH . DS . 'api' . DS . 'snsapi' . DS . 'qqweibo' . DS . 'config.php'; OAuth::init($client_id, $client_secret); Tencent::$debug = $debug; if ($_GET['code']) { //已获得code $code = $_GET['code']; $openid = $_GET['openid']; $openkey = $_GET['openkey']; //获取授权token $url = OAuth::getAccessToken($code, $callback); $r = Http::request($url); parse_str($r, $out); //存储授权数据 if ($out['access_token']) { $_SESSION['qqweibo']['t_access_token'] = $out['access_token']; $_SESSION['qqweibo']['t_expire_in'] = $out['expires_in']; $_SESSION['qqweibo']['t_refresh_token'] = $out['refresh_token']; $_SESSION['qqweibo']['t_uname'] = $out['name']; $_SESSION['qqweibo']['t_code'] = $code; $_SESSION['qqweibo']['t_openid'] = $openid; //OpenID可以唯一标识一个用户。在同一个应用下,同一个QQ号码的OpenID是相同的;但在不同应用下,同一个QQ号码可能有不同的OpenID $_SESSION['qqweibo']['t_openkey'] = $openkey; //OpenKey是与OpenID对应的用户key(用户在第三方应用的腾讯登录态),是验证OpenID身份的验证密钥,大多数API的访问,都需要同时具备OpenID和OpenKey的信息,其有效期为2小时 //验证授权 $r = OAuth::checkOAuthValid(); if ($r) {
/** * @param string $url * @param string $method * @return Status */ static function newFromURL($url, $method = 'GET') { wfDebug(__METHOD__ . ": opening {$url}\n"); # Use the standard HTTP fetch function; it times out # quicker and sorts out user-agent problems which might # otherwise prevent importing from large sites, such # as the Wikimedia cluster, etc. $data = Http::request($method, $url, array('followRedirects' => true), __METHOD__); if ($data !== false) { $file = tmpfile(); fwrite($file, $data); fflush($file); fseek($file, 0); return Status::newGood(new ImportStreamSource($file)); } else { return Status::newFatal('importcantopen'); } }
/** * 发起一个腾讯API请求 * @param $command 接口名称 如:t/add * @param $params 接口参数 array('content'=>'test'); * @param $method 请求方式 POST|GET * @param $multi 图片信息 * @return string */ public static function api($command, $params = array(), $method = 'GET', $multi = false) { if (es_session::is_set("t_access_token")) { //OAuth 2.0 方式 //鉴权参数 $params['access_token'] = es_session::get("t_access_token"); $params['oauth_consumer_key'] = OAuth::$client_id; $params['openid'] = es_session::get("t_openid"); $params['oauth_version'] = '2.a'; $params['clientip'] = Common::getClientIp(); $params['scope'] = 'all'; $params['appfrom'] = 'php-sdk2.0beta'; $params['seqid'] = time(); $params['serverip'] = $_SERVER['SERVER_ADDR']; $url = self::$apiUrlHttps . trim($command, '/'); } elseif (es_session::is_set("t_openid") && es_session::is_set("t_openkey")) { //openid & openkey方式 $params['appid'] = OAuth::$client_id; $params['openid'] = es_session::get("t_openid"); $params['openkey'] = es_session::get("t_openkey"); $params['clientip'] = Common::getClientIp(); $params['reqtime'] = time(); $params['wbversion'] = '1'; $params['pf'] = 'php-sdk2.0beta'; $url = self::$apiUrlHttp . trim($command, '/'); //生成签名 $urls = @parse_url($url); $sig = SnsSign::makeSig($method, $urls['path'], $params, OAuth::$client_secret . '&'); $params['sig'] = $sig; } //请求接口 $r = Http::request($url, $params, $method, $multi); /* $http = new Http2(); $r = $http->request($url, $method, $params, $multi); */ $r = preg_replace('/[^\\x20-\\xff]*/', "", $r); //清除不可见字符 $r = iconv("utf-8", "utf-8//ignore", $r); //UTF-8转码 //调试信息 if (self::$debug) { echo '<pre>'; echo '接口:' . $url; echo '<br>请求参数:<br>'; print_r($params); echo '返回结果:' . $r; echo '</pre>'; } return $r; }