api地址
https://cloud.baidu.com/doc/NLP/s/7k6z52ggx
控制台申请应用
https://console.bce.baidu.com/ai/?_=1619424019362&fromai=1#/ai/nlp/app/detail~appId=2431771
3、SDK下载
控制器方法:
/*
* 百度AI智能 文章自动打标签
* 2021-4-26 16:45:06
*/
public function autoTags(Request $request)
{
$this->validate($request, [
'id' => 'required',
//'title' => 'required',
//'content' => 'required'
],
[
'id.required' => '请传递文章id',
//'title.required' => '请传递文章标题',
//'content.required' => '请传递文章内容'
]);
$APP_ID = '24068588';
$API_KEY = 'GgpkkpSLPyqUzXhVoaCNIrZQ';
$SECRET_KEY = 'NZzGpb8hQEnXD94U2yefdugvyBtWBbsj';
$client = new \App\Expands\Baidu\Ocr\AipNlp($APP_ID, $API_KEY, $SECRET_KEY);
$article = ArticleModel::where('id',$request['id'])->select('*')->first();
//dd($article);
// 可选参数
$options = array();
$options["language_type"] = "CHN_ENG";
$options["detect_direction"] = "true";
$options["detect_language"] = "true";
$options["probability"] = "true";
// 调用通用文字识别, 图片参数为远程url图片
echo '标题: '.$article->title;
echo '<hr>';
echo '内容: '. (strip_tags($article->body));
$title = mb_substr( $article->title, 0, 40 );
$content = mb_substr( strip_tags($article->body), 0, 32000 );
//;
$res = $client->keyword($title, $content);
dd($res);
return ['code' => 0, 'data'=>$res];
}
api调用测试: