add groups api

This commit is contained in:
候学杰 2018-05-15 11:59:57 +08:00
parent a0ed6da24d
commit 60d1029134

View File

@ -2,6 +2,8 @@
namespace PdAuth; namespace PdAuth;
use PdAuth\Middleware\Authenticate;
class OAuth class OAuth
{ {
@ -38,24 +40,31 @@ class OAuth
/** /**
* 根据用户token获取用户信息 * 根据用户token获取用户信息
* @param $username
* @param $token * @param $token
* @return array|null * @return null
*/ */
public function getUserInfo($token) public function getUserInfo($token)
{ {
$token = urlencode($token); $token = urlencode($token);
$resp = $this->get("$this->host/api/user_info?access_token=$token"); $resp = $this->get("$this->host/api/user/info?access_token=$token");
if ($resp['code'] == 0) { if ($resp['code'] == 0) {
return $resp['data']; return $resp['data'];
} }
return null; return null;
} }
public function getGroups($token) /**
* 获取用户组
* @param null $token
* @return null
*/
public function getGroupUsers($token = null)
{ {
if ($token == null) {
$token = $_COOKIE[Authenticate::CookieName];
}
$token = urlencode($token); $token = urlencode($token);
$resp = $this->get("$this->host/api/{$this->id}/groups?access_token=$token"); $resp = $this->get("$this->host/api/group/users?access_token=$token");
if ($resp['code'] == 0) { if ($resp['code'] == 0) {
return $resp['data']; return $resp['data'];
} }