很多时候我们给与客户端在发布内容的时候,就很担心被客户输入恶意敏感词等信息,如若不慎还可能网站被封等;为了减少后台人工审核的成本,我们接入阿里云反文本垃圾。
第一步:在阿里云申请accessKeyId和accessKeySecret
第二步:下载阿里云的检测依赖
阿里云Sdk下载地址:
<?php namespace app\api\controller; use think\Controller; use think\Loader; class Textcheck extends Controller { public function text(){ Loader::import('aliyunSdk/green-php-sdk-sample/TextScanSample',EXTEND_PATH); $sems = new \TextScanSample(); $content = $this->request->param('words'); if(!$content){ return json(['errid' => '0','message'=>'检测字符为空']); } $res = $sems->textScan($content); if($res['suggetion'] == 'pass'){ return json(['errid' => '0','message'=>'阿里云文本安全审核通过']); }else{ return json(['errid' => '1','message'=>'不通过,原因'.$res['scene']]); } } }