Commit 10ebc2a2 by jscat

nyx: java, 增加敏感文字判别功能,用于

1. 公屏文字
2. 评论文字
parent 4ab88da6
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
...@@ -165,6 +165,13 @@ ...@@ -165,6 +165,13 @@
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.aliyun.oss/aliyun-sdk-oss -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.8.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package cn.com.fun.nyxkey.api.service;
package cn.com.fun.nyxkey.api.service;
import cn.com.fun.nyxkey.api.common.JSONResult;
import cn.com.fun.nyxkey.api.domain.*;
import cn.com.fun.nyxkey.api.domain.*;
import cn.com.fun.nyxkey.api.domain.query.*;
import org.joda.time.DateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* Created by jscat on 2020-04-23.
*/
public interface Rockwell_checkService {
JSONResult Rockwell_checkServiceCheckText(String text);
}
package cn.com.fun.nyxkey.api.service.impl;
package cn.com.fun.nyxkey.api.service.impl;
import cn.com.fun.nyxkey.api.common.JSONResult;
import cn.com.fun.nyxkey.api.service.*;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* Created by jscat on 2020/04/23.
*/
@Service
public class Rockwell_checkServiceImpl implements Rockwell_checkService {
private static final Logger LOGGER = LoggerFactory.getLogger(Rockwell_keyServiceImpl.class);
@Value("${weixin.appid}")
private String appid;
@Value("${weixin.secret}")
private String secret;
//获取access_token
public JSONObject getAccessToken() {
Map<String, Object> map = null;
StringBuffer url = new StringBuffer("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential");
String ss = appid;
url.append("&appid=");//appid设置
url.append(appid);
url.append("&secret=");//secret设置
url.append(secret);
JSONObject json = new JSONObject();
try {
HttpClient client = HttpClientBuilder.create().build();//构建一个Client
HttpGet get = new HttpGet(url.toString()); //构建一个GET请求
HttpResponse response = client.execute(get);//提交GET请求
HttpEntity httpEntity = response.getEntity();//拿到返回的HttpResponse的"实体"
String result = EntityUtils.toString(httpEntity, "UTF-8");// 转成string
json = JSONObject.parseObject(result);
} catch (Exception e) {
e.printStackTrace();
}
return json;
}
//校验文本内容是否有违法违规内容
public JSONResult checkText(String accessToken, String textConetnt) {
try {
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null;
HttpPost request = new HttpPost("https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + accessToken);
request.addHeader("Content-Type", "application/json;charset=UTF-8");
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("content", textConetnt);
request.setEntity(new StringEntity(com.alibaba.fastjson.JSONObject.toJSONString(paramMap), ContentType.create("application/json", "utf-8")));
response = httpclient.execute(request);
HttpEntity httpEntity = response.getEntity();
String result = EntityUtils.toString(httpEntity, "UTF-8");// 转成string
JSONObject json = JSONObject.parseObject(result);
System.out.println(json);
JSONResult jsonResult = new JSONResult(0, json);
return jsonResult;
} catch (Exception e) {
e.printStackTrace();
System.out.println("----------------调用腾讯内容过滤系统出错------------------");
return new JSONResult();
}
}
/*
接口api: main use 题目热搜
*/
public JSONResult Rockwell_checkServiceCheckText(String text){
LOGGER.debug("find Rockwell_checkServiceCheckText");
JSONObject json = getAccessToken();
String token = json.getString("access_token")+"";
return checkText(token, text);
}
}
package cn.com.fun.nyxkey.api.service.impl; package cn.com.fun.nyxkey.api.service.impl;
...@@ -33,15 +33,12 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService { ...@@ -33,15 +33,12 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
private static final Logger LOGGER = LoggerFactory.getLogger(Rockwell_ossServiceImpl.class); private static final Logger LOGGER = LoggerFactory.getLogger(Rockwell_ossServiceImpl.class);
@Value("${weixin.accessKeyId}") @Value("${weixin.appid}")
private String accessKeyId; private String accessKeyId;
@Value("${weixin.accessKeySecret}") @Value("${weixin.secret}")
private String accessKeySecret; private String accessKeySecret;
@Value("${weixin.host}")
private String host;
/* /*
接口api: 接口api:
STS临时授权访问OSS STS临时授权访问OSS
......
package cn.com.fun.nyxkey.api.web.controller; package cn.com.fun.nyxkey.api.web.controller;
package cn.com.fun.nyxkey.api.web.controller; package cn.com.fun.nyxkey.api.web.controller;
import cn.com.fun.nyxkey.api.common.JSONResult;
import cn.com.fun.nyxkey.api.service.Rockwell_checkService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -13,15 +21,36 @@ import java.util.Map; ...@@ -13,15 +21,36 @@ import java.util.Map;
*/ */
@Controller @RestController
@RequestMapping("/api/check/content") @RequestMapping("/api")
public class CheckApiController { public class CheckApiController {
//页面请求
@GetMapping("/index/{userId}") private static final Logger LOGGER = LoggerFactory.getLogger(CheckApiController.class);
public Map socket(@PathVariable String userId) {
Map result = new HashMap(); @Autowired
result.put("userId", userId); private Rockwell_checkService checkService;
return result;
/*
正常结果
{
"errcode": "0",
"errmsg": "ok"
}
含有敏感信息,则返回87014
{
"errcode": 87014,
"errmsg": "risky content"
}
*/
@ApiOperation(value="文本敏感信息检测", notes="文本敏感信息检测")
@ApiImplicitParams({
@ApiImplicitParam(name = "text", value = "用于监测的文本", required = false, dataType = "String", defaultValue = "")
})
@RequestMapping(value = "/nyx/wx/check/text", method = RequestMethod.GET)
public JSONResult checkText(
@RequestParam(value = "text", required = false, defaultValue = "0") String text
) {
return checkService.Rockwell_checkServiceCheckText(text);
} }
} }
\ No newline at end of file
package cn.com.fun.nyxkey.api.web.controller; package cn.com.fun.nyxkey.api.web.controller;
...@@ -34,9 +34,9 @@ import static cn.com.fun.nyxkey.api.utils.BaseUtils.getSession; ...@@ -34,9 +34,9 @@ import static cn.com.fun.nyxkey.api.utils.BaseUtils.getSession;
*/ */
@Controller @Controller
@RequestMapping("/") @RequestMapping("/")
public class DiscoverApiController extends BaseController { public class DiscoverController extends BaseController {
private static final Logger LOGGER = LoggerFactory.getLogger(DiscoverApiController.class); private static final Logger LOGGER = LoggerFactory.getLogger(DiscoverController.class);
@Autowired @Autowired
private Rockwell_userService userService; private Rockwell_userService userService;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论