Skip to content

Commit

Permalink
🆕 #2399 【小程序】增加内容安全mediaCheckAsync接口新的实现方法
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaowei6066 authored Nov 24, 2021
1 parent 1984b28 commit 95d130d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
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.WxMaMediaSecCheckCheckRequest;
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(WxMaMediaSecCheckCheckRequest medisRequest) throws WxErrorException;

}
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.WxMaMediaSecCheckCheckRequest;
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(WxMaMediaSecCheckCheckRequest 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,34 @@
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 WxMaMediaSecCheckCheckRequest implements Serializable {

private static final long serialVersionUID = -3947838615379224577L;

@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;

}

0 comments on commit 95d130d

Please sign in to comment.