lifang 4 месяцев назад
Родитель
Сommit
d1dcc366e6

+ 6 - 2
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/config/WxMpConfiguration.java

@@ -3,7 +3,9 @@ package cn.tr.module.smart.wx.config;
 import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage;
 import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
 import cn.binarywang.wx.miniapp.message.WxMaMessageHandler;
+import cn.tr.module.smart.wx.constant.WxAppletEventType;
 import cn.tr.module.smart.wx.handler.SubscribeMsgHandler;
+import cn.tr.module.smart.wx.handler.SubscribeMsgPopupEventHandler;
 import cn.tr.module.smart.wx.handler.UnSubscribeMsgHandler;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -36,6 +38,7 @@ public class WxMpConfiguration {
     private final WxMpProperties properties;
     private final SubscribeMsgHandler subscribeMsgHandler;
     private final UnSubscribeMsgHandler unSubscribeMsgHandler;
+    private final SubscribeMsgPopupEventHandler subscribeMsgPopupEventHandler;
 
 
     @Bean
@@ -64,8 +67,9 @@ public class WxMpConfiguration {
         final WxMpMessageRouter router = new WxMpMessageRouter(wxMaService);
         router
                 .rule().handler(logHandler).next()
-                .rule().event("subscribe").async(false).handler(subscribeMsgHandler).end()
-                .rule().event("unSubscribe").async(false).handler(unSubscribeMsgHandler).end();
+                .rule().event(WxAppletEventType.SUBSCRIBE).async(Boolean.FALSE).handler(subscribeMsgHandler).end()
+                .rule().event(WxAppletEventType.UNSUBSCRIBE).async(Boolean.FALSE).handler(unSubscribeMsgHandler).end()
+                .rule().event(WxAppletEventType.SUBSCRIBE_MSG_POPUP_EVENT).async(Boolean.FALSE).handler(subscribeMsgPopupEventHandler).end();
         return router;
     }
 

+ 36 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/constant/WxAppletEventType.java

@@ -0,0 +1,36 @@
+package cn.tr.module.smart.wx.constant;
+/**
+ * 微信小程序事件类型常量类
+ *
+ * 该类定义了微信小程序中可能触发的各种事件类型常量,
+ * 主要用于处理用户与小程序的交互事件,如订阅消息相关的事件等。
+ *
+ * @author lf
+ * @date 2025/08/26
+ */
+public interface WxAppletEventType {
+    /**
+     * 订阅事件
+     *
+     * 当用户订阅小程序通知时触发的事件类型
+     * 通常在用户点击允许接收订阅消息后触发
+     */
+    String SUBSCRIBE = "subscribe";
+
+    /**
+     * 取消订阅事件
+     *
+     * 当用户取消订阅小程序通知时触发的事件类型
+     * 通常在用户点击拒绝接收订阅消息或在设置中关闭订阅后触发
+     */
+    String UNSUBSCRIBE = "unSubscribe";
+
+    /**
+     * 订阅消息弹窗事件
+     *
+     * 当用户点击订阅消息弹窗中的“不再弹出”按钮时触发的事件类型
+     * 通常在用户点击拒绝接收订阅消息或在设置中关闭订阅后触发
+     */
+    String SUBSCRIBE_MSG_POPUP_EVENT = "subscribeMsgPopupEvent";
+
+}

+ 27 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/constant/WxAppletSubscribeStatusStringType.java

@@ -0,0 +1,27 @@
+package cn.tr.module.smart.wx.constant;
+/**
+ * 微信小程序订阅状态字符串类型常量类
+ *
+ * 该类定义了微信小程序订阅消息的状态类型常量,
+ * 用于表示用户对订阅消息的接受或拒绝状态。
+ *
+ * @author lingma
+ * @date 2025/08/26
+ */
+public interface WxAppletSubscribeStatusStringType {
+
+
+    /**
+     * 接受状态
+     *
+     * 表示用户接受了订阅消息的推送请求
+     */
+    public static final String ACCEPT = "accept";
+
+    /**
+     * 拒绝状态
+     *
+     * 表示用户拒绝了订阅消息的推送请求
+     */
+    public static final String REJECT = "reject";
+}

+ 40 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/handler/SubscribeMsgPopupEventHandler.java

@@ -0,0 +1,40 @@
+package cn.tr.module.smart.wx.handler;
+
+import cn.hutool.core.util.StrUtil;
+import cn.tr.module.smart.common.repository.BizWxUserMpCareRepository;
+import cn.tr.module.smart.wx.constant.WxAppletSubscribeStatusStringType;
+import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.session.WxSessionManager;
+import me.chanjar.weixin.mp.api.WxMpMessageHandler;
+import me.chanjar.weixin.mp.api.WxMpService;
+import me.chanjar.weixin.mp.bean.message.WxMpSubscribeMsgEvent;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+@Component
+@Slf4j
+public class SubscribeMsgPopupEventHandler implements WxMpMessageHandler {
+    @Autowired
+    private BizWxUserMpCareRepository wxUserMpCareRepository;
+
+    @Override
+    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
+        WxMpSubscribeMsgEvent.SubscribeMsgPopupEvent subscribeMsgPopupEvent = wxMessage.getSubscribeMsgPopupEvent();
+        String unionId = wxMessage.getUnionId();
+        for (WxMpSubscribeMsgEvent.PopupEvent popupEvent : subscribeMsgPopupEvent.getList()) {
+            String subscribeStatusString = popupEvent.getSubscribeStatusString();
+            String templateId = popupEvent.getTemplateId();
+            if (StrUtil.equals(subscribeStatusString, WxAppletSubscribeStatusStringType.ACCEPT)) {
+                log.debug("[WxMpSubscribeMsgEvent] unionId:{},templateId:{},subscribeStatusString:{}", unionId, templateId, subscribeStatusString);
+            }else if (StrUtil.equals(subscribeStatusString, WxAppletSubscribeStatusStringType.REJECT)) {
+                log.debug("[WxMpSubscribeMsgEvent] unionId:{},templateId:{},subscribeStatusString:{}", unionId, templateId, subscribeStatusString);
+            }
+        }
+        return null;
+    }
+}

