Skip to content

Commit

Permalink
add purview and curl request
Browse files Browse the repository at this point in the history
add purview and curl request
  • Loading branch information
hisune committed Jul 23, 2015
1 parent f0e4d13 commit 326492c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Tiny/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public static function hasPurview($controller = null, $method = null)
}

$purview = self::getPurviewCache();
if(!$purview && Config::$authPurviewMethod){
$class = Config::$authPurviewMethod['0'];
$call = Config::$authPurviewMethod['1'];
$class::$call();
}

$white = property_exists($ctr, 'authWhite') && isset($ctr::$authWhite['purview']) ? $ctr::$authWhite['purview'] : array();
if(
Expand Down
1 change: 1 addition & 0 deletions Tiny/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ abstract class Config
static $error404 = array(); // array('Controller', 'method')
static $secret = '8RtX*K#%Gw=5VEQ=VT';
static $authPurview = false; // 是否验证权限
static $authPurviewMethod = false; // 自动更新权限的方法

public static function __callStatic($method, $args = array())
{
Expand Down
62 changes: 62 additions & 0 deletions Tiny/Curl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Created by Hisune.
* User: [email protected]
* Date: 2015/7/2
* Time: 11:18
*/
namespace Tiny;

class Curl
{
static public function request($url, $params = array(), $method = 'get', $protocol = 'http'){
$query_string = '';
if(is_array($params)){
$query_string = http_build_query($params);
}elseif(is_string($params)){
$query_string = $params;
}
$ch = curl_init();
if('get' == $method){
curl_setopt($ch, CURLOPT_URL, $url.'?'.$query_string);
}else{
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
}

curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); // disable 100-continue

if('https' == $protocol){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}

$ret = curl_exec($ch);
$err = curl_error($ch);

if(false === $ret || !empty($err)){
$errno = curl_errno($ch);
$info = curl_getinfo($ch);
curl_close($ch);

return array(
'result' => false,
'errno' => $errno,
'msg' => $err,
'info' => $info,
);
}

curl_close($ch);

return array(
'result' => true,
'msg' => $ret,
);
}
}

0 comments on commit 326492c

Please sign in to comment.