陈昶聿
2026-05-15 a491712dea71be0682d025bb79fdc471ec157802
ruoyi-common/src/main/java/com/ruoyi/common/utils/WxMpUtils.java
@@ -8,6 +8,7 @@
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.stereotype.Component;
import java.util.Map;
@@ -56,10 +57,7 @@
            return false;
        }
        try {
            WxMpKefuMessage message = WxMpKefuMessage.TEXT()
                    .toUser(openid)
                    .content(content)
                    .build();
            WxMpKefuMessage message = WxMpKefuMessage.TEXT().toUser(openid).content(content).build();
            boolean result = wxMpService.getKefuService().sendKefuMessage(message);
            log.info("【WxMpUtils】文本客服消息发送{},openid:{}", result ? "成功" : "失败", openid);
            return result;
@@ -83,8 +81,7 @@
     *                   示例:{"first": new WxMpTemplateData("first", "你好", "#173177"), ...}
     * @return 发送成功返回微信返回的 msgid,失败返回 null
     */
    public String sendTemplateMessage(String openid, String templateId, String url,
                                      Map<String, WxMpTemplateData> dataMap) {
    public String sendTemplateMessage(String openid, String templateId, String url, Map<String, WxMpTemplateData> dataMap) {
        if (StringUtils.isEmpty(openid)) {
            log.warn("【WxMpUtils】sendTemplateMessage 失败:openid 为空");
            return null;
@@ -109,8 +106,7 @@
            log.info("【WxMpUtils】模板消息发送成功,openid:{},msgId:{}", openid, msgId);
            return msgId;
        } catch (WxErrorException e) {
            log.error("【WxMpUtils】模板消息发送异常,openid:{},templateId:{},错误:{}",
                    openid, templateId, e.getError(), e);
            log.error("【WxMpUtils】模板消息发送异常,openid:{},templateId:{},错误:{}", openid, templateId, e.getError(), e);
            return null;
        }
    }
@@ -125,8 +121,7 @@
     *                   示例:{"first": "你好", "keyword1": "2024-01-01", "remark": "感谢使用"}
     * @return 发送成功返回微信返回的 msgid,失败返回 null
     */
    public String sendTemplateMessage(String openid, String templateId, String url,
                                      Map<String, String> dataMap, String defaultColor) {
    public String sendTemplateMessage(String openid, String templateId, String url, Map<String, String> dataMap, String defaultColor) {
        if (StringUtils.isEmpty(openid)) {
            log.warn("【WxMpUtils】sendTemplateMessage 失败:openid 为空");
            return null;
@@ -152,8 +147,7 @@
            log.info("【WxMpUtils】模板消息发送成功,openid:{},msgId:{}", openid, msgId);
            return msgId;
        } catch (WxErrorException e) {
            log.error("【WxMpUtils】模板消息发送异常,openid:{},templateId:{},错误:{}",
                    openid, templateId, e.getError(), e);
            log.error("【WxMpUtils】模板消息发送异常,openid:{},templateId:{},错误:{}", openid, templateId, e.getError(), e);
            return null;
        }
    }