public function show() { $condition = $this->get_condition(); $offset = $this->input['offset'] ? intval($this->input['offset']) : 0; $count = $this->input['count'] ? intval($this->input['count']) : 20; $limit = " LIMIT " . $offset . "," . $count; $order = " ORDER BY id DESC"; $sql = "SELECT pu.*,t.access_token,t.openid,t.addtime,p.name plat_name FROM " . DB_PREFIX . "plat_user pu " . "LEFT JOIN " . DB_PREFIX . "token t " . "ON pu.token = t.token " . "LEFT JOIN " . DB_PREFIX . "plat p " . "ON pu.platId = p.id " . "WHERE 1 " . $condition . $order . $limit; $q = $this->db->query($sql); while (false != ($row = $this->db->fetch_array($q))) { $row['access_token'] = json_decode($row['access_token'], 1); $row['expired'] = !check_token_time($row['addtime'], $row['access_token']['expires_in']); $row['expired_time'] = date('Y-m-d H:i', $row['addtime'] + $row['access_token']['expires_in']); $row['create_time'] = date('Y-m-d H:i', $row['create_time']); if ($row['avatar']) { $row['avatar'] = array('host' => $row['avatar'], 'dir' => '', 'filepath' => '', 'filename' => ''); } $row['mode_type'] = $row['mode_type'] ? unserialize($row['mode_type']) : array(); $this->addItem($row); } $this->output(); }
public function check_access_token() { $access_plat_token = $this->input['access_plat_token']; if (!$access_plat_token) { $this->errorOutput('NO_ACCESS_PLAT_TOKEN'); } $sql = "SELECT * FROM " . DB_PREFIX . "token WHERE token='" . $access_plat_token . "'"; $info = $this->db->query_first($sql); if (!$info) { $this->errorOutput('NO_INFO'); } if (!$info['access_token']) { $this->errorOutput('NO_ACCESS_TOKEN'); } $info['access_token'] = unserialize($info['access_token']); if (check_token_time($info['addtime'], $info['access_token']['expires_in'])) { $this->addItem('success'); } else { $this->addItem('faild'); } $this->output(); }
public function get_auth_user() { $token = urldecode($this->input['access_plat_token']); if (!$token) { $this->errorOutput('NO_ACCESS_PLAT_TOKEN'); } $checktoken = $this->pub->share_check_token($token); if (empty($checktoken['data']['access_token'])) { $this->errorOutput('NO_PLAT_DATA'); } if (!empty($checktoken['data']['access_token']['uid'])) { $uid = $checktoken['data']['access_token']['uid']; } else { if (!empty($checktoken['data']['access_token']['name'])) { $name = $checktoken['data']['access_token']['name']; } } if (!$uid && !$name) { $this->errorOutput('NO_USER_DATA'); } if ($checktoken['data']['addtime'] || $checktoken['data']['access_token']) { $expired = !check_token_time($checktoken['data']['token_addtime'], $checktoken['data']['access_token']['expires_in']); $expired_time = $checktoken['data']['token_addtime'] + $checktoken['data']['access_token']['expires_in']; } else { $expired = true; } $sql = "SELECT * FROM " . DB_PREFIX . "auth_user WHERE plat_type=" . $checktoken['data']['type']; if ($uid) { $sql .= " AND uid='" . $uid . "'"; } if ($name) { $sql .= " AND name='" . $name . "'"; } $ret = $this->db->query_first($sql); if (!empty($ret)) { $ret['plat_name'] = $checktoken['data']['name']; $ret['access_plat_token'] = $token; $expired_time ? $ret['expired_time'] = $expired_time : ''; $ret['expired'] = $expired; } $this->addItem($ret); $this->output(); }