rk
2026-03-23 6cfc2e4258089c953b67054229170c1178585590
server/dmmall_service/src/main/java/com/doumee/service/business/impl/CommentServiceImpl.java
@@ -1,5 +1,7 @@
package com.doumee.service.business.impl;
import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckRequest;
import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -12,6 +14,7 @@
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.core.wx.WxMiniConfig;
import com.doumee.dao.business.*;
import com.doumee.dao.business.model.*;
import com.doumee.dao.web.dto.CommentDTO;
@@ -22,6 +25,7 @@
import com.doumee.service.business.CommentService;
import com.doumee.service.business.ZanService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
@@ -67,6 +71,26 @@
    @Override
    public Comment apply(CommentApplyRequest comment, Integer memberId) {
        if (StringUtils.isNotBlank(comment.getContent())) {
            try {
                WxMaMsgSecCheckCheckRequest checkRequest = WxMaMsgSecCheckCheckRequest.builder()
                        .version("2")
                        .scene(3)
                        .openid(getMemberOpenId(memberId))
                        .content(comment.getContent())
                        .build();
                WxMaMsgSecCheckCheckResponse checkResponse = WxMiniConfig.wxMaService.getSecurityService().checkMessage(checkRequest);
                if (checkResponse.getResult() != null && checkResponse.getResult().getSuggest() != null) {
                    String suggest = checkResponse.getResult().getSuggest();
                    if ("risky".equalsIgnoreCase(suggest)) {
                        throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "评论内容包含违规信息,请修改后重新发布");
                    }
                }
            } catch (WxErrorException e) {
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "内容安全检测失败,请稍后重试");
            }
        }
        Comment target = new Comment();
        target.setCreateDate(new Date());
        target.setEditDate(new Date());
@@ -408,4 +432,9 @@
        });
        return PageData.from(result);
    }
    private String getMemberOpenId(Integer memberId) {
        Member member = memberMapper.selectById(memberId);
        return member != null ? member.getOpenId() : null;
    }
}