+ 0 - 8
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/handler/UnSubscribeMsgHandler.java

@@ -1,22 +1,14 @@
 package cn.tr.module.smart.wx.handler;
 
-import cn.binarywang.wx.miniapp.api.WxMaService;
-import cn.binarywang.wx.miniapp.bean.WxMaMessage;
-import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
-import cn.binarywang.wx.miniapp.message.WxMaMessageHandler;
-import cn.binarywang.wx.miniapp.message.WxMaXmlOutMessage;
 import cn.tr.module.smart.common.po.BizWxUserMpCarePO;
 import cn.tr.module.smart.common.repository.BizWxUserMpCareRepository;
-import cn.tr.module.smart.common.repository.BizWxUserRepository;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.google.common.collect.Lists;
 import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.common.session.WxSessionManager;
 import me.chanjar.weixin.mp.api.WxMpMessageHandler;
 import me.chanjar.weixin.mp.api.WxMpService;
 import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
 import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
-import me.chanjar.weixin.mp.bean.result.WxMpUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 

+ 2 - 1
tr-test/src/main/resources/application.yml

@@ -8,7 +8,8 @@ server:
 mybatis-plus:
   mapper-locations: classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml,classpath*:mapper/*/*.xml
   configuration:
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
+#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
   global-config:
     db-config:
       logic-delete-value: 1

+ 1 - 1
tr-test/src/main/resources/log4j2.xml

@@ -37,7 +37,7 @@
     <Loggers>
         <logger name="org.springframework" level="INFO"></logger>
         <logger name="org.mybatis" level="INFO"></logger>
-        <logger name="net.x52im.mobileimsdk" level="WARN"></logger>
+<!--        <logger name="net.x52im.mobileimsdk" level="WARN"></logger>-->
         <Root level="INFO">
             <AppenderRef ref="Console"/>
             <AppenderRef ref="RollingFile"/>