Oauth接口驱动异常抛出添加命名空间

This commit is contained in:
麦当苗儿
2013-04-16 11:20:06 +08:00
parent 20741c2376
commit 447ba097ea
16 changed files with 29 additions and 29 deletions

View File

@@ -77,16 +77,16 @@ abstract class Driver {
* @param array $config
*/
public function __construct($config = []){
$this->appKey = $config['app_key'];
$this->appSecret = $config['app_secret'];
$this->authorize = isset($config['authorize'])?$config['authorize']:'';
$this->callback = isset($config['callback'])?$config['callback']:'';
$this->appKey = $config['app_key'];
$this->appSecret = $config['app_secret'];
$this->authorize = isset($config['authorize']) ? $config['authorize'] : '';
$this->callback = isset($config['callback']) ? $config['callback'] : '';
}
// 跳转到授权登录页面
public function login($callback=''){
public function login($callback = ''){
if($callback) {
$this->callback = $callback;
$this->callback = $callback;
}
//跳转到授权页面
header('Location: ' . $this->getRequestCodeURL());
@@ -110,7 +110,7 @@ abstract class Driver {
if(is_array($_param)){
$params = array_merge($params, $_param);
} else {
throw new Exception('AUTHORIZE配置不正确');
throw new \Exception('AUTHORIZE配置不正确');
}
}
return $this->getRequestCodeURL . '?' . http_build_query($params);
@@ -194,7 +194,7 @@ abstract class Driver {
$opts[CURLOPT_POSTFIELDS] = $params;
break;
default:
throw new Exception('不支持的请求方式!');
throw new \Exception('不支持的请求方式!');
}
/* 初始化并执行curl请求 */
@@ -203,7 +203,7 @@ abstract class Driver {
$data = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if($error) throw new Exception('请求发生错误:' . $error);
if($error) throw new \Exception('请求发生错误:' . $error);
return $data;
}

View File

@@ -58,7 +58,7 @@ class Baidu extends Driver{
$data['openid'] = $this->openid();
return $data;
} else
throw new Exception("获取百度ACCESS_TOKEN出错{$data['error']}");
throw new \Exception("获取百度ACCESS_TOKEN出错{$data['error']}");
}
/**
@@ -86,7 +86,7 @@ class Baidu extends Driver{
$userInfo['avatar'] = "http://tb.himg.baidu.com/sys/portrait/item/{$data['portrait']}";
return $userInfo;
} else {
throw new Exception("获取百度用户信息失败:{$data['error_msg']}");
throw new \Exception("获取百度用户信息失败:{$data['error_msg']}");
}
}

View File

@@ -59,7 +59,7 @@ class Diandian extends Driver{
unset($data['uid']);
return $data;
} else
throw new Exception("获取点点网ACCESS_TOKEN出错{$data['error']}");
throw new \Exception("获取点点网ACCESS_TOKEN出错{$data['error']}");
}
/**

View File

@@ -57,7 +57,7 @@ class Douban extends Driver{
unset($data['douban_user_id']);
return $data;
} else
throw new Exception("获取豆瓣ACCESS_TOKEN出错{$data['msg']}");
throw new \Exception("获取豆瓣ACCESS_TOKEN出错{$data['msg']}");
}
/**

View File

@@ -57,7 +57,7 @@ class Github extends Driver{
$data['openid'] = $this->getOpenId();
return $data;
} else
throw new Exception("获取 Github ACCESS_TOKEN出错未知错误");
throw new \Exception("获取 Github ACCESS_TOKEN出错未知错误");
}
/**

View File

@@ -63,7 +63,7 @@ class Google extends Driver{
$data['openid'] = $this->getOpenId();
return $data;
} else
throw new Exception("获取 Google ACCESS_TOKEN出错未知错误");
throw new \Exception("获取 Google ACCESS_TOKEN出错未知错误");
}
/**

View File

@@ -58,7 +58,7 @@ class Kaixin extends Driver{
$data['openid'] = $this->getOpenId();
return $data;
} else
throw new Exception("获取开心网ACCESS_TOKEN出错{$data['error']}");
throw new \Exception("获取开心网ACCESS_TOKEN出错{$data['error']}");
}
/**

View File

@@ -64,7 +64,7 @@ class Msn extends Driver{
$data['openid'] = $this->getOpenId();
return $data;
} else
throw new Exception("获取 MSN ACCESS_TOKEN出错未知错误");
throw new \Exception("获取 MSN ACCESS_TOKEN出错未知错误");
}
/**

View File

@@ -67,7 +67,7 @@ class Qq extends Driver{
$data['openid'] = $this->getOpenId();
return $data;
} else
throw new Exception("获取腾讯QQ ACCESS_TOKEN 出错:{$result}");
throw new \Exception("获取腾讯QQ ACCESS_TOKEN 出错:{$result}");
}
/**

View File

@@ -83,7 +83,7 @@ class Renren extends Driver{
unset($data['user']);
return $data;
} else
throw new Exception("获取人人网ACCESS_TOKEN出错{$data['error_description']}");
throw new \Exception("获取人人网ACCESS_TOKEN出错{$data['error_description']}");
}
/**

View File

@@ -38,13 +38,13 @@ class Sina extends Driver{
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET'){
public function call($api, $param = '', $method = 'GET', $multi = false){
/* 新浪微博调用公共参数 */
$params = array(
'access_token' => $this->token['access_token'],
);
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method);
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method, $multi);
return json_decode($data, true);
}
@@ -59,7 +59,7 @@ class Sina extends Driver{
unset($data['uid']);
return $data;
} else
throw new Exception("获取新浪微博ACCESS_TOKEN出错{$data['error']}");
throw new \Exception("获取新浪微博ACCESS_TOKEN出错{$data['error']}");
}
/**

View File

@@ -59,7 +59,7 @@ class Sohu extends Driver{
unset($data['open_id']);
return $data;
} else
throw new Exception("获取搜狐ACCESS_TOKEN出错{$data['error']}");
throw new \Exception("获取搜狐ACCESS_TOKEN出错{$data['error']}");
}
/**

View File

@@ -59,7 +59,7 @@ class T163 extends Driver{
unset($data['uid']);
return $data;
} else
throw new Exception("获取网易微博ACCESS_TOKEN出错{$data['error']}");
throw new \Exception("获取网易微博ACCESS_TOKEN出错{$data['error']}");
}
/**

View File

@@ -61,7 +61,7 @@ class Taobao extends Driver{
unset($data['taobao_user_id']);
return $data;
} else
throw new Exception("获取淘宝网ACCESS_TOKEN出错{$data['error']}");
throw new \Exception("获取淘宝网ACCESS_TOKEN出错{$data['error']}");
}
/**

View File

@@ -38,7 +38,7 @@ class Tencent extends Driver{
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET'){
public function call($api, $param = '', $method = 'GET', $multi = false){
/* 腾讯微博调用公共参数 */
$params = array(
'oauth_consumer_key' => $this->AppKey,
@@ -50,7 +50,7 @@ class Tencent extends Driver{
'format' => 'json'
);
$data = $this->http($this->url($api), $this->param($params, $param), $method);
$data = $this->http($this->url($api), $this->param($params, $param), $method, $multi);
return json_decode($data, true);
}
@@ -64,7 +64,7 @@ class Tencent extends Driver{
if($data['access_token'] && $data['expires_in'] && $data['openid'])
return $data;
else
throw new Exception("获取腾讯微博 ACCESS_TOKEN 出错:{$result}");
throw new \Exception("获取腾讯微博 ACCESS_TOKEN 出错:{$result}");
}
/**

View File

@@ -58,7 +58,7 @@ class X360 extends Driver{
$data['openid'] = $this->getOpenId();
return $data;
} else
throw new Exception("获取360开放平台ACCESS_TOKEN出错{$data['error']}");
throw new \Exception("获取360开放平台ACCESS_TOKEN出错{$data['error']}");
}
/**