85 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace app\api\controller;
use app\common\controller\Api;
/**
* 敏感词接口
*/
class Sensitivewords extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* 生成敏感词json文件
*/
public function sensitivewords_generate_json()
{
try{
$sensitivewords = new \bw\sensitivewords\Sensitivewords();
$res = $sensitivewords->generateJson();
}catch (\Exception $e){
$this->error("执行失败:".$e->getMessage());
}
$this->success("执行成功" , ["path" => $res]);
}
/**
* @ApiTitle( 检测敏感词是否存在)
* @ApiSummary(检测敏感词是否存在)
* @ApiMethod(POST)
* @ApiParams(name = "text", type = "string",required=true,description = "敏感词")
* @ApiParams(name = "excption", type = "int",required=true,description = "是否报错")
* @ApiReturn({
*
*})
*/
public function check()
{
$text = $this->request->param('text/s', 0); //课程id
$excption = $this->request->param('excption/d', 0); //课程id
try{
$sensitivewords = new \bw\sensitivewords\Sensitivewords();
$res = $sensitivewords->check($text,$excption);
}catch (\Exception $e){
$this->error("执行失败:".$e->getMessage());
}
$this->success("执行成功" , ["check" => $res]);
}
/**
* @ApiTitle( 检测敏感词并替换)
* @ApiSummary(检测敏感词并替换)
* @ApiMethod(POST)
* @ApiParams(name = "text", type = "string",required=true,description = "敏感词")
* @ApiParams(name = "replace", type = "string",required=true,description = "替换符号")
* @ApiReturn({
*
*})
*/
public function check_and_replace()
{
$text = $this->request->param('text/s', 0); //课程id
$replace = $this->request->param('replace/s', "*") ?:"*"; //课程id
try{
$sensitivewords = new \bw\sensitivewords\Sensitivewords();
$res = $sensitivewords->check_and_replace($text,$replace);
}catch (\Exception $e){
$this->error("执行失败:".$e->getMessage());
}
$this->success("执行成功" , ["replace" => $res]);
}
}