场景:微信校验图片合法性
Map<String, Object> map = new HashedMap();
map.put("media_url", url); //要检测的图片或音频的url
map.put("media_type", "2"); //1:音频;2:图片
map.put("version", 2); //接口版本号,2.0版本为固定值2
map.put("scene", 2); //场景枚举值(1 资料;2 评论;3 论坛;4 社交日志)
map.put("openid", openId);
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
// 创建Http Post请求
HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/wxa/media_check_async?access_token=" + getToken());
StringEntity entity = new StringEntity(JSONObject.toJSONString(map), ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
try {
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
JSONObject result = JSONObject.parseObject(resultString);
log.info("图片校验:{}",result.toString());
回调实体类
public class ImgResp {
private String ToUserName;
private String FromUserName;
private String Event;
private String appid;
private String MsgType;
private String trace_id;
private String version;
private ResultResp result;
}
public class ResultResp {
private String suggest;
private Integer label;
}
具体回调实现参考微信回调文章:
微信消息回调
https://blog.youkuaiyun.com/csgqaq/article/details/148531712
4697

被折叠的 条评论
为什么被折叠?



