예제 #1
0
$app->post('/messages', function (Request $request) use($app) {
    $data = $app->validateRequestAsJson($request);
    $username = isset($data['username']) ? $data['username'] : '';
    $body = isset($data['body']) ? $data['body'] : '';
    if (strcmp($username, 'image') == 0) {
        //Consumer Key
        $app_key = CONSUMER_KEY;
        //Consumer Secret
        $app_secret = CONSUMER_SECRET;
        //インスタンスを作成する
        $flickr = new phpFlickr($app_key, $app_secret);
        //検索ワードの指定
        $keyword = $body;
        //取得件数の指定
        $count = 1;
        //オプションの設定
        $option = array("text" => $keyword, "per_page" => $count, "extras" => "url_m", "safe_search" => 1);
        //検索を実行し、取得したデータを[$result]に代入する
        $result = $flickr->photos_search($option);
        var_dump($result);
        //[$result]をJSONに変換する
        $json = json_encode($result);
        var_dump($json);
        //JSONをオブジェクト型に変換する
        $obj = json_decode($json);
        var_dump($obj);
        //ループ処理
        foreach ($obj->photo as $photo) {
            //データの整理
            $body = $photo->url_m;
            //画像ファイルのURL
            //出力する
            //echo '<img src="' . $src . '" width="' . $width . '" height="' . $height . '"/><br/>';
            $createdMessage = $app->createMessage($username, $body, base64_encode(file_get_contents($app['icon_image_path'])));
        }
        return $app->json($createdMessage);
    } else {
        //bodyの内容がuranaiだったら
        if (strcmp($body, 'uranai') == 0) {
            //占い結果を擬似乱数で作成
            $randint = rand(1, 10);
            if ($randint < 3) {
                //凶
                $body = '凶';
            } else {
                if ($randint < 8) {
                    //吉
                    $body = '吉';
                } else {
                    if ($randint <= 10) {
                        //大吉
                        $body = '大吉';
                    }
                }
            }
            $username = '******';
            //username = "******", body = 占い結果 に書き換える
        }
        $createdMessage = $app->createMessage($username, $body, base64_encode(file_get_contents($app['icon_image_path'])));
        return $app->json($createdMessage);
    }
});
예제 #2
0
$app->post('/messages', function (Request $request) use($app) {
    $data = $app->validateRequestAsJson($request);
    $username = isset($data['username']) ? $data['username'] : '';
    $body = isset($data['body']) ? $data['body'] : '';
    if ($body == "uranai") {
        $kekka = mt_rand(1, 6);
        if ($kekka == 1) {
            $kekka = "大吉";
        } else {
            if ($kekka == 2) {
                $kekka = "吉";
            } else {
                if ($kekka == 3) {
                    $kekka = "中吉";
                } else {
                    if ($kekka == 4) {
                        $kekka = "小吉";
                    } else {
                        if ($kekka == 5) {
                            $kekka = "凶";
                        } else {
                            $kekka = "大凶";
                        }
                    }
                }
            }
        }
        $createdMessage = $app->createMessage("bot", $kekka, base64_encode(file_get_contents($app['icon_image_path'])));
    } else {
        $createdMessage = $app->createMessage($username, $body, base64_encode(file_get_contents($app['icon_image_path'])));
    }
    return $app->json($createdMessage);
});
예제 #3
0
    $messages = $app->getAllMessages();

    return $app->json($messages);
});

$app->get('/messages/{id}', function ($id) use ($app) {
    $message = $app->getMessage($id);

    return $app->json($message);
});

$app->post('/messages', function (Request $request) use ($app) {
    $data = $app->validateRequestAsJson($request);

    $username = isset($data['username']) ? $data['username'] : '';
    $body = isset($data['body']) ? $data['body'] : '';

    $createdMessage = $app->createMessage($username, $body, base64_encode(file_get_contents($app['icon_image_path'])));

    return $app->json($createdMessage);
});

$app->delete('/messages/{id}', function ($id) use ($app) {
    $app->deleteMessage($id);

    return new Response('', Response::HTTP_NO_CONTENT, [
        'Access-Control-Allow-Origin' => '*',
    ]);
});

$app->options('/messages/{id}', function ($id) use ($app) {
    return new Response('', Response::HTTP_NO_CONTENT, [
예제 #4
0
});

$app->post('/messages', function (Request $request) use ($app) {
    $data = $app->validateRequestAsJson($request);

    $username = isset($data['username']) ? $data['username'] : '';
    $body = isset($data['body']) ? $data['body'] : '';

    //bodyの内容がuranaiだったら
    if(strcmp($body,'uranai') == 0){
        //占い結果を擬似乱数で作成
        $randint = rand(1,10);
        if($randint < 3){
            //凶
            $body = '凶';
        }else if($randint < 8){
            //吉
            $body = '吉';
        }else if($randint <= 10){
            //大吉
            $body = '大吉';
        }
        $username = '******';
        //username = "******", body = 占い結果 に書き換える
    }
    $createdMessage = $app->createMessage($username, $body, base64_encode(file_get_contents($app['icon_image_path'])));

    return $app->json($createdMessage);
});

$app->delete('/messages/{id}', function ($id) use ($app) {