mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
🆕 #2261 【小程序】增加内容安全接口(兼容2.0版本)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaMediaAsyncCheckResult;
|
||||
import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckRequest;
|
||||
import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckResponse;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
|
||||
import java.io.File;
|
||||
@@ -55,6 +57,17 @@ public interface WxMaSecCheckService {
|
||||
boolean checkMessage(String msgString) throws WxErrorException;
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 检查一段文本是否含有违法违规内容(新版本接口,主要是request和response做了参数优化)
|
||||
* 详情请见: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html
|
||||
* </pre>
|
||||
* @param msgRequest
|
||||
* @return WxMaMsgSecCheckCheckResponse
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxMaMsgSecCheckCheckResponse checkMessage(WxMaMsgSecCheckCheckRequest msgRequest) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 异步校验图片/音频是否含有违法违规内容。
|
||||
|
||||
@@ -14,8 +14,19 @@ public interface WxMaShopImgService {
|
||||
/**
|
||||
* 上传图片
|
||||
*
|
||||
* @param file
|
||||
* @return WxMinishopImageUploadCustomizeResult
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxMinishopImageUploadCustomizeResult uploadImg(File file) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 上传图片,带respType参数
|
||||
*
|
||||
* @param file
|
||||
* @param respType
|
||||
* @return WxMinishopImageUploadCustomizeResult
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxMinishopImageUploadCustomizeResult uploadImg(File file, String respType) throws WxErrorException;
|
||||
}
|
||||
|
||||
@@ -3,12 +3,17 @@ 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 cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckRequest;
|
||||
import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckResponse;
|
||||
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.enums.WxType;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.json.GsonParser;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -16,6 +21,7 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.SecCheck.*;
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ERRCODE;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@@ -59,6 +65,16 @@ public class WxMaSecCheckServiceImpl implements WxMaSecCheckService {
|
||||
return true;
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
return WxMaGsonBuilder.create().fromJson(response, WxMaMsgSecCheckCheckResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaMediaAsyncCheckResult mediaCheckAsync(String mediaUrl, int mediaType)
|
||||
throws WxErrorException {
|
||||
|
||||
@@ -23,7 +23,14 @@ public class WxMaShopImgServiceImpl implements WxMaShopImgService {
|
||||
@Override
|
||||
public WxMinishopImageUploadCustomizeResult uploadImg(File file) throws WxErrorException {
|
||||
WxMinishopImageUploadCustomizeResult result = this.service.execute(
|
||||
MinishopUploadRequestCustomizeExecutor.create(this.service.getRequestHttp()), IMG_UPLOAD, file);
|
||||
MinishopUploadRequestCustomizeExecutor.create(this.service.getRequestHttp(), "0"), IMG_UPLOAD, file);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMinishopImageUploadCustomizeResult uploadImg(File file, String respType) throws WxErrorException {
|
||||
WxMinishopImageUploadCustomizeResult result = this.service.execute(
|
||||
MinishopUploadRequestCustomizeExecutor.create(this.service.getRequestHttp(), respType), IMG_UPLOAD, file);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user