百度敏感詞過濾
阿新 • • 發佈:2021-11-08
百度智慧雲網址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); } }