コード例 #1
0
    $server = $authenticateForRole();
    $dbstorage = $diy_storage();
    if (!$server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
        $server->getResponse()->send();
        die;
    } else {
        $crypto_token = OAuth2\Request::createFromGlobals()->query["access_token"];
        $separator = '.';
        list($header, $payload, $signature) = explode($separator, $crypto_token);
        //echo base64_decode($payload);
        $params["payload"] = $payload;
        $params["storage"] = $dbstorage;
        $result = diy_removedevice($params["payload"], $params["storage"], $params["test"]);
        PrepareResponse();
        //$result["result"]=  var_export(OAuth2\Request::createFromGlobals(),true);
        $app->response()->setBody(toGreek(json_encode($result)));
    }
});
function diy_removedevice($payload, $storage)
{
    global $app;
    $result["controller"] = __FUNCTION__;
    $result["function"] = substr($app->request()->getPathInfo(), 1);
    $result["method"] = $app->request()->getMethod();
    $params = loadParameters();
    $result->function = substr($app->request()->getPathInfo(), 1);
    $result->method = $app->request()->getMethod();
    //$params = loadParameters();
    $up = json_decode(base64_decode($payload));
    $client_id = $up->client_id;
    $userscope = $up->scope;
コード例 #2
0
ファイル: index.php プロジェクト: pantnik/DIYiotServer
//=========================  HELPER ==================================
//function not found
$app->notFound(function () use($app) {
    $controller = $app->environment();
    $controller = substr($controller["PATH_INFO"], 1);
    try {
        if (!in_array(strtoupper($app->request()->getMethod()), array(MethodTypes::GET, MethodTypes::POST, MethodTypes::PUT, MethodTypes::DELETE))) {
            throw new Exception(ExceptionMessages::MethodNotFound, ExceptionCodes::MethodNotFound);
        } else {
            throw new Exception(ExceptionMessages::FunctionNotFound, ExceptionCodes::FunctionNotFound);
        }
    } catch (Exception $e) {
        $result["status"] = $e->getCode();
        $result["message"] = "[" . $app->request()->getMethod() . "][" . $controller . "]:" . $e->getMessage();
    }
    echo toGreek(json_encode($result));
});
$app->run();
//=========================================================================
function PrepareResponse()
{
    global $app;
    $app->contentType('application/json');
    $app->response()->headers()->set('Content-Type', 'application/json; charset=utf-8');
    $app->response()->headers()->set('X-Powered-By', 'DIYiot Tools');
    $app->response()->setStatus(200);
}
function UrlParamstoArray($params)
{
    $items = array();
    foreach (explode('&', $params) as $chunk) {