百度敏感词过滤(tp)

百度智能云网址https://cloud.baidu.com/

1:打开网址-》管理控制台-》产品服务-》SDK下载》内容审核-》phpSDK

 

 

 

 

 

 

2:下载至php目录service成下的baidu文件夹

 

 

3:修改红框文件中的namespace

 

 4:定义一个service文件,取名为baiduservice

 

 文件内容:

<?php
namespace app\services;

use app\services\libs\baidu\AipContentCensor;

class BaiduService
{
    const APP_ID = '25124158';
    const API_KEY = 'RoEfGVGRBnEu2id7sB2k5sc7';
    const SECRET_KEY = 'uOSTC0ZCcuPLuh05Xs8Dcx38bBxksKHG';
    /**
     * 百度敏感词校验
     * @param $content
     * @return bool
     */
    public static function textCheck($content)
    {
        $client = new AipContentCensor(self::APP_ID, self::API_KEY, self::SECRET_KEY);
        $result = $client->textCensorUserDefined($content);
        if($result['conclusionType'] == 1) {
            return true;
        }
        return false;
    }

}

tp控制器调用:

<?php
namespace app\day1\controller;

use app\services\BaiduService;

class Index
{
 

    public function check(){
     $content='万岁';
     $res=BaiduService::textCheck($content);
     print_r($res);
     
    }

}

 

posted @ 2021-11-08 16:42  王越666  阅读(774)  评论(0编辑  收藏  举报