public function test_oauth(Request $request)
{
$url = "http://test.apigateway.nmg.com.hk:8000/auth/v1/access_token/refresh";
$ch = curl_init();
$headers[] = 'Connection: Keep-Alive';
// $headers[] = 'X-refresh-token: EXyuzGkTOGkmhSFJEwxTPKDGcXalCiOk';
// $headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC90ZXN0Lm9hdXRoLm5tZy5jb20uaGsiLCJpYXQiOjE1NDAxNzI4ODQsImRhdGEiOnsidXNlcl9pZCI6Mn0sInNjb3BlcyI6IltdIiwiZXhwIjoxNTQwMTgwMDg0LCJhdWQiOiJkZXYucGFydG5lci1ucy5ubWcuY29tLmhrIn0.p3p2f4rW-fA2BEpuM4t4f4CxqBBz6n4h1UOa_8KJPR8';
$headers[] = "Cookie: refresh_token=EXyuzGkTOGkmhSFJEwxTPKDGcXalCiOk";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch) . PHP_EOL;
curl_close($ch);
return false;
}
curl_close($ch);
var_dump(json_decode($data, true));
exit();
}
public function test_accesstoken_create(Request $request)
{
$url = "http://test.apigateway.nmg.com.hk:8000/auth/v1/access_token/create";
$ch = curl_init();
$headers[] = 'Connection: Keep-Alive';
// $headers[] = 'X-refresh-token: EXyuzGkTOGkmhSFJEwxTPKDGcXalCiOk';
// $headers[] = 'Content-Type: application/json';
$post_data["email"] = "davidhuang@nmg.com.hk";
$post_data["password"] = "aA123456";
$post_data["app_id"] = "dev.partner-ns.nmg.com.hk";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
echo $data . "<br>";
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $data, $matches);
$cookies = array();
foreach($matches[1] as $item) {
parse_str($item, $cookie);
$cookies = array_merge($cookies, $cookie);
}
// var_dump($cookies);
echo "refresh_token:" . $cookies['refresh_token'] . "<br>";
// Then, after your curl_exec call:
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($data, 0, $header_size);
$body = substr($data, $header_size);
$response_data = json_decode($body, true);
var_dump($response_data);
// var_dump($request->cookie('refresh_token'));
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch) . PHP_EOL;
curl_close($ch);
return false;
}
curl_close($ch);
// var_dump(json_decode($data, true));
exit();
}
网友评论