关于passport client_credentials 模式 需要登录问题


<?php
//初始化
$url = "http://xxx/OAapi/public/index.php/oauth/token";
$curl = curl_init();
//设置抓取的url
curl_setopt($curl, CURLOPT_URL, $url);
//设置头文件的信息作为数据流输出
// curl_setopt($curl, CURLOPT_HEADER, 1);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//设置post方式提交
curl_setopt($curl, CURLOPT_POST, 1);
//设置post数据
$post_data = array(
"grant_type" => "client_credentials",
"client_id" => "3",
"client_secret" => "eVRhG7tbCUHBF1EOD5PCOI2XKjcTEvL7QJkOVYOA",
);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
//执行命令
$data = curl_exec($curl);
$data = json_decode($data,1);
//关闭URL请求
curl_close($curl);
$access_token = $data['access_token'];
$url = "http://xxxx/OAapi/public/index.php/api/upload";

$post_data = array(
"file" => "111",
"module" => "workflow"
);
$headers = array(
'Authorization'=>'Bearer '.$access_token,
'Accept'=>'application/json',
);

$curl = curl_init();
//设置抓取的url
curl_setopt($curl, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//设置post方式提交
curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
//执行命令
$data = curl_exec($curl);
print_r($data);
//关闭URL请求
curl_close($curl);

?>

[upl-image-preview url=http://static.forum.laravelacademy.org/assets/files/2018-07-15/1531650717-813501-qq20180715-183137.png]

为什么会要求登录。access_token 已经能拿到了。希望不登录,可以实现吗?


点赞 取消点赞 收藏 取消收藏

<< 上一篇: 资源路由的show方法 如何使用

>> 下一篇: Laravel5.2照着手册写报错!!!!大佬指教一下