2017-08-27 04:44:53 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| API Routes
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
| Here is where you can register API routes for your application. These
|
|
|
|
| routes are loaded by the RouteServiceProvider within a group which
|
|
|
|
| is assigned the "api" middleware group. Enjoy building your API!
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
Route::middleware('auth:api')->get('/user', function (Request $request) {
|
|
|
|
return $request->user();
|
|
|
|
});
|
2018-01-05 00:26:48 +09:00
|
|
|
|
2018-01-05 22:43:33 +09:00
|
|
|
Route::get('/checkin/card', function (Request $request) {
|
2018-01-05 00:26:48 +09:00
|
|
|
$request->validate([
|
|
|
|
'url:required|url'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$client = new GuzzleHttp\Client();
|
|
|
|
$res = $client->get($request->input('url'));
|
|
|
|
if ($res->getStatusCode() === 200) {
|
|
|
|
$dom = new DOMDocument();
|
|
|
|
@$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8'));
|
|
|
|
$xpath = new DOMXPath($dom);
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
'title' => '',
|
|
|
|
'description' => '',
|
|
|
|
'image' => ''
|
|
|
|
];
|
|
|
|
|
|
|
|
$titleNode = $xpath->query('//meta[@*="og:title"]');
|
|
|
|
foreach ($titleNode as $node) {
|
|
|
|
if (!empty($node->getAttribute('content'))) {
|
|
|
|
$result['title'] = $node->getAttribute('content');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$descriptionNode = $xpath->query('//meta[@*="og:description"]');
|
|
|
|
foreach ($descriptionNode as $node) {
|
|
|
|
if (!empty($node->getAttribute('content'))) {
|
|
|
|
$result['description'] = $node->getAttribute('content');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$imageNode = $xpath->query('//meta[@*="og:image"]');
|
|
|
|
foreach ($imageNode as $node) {
|
|
|
|
if (!empty($node->getAttribute('content'))) {
|
|
|
|
$result['image'] = $node->getAttribute('content');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-05 00:54:33 +09:00
|
|
|
$response = response()->json($result);
|
|
|
|
if (!config('app.debug')) {
|
|
|
|
$response = $response->setCache(['public' => true, 'max_age' => 86400]);
|
|
|
|
}
|
|
|
|
return $response;
|
2018-01-05 00:26:48 +09:00
|
|
|
} else {
|
|
|
|
abort($res->getStatusCode());
|
|
|
|
}
|
|
|
|
});
|