本文整理汇总了PHP中Http::request方法的典型用法代码示例。如果您正苦于以下问题:PHP Http::request方法的具体用法?PHP Http::request怎么用?PHP Http::request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Http
的用法示例。
在下文中一共展示了Http::request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: shouquan
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);
}
}
}
示例2: request
/**
* 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;
}
示例3: testRequest_return_response_instance
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]));
}
示例4: checkUser
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);
}
}
}
示例5: sendData
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;
}
示例6: DoApi
/**
* 接口调用的统一封装
* @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();
}
示例7: doPairs
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;
}
示例8: getThumbnailUrl
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;
}
示例9: doPairs
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;
}
示例10: doPairs
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;
}
示例11: actionReturn
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;
}
示例12: execute
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";
}
示例13: getVideoThumbnailIva
/**
* 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;
}
示例14: callback
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"));
}
}
}
}
示例15: requestData
/**
* 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'];
}