Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(小程序模块): 新增内容安全mediaCheckAsync新版本实现 #2399

Merged
merged 4 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.binarywang.wx.miniapp.api;

import cn.binarywang.wx.miniapp.bean.WxMaMediaAsyncCheckResult;
import cn.binarywang.wx.miniapp.bean.security.WxMaMedisSecCheckCheckRequest;
import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckRequest;
import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckResponse;
import me.chanjar.weixin.common.error.WxErrorException;
Expand Down Expand Up @@ -64,7 +65,7 @@ public interface WxMaSecCheckService {
* </pre>
* @param msgRequest
* @return WxMaMsgSecCheckCheckResponse
* @throws WxErrorException
* @throws WxErrorException the wx error exception
*/
WxMaMsgSecCheckCheckResponse checkMessage(WxMaMsgSecCheckCheckRequest msgRequest) throws WxErrorException;

Expand All @@ -88,4 +89,25 @@ public interface WxMaSecCheckService {
*/
WxMaMediaAsyncCheckResult mediaCheckAsync(String mediaUrl, int mediaType) throws WxErrorException;


/**
* <pre>
* 异步校验图片/音频是否含有违法违规内容。(新版本接口,主要对request和respone做了参数优化)
* 应用场景举例:
* 语音风险识别:社交类用户发表的语音内容检测;
* 图片智能鉴黄:涉及拍照的工具类应用(如美拍,识图类应用)用户拍照上传检测;电商类商品上架图片检测;媒体类用户文章里的图片检测等;
* 敏感人脸识别:用户头像;媒体类用户文章里的图片检测;社交类用户上传的图片检测等。
* 频率限制:
* 单个 appId 调用上限为 2000 次/分钟,200,000 次/天;文件大小限制:单个文件大小不超过10M
* 详情请见:
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.mediaCheckAsync.html
* </pre>
*
* @param medisRequest
* @return wx ma media async check result
* @throws WxErrorException the wx error exception
*/

WxMaMediaAsyncCheckResult mediaCheckAsync(WxMaMedisSecCheckCheckRequest medisRequest) throws WxErrorException;
binarywang marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cn.binarywang.wx.miniapp.api.WxMaSecCheckService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaMediaAsyncCheckResult;
import cn.binarywang.wx.miniapp.bean.security.WxMaMedisSecCheckCheckRequest;
import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckRequest;
import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
Expand Down Expand Up @@ -68,10 +69,7 @@ public boolean checkMessage(String msgString) throws WxErrorException {
@Override
public WxMaMsgSecCheckCheckResponse checkMessage(WxMaMsgSecCheckCheckRequest msgRequest) throws WxErrorException {
String response = this.service.post(MSG_SEC_CHECK_URL, msgRequest);
JsonObject jsonObject = GsonParser.parse(response);
if (jsonObject.get(ERRCODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
parseErrorResponse(response);
return WxMaGsonBuilder.create().fromJson(response, WxMaMsgSecCheckCheckResponse.class);
}

Expand All @@ -86,4 +84,17 @@ public WxMaMediaAsyncCheckResult mediaCheckAsync(String mediaUrl, int mediaType)
.fromJson(this.service.post(MEDIA_CHECK_ASYNC_URL, jsonObject.toString()));
}

@Override
public WxMaMediaAsyncCheckResult mediaCheckAsync(WxMaMedisSecCheckCheckRequest medisRequest) throws WxErrorException {
String response = this.service.post(MEDIA_CHECK_ASYNC_URL,medisRequest);
parseErrorResponse(response);
return WxMaGsonBuilder.create().fromJson(response,WxMaMediaAsyncCheckResult.class);
}

private void parseErrorResponse(String response) throws WxErrorException {
JsonObject jsonObject = GsonParser.parse(response);
if (jsonObject.get(ERRCODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cn.binarywang.wx.miniapp.bean.security;

import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

/**
* @author dingxw
* @date 2021/11/18 20:27
*/
@Data
@Builder
public class WxMaMedisSecCheckCheckRequest implements Serializable {
binarywang marked this conversation as resolved.
Show resolved Hide resolved

@SerializedName("media_url")
private String mediaUrl;

@SerializedName("media_type")
private Integer mediaType;

@SerializedName("version")
private Integer version;

@SerializedName("openid")
private String openid;

@SerializedName("scene")
private Integer scene;

}