Skip to content

Instantly share code, notes, and snippets.

@belltzel
Last active June 10, 2021 08:39
Show Gist options
  • Save belltzel/5c497479e7989c498270936bbe52a951 to your computer and use it in GitHub Desktop.
Save belltzel/5c497479e7989c498270936bbe52a951 to your computer and use it in GitHub Desktop.
OkayamaUg5
// アクセストークン発行
Route::get('/redirect', function (Request $request) {
$request->session()->put('state', $state = Str::random(40));
$query = http_build_query([
'client_id' => '{client_id}',
'redirect_uri' => 'http://127.0.0.1:8000/callback',
'response_type' => 'code',
'scope' => ['read','write'],
'state' => $state,
]);
return redirect('{eccube_admin_url}/authorize?'.$query);
});
// コールバック
Route::get('/callback', function (Request $request) {
$state = $request->session()->pull('state');
throw_unless(
strlen($state) > 0 && $state === $request->state,
InvalidArgumentException::class
);
$response = Http::asForm()->post('https://www.ec-devlop.xyz/token', [
'grant_type' => 'authorization_code',
'client_id' => '{client_id}',
'client_secret' => '{client_secret}',
'redirect_uri' => 'http://127.0.0.1:8000/callback',
'code' => $request->code,
]);
return $response->json();
});
// トークンリフレッシュ
Route::get('/callback_ref', function (Request $request) {
$response = Http::asForm()->post('https://www.ec-devlop.xyz/token', [
'grant_type' => 'refresh_token',
'redirect_uri' => 'http://127.0.0.1:8000/callback',
'refresh_token' => '{refresh_token}',
'client_id' => '{client_id}',
'client_secret' => '{client_secret}',
]);
return $response->json();
});
// API接続
Route::get('/apiget', function (Request $request) {
//取得
// $query = <<<'GRAPHQL'
//{
// product(id:2) {
// id,
// name
// }
//}
//GRAPHQL;
// 更新
// $query = <<<'GRAPHQL'
//mutation {
// updateProductStock(code: "cube-09",stock_unlimited: true) {
// code stock stock_unlimited
// }
//}
//GRAPHQL;
$response = Http::withHeaders([
'Accept' => 'application/json',
'Authorization' => 'Bearer {access_token}',
])->post('{eccube_url}/api',[
'query' => $query
]);
return $response->json();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment