示例#1
0
function api_call($method, $args = array())
{
    $team = $GLOBALS['data']->get('metadata', 'team');
    $url = $GLOBALS['cfg']['slack_root'] . "api/" . $method . "?token=" . $team['token'];
    foreach ($args as $k => $v) {
        $url .= '&' . urlencode($k) . '=' . urlencode($v);
    }
    $ret = SlackHTTP::get($url);
    if ($ret['ok'] && $ret['code'] == '200') {
        return array('ok' => true, 'data' => json_decode($ret['body'], true));
    }
    return $ret;
}
    }
} else {
    echo "problem with oauth.access call";
    dumper($ret);
    exit;
}
if ($_GET['debug']) {
    echo "debug mode:";
    dumper($obj);
    exit;
}
#
# fetch user info
#
$url = $cfg['slack_root'] . "api/auth.test?token={$token}";
$ret = SlackHTTP::get($url);
if ($ret['ok'] && $ret['code'] == '200') {
    $obj = json_decode($ret['body'], true);
} else {
    echo "problem with auth.test call";
    dumper($ret);
    exit;
}
$info = $obj;
unset($info['ok']);
$info['access_token'] = $token;
$info['secret'] = substr(md5(rand()), 0, 10);
$cookie = $info['user_id'] . '-' . $info['secret'];
$expire = time() + 365 * 24 * 60 * 60;
setcookie($cfg['cookie_name'], $cookie, $expire, $cfg['cookie_path'], $cfg['cookie_domain'], isset($_SERVER["HTTPS"]), true);
$data->set('users', $info['user_id'], $info);