mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
✨ #1217 小程序增加校验图片/音频是否含有违法违规内容的接口
* 添加 微信内容异步检测接口 * 消息route 增加 title 参数
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaMediaAsyncCheckResult;
|
||||
import java.io.File;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
@@ -18,6 +19,8 @@ public interface WxMaSecCheckService {
|
||||
|
||||
String MSG_SEC_CHECK_URL = "https://api.weixin.qq.com/wxa/msg_sec_check";
|
||||
|
||||
String MEDIA_CHECK_ASYNC_URL = "https://api.weixin.qq.com/wxa/media_check_async";
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 校验一张图片是否含有违法违规内容.
|
||||
@@ -39,5 +42,25 @@ public interface WxMaSecCheckService {
|
||||
* 详情请见: https://developers.weixin.qq.com/miniprogram/dev/api/open-api/sec-check/msgSecCheck.html
|
||||
* </pre>
|
||||
*/
|
||||
boolean checkMessage(String msgString);
|
||||
boolean checkMessage(String msgString) throws WxErrorException;
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 异步校验图片/音频是否含有违法违规内容。
|
||||
* 应用场景举例:
|
||||
* 语音风险识别:社交类用户发表的语音内容检测;
|
||||
* 图片智能鉴黄:涉及拍照的工具类应用(如美拍,识图类应用)用户拍照上传检测;电商类商品上架图片检测;媒体类用户文章里的图片检测等;
|
||||
* 敏感人脸识别:用户头像;媒体类用户文章里的图片检测;社交类用户上传的图片检测等。
|
||||
* 频率限制:
|
||||
* 单个 appId 调用上限为 2000 次/分钟,200,000 次/天;文件大小限制:单个文件大小不超过10M
|
||||
* 详情请见:
|
||||
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.mediaCheckAsync.html
|
||||
* </pre>
|
||||
* @param mediaUrl 要检测的多媒体url
|
||||
* @param mediaType 媒体类型,{@link cn.binarywang.wx.miniapp.constant.WxMaConstants.SecCheckMediaType}
|
||||
* @return
|
||||
*/
|
||||
WxMaMediaAsyncCheckResult mediaCheckAsync(String mediaUrl,int mediaType) throws WxErrorException;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaSecCheckService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaMediaAsyncCheckResult;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.io.File;
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
*
|
||||
@@ -20,6 +20,7 @@ import java.io.File;
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class WxMaSecCheckServiceImpl implements WxMaSecCheckService {
|
||||
|
||||
private WxMaService service;
|
||||
|
||||
@Override
|
||||
@@ -31,16 +32,24 @@ public class WxMaSecCheckServiceImpl implements WxMaSecCheckService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkMessage(String msgString) {
|
||||
public boolean checkMessage(String msgString) throws WxErrorException {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("content", msgString);
|
||||
try {
|
||||
this.service.post(MSG_SEC_CHECK_URL, jsonObject.toString());
|
||||
} catch (WxErrorException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.service.post(MSG_SEC_CHECK_URL, jsonObject.toString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaMediaAsyncCheckResult mediaCheckAsync(String mediaUrl, int mediaType)
|
||||
throws WxErrorException {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("media_url", mediaUrl);
|
||||
jsonObject.addProperty("media_type", mediaType);
|
||||
|
||||
return WxMaMediaAsyncCheckResult
|
||||
.fromJson(this.service.post(MEDIA_CHECK_ASYNC_URL, jsonObject.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user