* @version : HuoMp 1.0 */ namespace mini\sdk\controller; use huolib\status\CommonStatus; use huomp\controller\game\GameMini; use huomp\controller\sec\secCheckApi; use mini\common\controller\V2ApiBaseController; use think\Log; class MpSecCheckController extends V2ApiBaseController { function _initialize() { parent::_initialize(); $this->checkLogin(); } /** * 小程序敏感词检测 * 【域名】/mp/msg/check * */ public function msgSecCheck() { $_game_rq = $this->setGameData(); $_app_id = $_game_rq->getHAppId(); $_content = get_val($this->rq_data, 'content', ''); if (empty($_content)) { $_code = CommonStatus::INVALID_PARAMS; $this->error('检测内容为空', [], $_code); } $_config = (new GameMini())->getMpConfig($_app_id); if (empty($_config) || empty($_config['app_id']) || empty($_config['app_secret'])) { $_err_msg = 'func='.__FUNCTION__.'&class='.__CLASS__.'¶m='.json_encode($this->request->param()) .'&config='.json_encode($_config); Log::write($_err_msg, Log::ERROR, true); $_code = CommonStatus::INVALID_PARAMS; $this->error(CommonStatus::getMsg($_code), [], $_code); } $_rs = (new secCheckApi())->msgSecCheck($_config['app_id'], $_config['app_secret'], $_content); $this->returnData($_rs); } /** * 小程序敏感图片检测 * 【域名】/mp/img/check * */ public function imgSecCheck() { $_game_rq = $this->setGameData(); $_app_id = $_game_rq->getHAppId(); $file = request()->file('image'); $_path = ROOT_PATH.'public'.DS.'upload/secCheck/'; if ($file) { $info = $file->move($_path); if ($info) { $_img_path = $_path.$info->getSaveName(); //文件地址 $_ext = $info->getExtension(); //文件后缀 $_img_name = $info->getBasename('.'.$_ext); //文件名称 $_image = \think\Image::open($_img_path); $_thumb = $_img_name.'_thumb.'.$_ext; //缩略图 $_thumb_path = $_path.$_thumb; //缩略图地址 $_image->thumb(750, 750)->save($_thumb_path); //生成缩略图 /* 获取小程序配置 */ $_config = (new GameMini())->getMpConfig($_app_id); if (empty($_config) || empty($_config['app_id']) || empty($_config['app_secret'])) { $_err_msg = 'func='.__FUNCTION__.'&class='.__CLASS__.'¶m='.json_encode($this->request->param()) .'&config='.json_encode($_config); Log::write($_err_msg, Log::ERROR, true); $_code = CommonStatus::INVALID_PARAMS; $this->error(CommonStatus::getMsg($_code), [], $_code); } $_rs = (new secCheckApi())->imgSecCheck($_config['app_id'], $_config['app_secret'], $_thumb_path); /* 删除图片 */ unlink($_thumb_path); unlink($_img_path); $this->returnData($_rs); } else { // 上传失败获取错误信息 echo $file->getError(); } } } }