php中的授权令牌

时间:2016-06-18 08:25:46

标签: php curl laravel-5

当用户登录到系统Web服务时将发送如下的授权令牌,我需要将这些令牌添加为用户在登录后将生成的所有get请求的标头我已经使用curl通过not编写了以下代码发现异常可以帮助我找到解决方案

token:{"user" :"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMsImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDAwXC9hcGlcL2F1dGhcL2F1dGhlbnRpY2F0ZSIsImlhdCI6MTQ2NjIzNTc1OSwiZXhwIjoxNDY2MjM5MzU5LCJuYmYiOjE0NjYyMzU3NTksImp0aSI6ImJjZmExYjc5OGYyYTY2MTAyMWY2OTM3NTc3MTkyZTNhIn0.ai91pavOiqs_41bFD5A9X2IsoniP1FHvRswR6coTwXc"}


$authorization = "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMsImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDAwXC9hcGlcL2F1dGhcL2F1dGhlbnRpY2F0ZSIsImlhdCI6MTQ2NjIzNTc1OSwiZXhwIjoxNDY2MjM5MzU5LCJuYmYiOjE0NjYyMzU3NTksImp0aSI6ImJjZmExYjc5OGYyYTY2MTAyMWY2OTM3NTc3MTkyZTNhIn0.ai91pavOiqs_41bFD5A9X2IsoniP1FHvRswR6coTwXc";                  
$ch = curl_init('http://localhost:8000/api/auth/logout');                                                                       
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
//return json_decode($result);
return view('checking', ['title' => $result]);

0 个答案:

没有答案