Commit 4241daaf authored by shiyu's avatar shiyu

微信文字内容安全识别

parent c4e34921
......@@ -46,6 +46,9 @@ public class QdWxAppletApi {
// 微信小程序音视频内容安全识别地址
private static final String MEDIA_CHECK_URL = "https://api.weixin.qq.com/wxa/media_check_async?access_token=%s";
// 微信小程序文字内容安全识别地址
private static final String WORD_CHECK_URL = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=%s";
//获取urllink
private static final String URL_LINK = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=%s";
......@@ -81,6 +84,23 @@ public class QdWxAppletApi {
}
public String checkWord(WxCheckMediaRequestDto dto) {
String accessToken = qdWxLoginManager.getAccessToken();
String url = String.format(WORD_CHECK_URL, accessToken);
OkHttpUtil okHttpUtil = OkHttpUtil.builder().url(url);
Map<String, Object> map = new HashMap<>();
map.put("content", dto.getWordStr());
map.put("version", 2);
map.put("scene", 4);
map.put("openid", dto.getWxOpenId());
okHttpUtil.addParams(map);
okHttpUtil.post(true);
String responseStr = okHttpUtil.async();
logger.info("[checkContent] response :{}", responseStr);
return responseStr;
}
public String getUrlLink(String redirectUrl, String query) {
String urlLink = "";
......
......@@ -13,4 +13,9 @@ public class WxCheckMediaRequestDto implements Entity {
private Integer mediaType;
private String mediaUrl;
/**
* 文字内容
*/
private String wordStr;
}
package com.wwdz.ch.wx.impl.qiandao;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.core.api.qiandao.QdWxAppletApi;
import com.wwdz.ch.core.consts.CommConsts;
import com.wwdz.ch.core.consts.qiandao.SignInTaskEnum;
import com.wwdz.ch.core.entity.WxCheckMediaRequestDto;
import com.wwdz.ch.core.type.PageSearchResult;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dao.qiandao.QdUserDao;
......@@ -22,6 +24,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
......@@ -52,9 +56,21 @@ public class QdSignInTaskServiceImpl implements QdSignInTaskService {
@Autowired
QdUserDao qdUserDao;
@Autowired
QdWxAppletApi qdWxAppletApi;
@Override
public Result add(SignInTaskRequestDto dto) {
try {
WxCheckMediaRequestDto wxCheckMediaRequestDto = new WxCheckMediaRequestDto();
//查询用户openid
QdUser user = qdUserDao.queryById(dto.getCreatorId());
wxCheckMediaRequestDto.setWxOpenId(user.getWxOpenid());
logger.info("=========== 微信内容安全识别接口调用成功 ===========");
wxCheckMediaRequestDto.setWordStr(dto.getName());
qdWxAppletApi.checkWord(wxCheckMediaRequestDto);
Date now = new Date();
SignInTask signInTask = new SignInTask();
EntityMapper.copyAttribute(dto, signInTask);
......
......@@ -136,17 +136,19 @@ public class QdUserSignInServiceImpl implements QdUserSignInService {
return Result.failed("非打卡时段");
}
}
if (!CollectionUtils.isEmpty(dto.getImages())) {
//微信音频内容安全识别
WxCheckMediaRequestDto wxCheckMediaRequestDto = new WxCheckMediaRequestDto();
wxCheckMediaRequestDto.setMediaType(2);
wxCheckMediaRequestDto.setMediaUrl(dto.getImages().get(0));
//查询用户openid
QdUser user = qdUserDao.queryById(dto.getUserId());
wxCheckMediaRequestDto.setWxOpenId(user.getWxOpenid());
if (!CollectionUtils.isEmpty(dto.getImages())) {
//微信音频内容安全识别
wxCheckMediaRequestDto.setMediaType(2);
wxCheckMediaRequestDto.setMediaUrl(dto.getImages().get(0));
qdWxAppletApi.checkMedia(wxCheckMediaRequestDto);
logger.info("=========== 微信音频内容安全识别接口调用成功 ===========");
}
wxCheckMediaRequestDto.setWordStr(dto.getContent());
qdWxAppletApi.checkWord(wxCheckMediaRequestDto);
//签到记录id
Long recordId = null;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment