百度审核

首先下载百度审核的Composer包

composer require sy-records/baidu-textcenso

我这边使用的是Laravel框架,在vendor目录里面找到sy-records目录,打开里面的README.md文件

 

复制以下代码

$appId = "";
$apiKey = "";
$secretKey = "";

$client = new \Luffy\TextCensor\Core($appId, $apiKey, $secretKey);
$res = $client->textCensorUserDefined("沈唁志博客:https://qq52o.me"); //待审核文本字符串
var_dump($res);

在控制器中创建一个方法,并且将刚才的代码复制来

public function index(Request $request){
        $text = $request->get('text');
        $appId = "";//你自己的百度审核appid
        $apiKey = "";//你自己的百度审核apikey
        $secretKey = "";//你自己的百度审核secretkry

        $client = new \Luffy\TextCensor\Core($appId, $apiKey, $secretKey);
        $res = $client->textCensorUserDefined($text);
        var_dump($res);
        if ($res['conclusion']=='不合规'){
            return ['code'=>503,'msg'=>'内容不合规'];
        }else{
            return ['code'=>203,'msg'=>'内容合规'];
        }
    }

 给该方法一个路由,并在apipost中测试

 

 

 

 这只是个简单的文字审核

posted @ 2023-09-04 09:27  还好阿卡  阅读(31)  评论(0编辑  收藏  举报