Ver Fonte

关注回复
签到回复
关键词回复

lijilei há 3 anos atrás
pai
commit
e76be9d0f9
32 ficheiros alterados com 1228 adições e 38 exclusões
  1. 3 0
      book-dao/src/main/java/com/book/dao/cps/mapper/UserMapper.java
  2. 24 0
      book-dao/src/main/java/com/book/dao/cps/mapper/WechatAutoreplyMapper.java
  3. 22 0
      book-dao/src/main/java/com/book/dao/cps/mapper/WechatSubscribeConfigMapper.java
  4. 22 0
      book-dao/src/main/java/com/book/dao/cps/mapper/WechatSubscribeSwitchMapper.java
  5. 30 1
      book-dao/src/main/java/com/book/dao/cps/pojo/AdminConfig.java
  6. 95 0
      book-dao/src/main/java/com/book/dao/cps/pojo/WechatAutoreply.java
  7. 85 0
      book-dao/src/main/java/com/book/dao/cps/pojo/WechatSubscribeConfig.java
  8. 40 0
      book-dao/src/main/java/com/book/dao/cps/pojo/WechatSubscribeSwitch.java
  9. 0 0
      book-dao/src/main/resources/mapper/cps/ManageCoverMapper.xml
  10. 0 0
      book-dao/src/main/resources/mapper/cps/ManageTitleMapper.xml
  11. 0 0
      book-dao/src/main/resources/mapper/cps/SignRecommandMapper.xml
  12. 0 0
      book-dao/src/main/resources/mapper/cps/SignedRecommandMapper.xml
  13. 7 0
      book-dao/src/main/resources/mapper/cps/UserMapper.xml
  14. 235 0
      book-dao/src/main/resources/mapper/cps/WechatAutoreplyMapper.xml
  15. 215 0
      book-dao/src/main/resources/mapper/cps/WechatSubscribeConfigMapper.xml
  16. 104 0
      book-dao/src/main/resources/mapper/cps/WechatSubscribeSwitchMapper.xml
  17. 9 0
      book-push/src/main/java/com/book/push/builder/TuWenBuilder.java
  18. 2 2
      book-push/src/main/java/com/book/push/cons/UrlCons.java
  19. 6 0
      book-push/src/main/java/com/book/push/controller/WxEventController.java
  20. 3 3
      book-push/src/main/java/com/book/push/handler/MenuHandler.java
  21. 64 17
      book-push/src/main/java/com/book/push/handler/MsgHandler.java
  22. 83 9
      book-push/src/main/java/com/book/push/handler/SubscribeHandler.java
  23. 13 6
      book-push/src/main/java/com/book/push/service/dao/UserService.java
  24. 17 0
      book-push/src/main/java/com/book/push/service/dao/WechatAutoreplayService.java
  25. 14 0
      book-push/src/main/java/com/book/push/service/dao/WechatSubscribeConfigService.java
  26. 14 0
      book-push/src/main/java/com/book/push/service/dao/WechatSubscribeSwitchService.java
  27. 5 0
      book-push/src/main/java/com/book/push/service/dao/impl/UserServiceImpl.java
  28. 27 0
      book-push/src/main/java/com/book/push/service/dao/impl/WechatAutoreplayServiceImpl.java
  29. 24 0
      book-push/src/main/java/com/book/push/service/dao/impl/WechatSubscribeConfigServiceImpl.java
  30. 23 0
      book-push/src/main/java/com/book/push/service/dao/impl/WechatSubscribeSwitchServiceImpl.java
  31. 23 0
      book-push/src/main/java/com/book/push/vo/NewsMsgContent.java
  32. 19 0
      book-push/src/main/java/com/book/push/vo/TextMsgContent.java

+ 3 - 0
book-dao/src/main/java/com/book/dao/cps/mapper/UserMapper.java

@@ -30,4 +30,7 @@ public interface UserMapper {
 
 
     List<User> selectListByPushMap(Map map);
+
+
+    void updateOperateTimeByOpenid(@Param("operateTime") String openid, @Param("operateTime") Integer operateTime);
 }

+ 24 - 0
book-dao/src/main/java/com/book/dao/cps/mapper/WechatAutoreplyMapper.java

@@ -0,0 +1,24 @@
+package com.book.dao.cps.mapper;
+
+import com.book.dao.cps.pojo.WechatAutoreply;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface WechatAutoreplyMapper {
+    int deleteByPrimaryKey(Integer id);
+
+    int insert(WechatAutoreply record);
+
+    int insertSelective(WechatAutoreply record);
+
+    WechatAutoreply selectByPrimaryKey(Integer id);
+
+    int updateByPrimaryKeySelective(WechatAutoreply record);
+
+    int updateByPrimaryKey(WechatAutoreply record);
+
+    WechatAutoreply selectByText(@Param("text") String text);
+
+    WechatAutoreply selectByAdminIdAndText(@Param("admin_id") Integer adminId, String text);
+}

+ 22 - 0
book-dao/src/main/java/com/book/dao/cps/mapper/WechatSubscribeConfigMapper.java

@@ -0,0 +1,22 @@
+package com.book.dao.cps.mapper;
+
+import com.book.dao.cps.pojo.WechatSubscribeConfig;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface WechatSubscribeConfigMapper {
+    int deleteByPrimaryKey(Integer id);
+
+    int insert(WechatSubscribeConfig record);
+
+    int insertSelective(WechatSubscribeConfig record);
+
+    WechatSubscribeConfig selectByPrimaryKey(Integer id);
+
+    int updateByPrimaryKeySelective(WechatSubscribeConfig record);
+
+    int updateByPrimaryKey(WechatSubscribeConfig record);
+
+    WechatSubscribeConfig selectByAdminId(@Param("admin_id") Integer adminId);
+}

+ 22 - 0
book-dao/src/main/java/com/book/dao/cps/mapper/WechatSubscribeSwitchMapper.java

@@ -0,0 +1,22 @@
+package com.book.dao.cps.mapper;
+
+import com.book.dao.cps.pojo.WechatSubscribeSwitch;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface WechatSubscribeSwitchMapper {
+    int deleteByPrimaryKey(Integer id);
+
+    int insert(WechatSubscribeSwitch record);
+
+    int insertSelective(WechatSubscribeSwitch record);
+
+    WechatSubscribeSwitch selectByPrimaryKey(Integer id);
+
+    int updateByPrimaryKeySelective(WechatSubscribeSwitch record);
+
+    int updateByPrimaryKey(WechatSubscribeSwitch record);
+
+    WechatSubscribeSwitch selectByAdminId(@Param("admin_id") Integer adminId);
+}

+ 30 - 1
book-dao/src/main/java/com/book/dao/cps/pojo/AdminConfig.java

@@ -7,7 +7,8 @@ import java.math.BigDecimal;
 
 /**
  * admin_config
- * @author 
+ *
+ * @author
  */
 @Data
 public class AdminConfig implements Serializable {
@@ -437,6 +438,34 @@ public class AdminConfig implements Serializable {
      * OPPO回传开关:0=关,1=开
      */
     private Byte oppoCallback;
+    private Info info;
+
+
+    @Data
+    public static class Info {
+        private AuthorizationInfo authorization_info;
+        private AuthorizerInfo authorizer_info;
+
+    }
+
+    @Data
+    public static class AuthorizationInfo {
+
+        private String authorizer_appid;
+        private String authorizer_refresh_token;
+    }
+
+    @Data
+    public static class AuthorizerInfo {
+        private String alias;
+        private int idc;
+        private String nick_name;
+        private String principal_name;
+        private String qrcode_url;
+        private String signature;
+        private String user_name;
+
+    }
 
     private static final long serialVersionUID = 1L;
 }

+ 95 - 0
book-dao/src/main/java/com/book/dao/cps/pojo/WechatAutoreply.java

@@ -0,0 +1,95 @@
+package com.book.dao.cps.pojo;
+
+import java.io.Serializable;
+import lombok.Data;
+
+/**
+ * wechat_autoreply
+ * @author 
+ */
+@Data
+public class WechatAutoreply implements Serializable {
+    private Integer id;
+
+    /**
+     * 管理员ID
+     */
+    private Integer adminId;
+
+    /**
+     * 标题
+     */
+    private String title;
+
+    /**
+     * 触发文本
+     */
+    private String text;
+
+    /**
+     * 响应事件
+     */
+    private String eventkey;
+
+    /**
+     * 备注
+     */
+    private String remark;
+
+    /**
+     * 添加时间
+     */
+    private Integer createtime;
+
+    /**
+     * 更新时间
+     */
+    private Integer updatetime;
+
+    /**
+     * 状态
+     */
+    private String status;
+
+    /**
+     * 模式
+     */
+    private String type;
+
+    /**
+     * 文本填充信息
+     */
+    private String textTipWord;
+
+    /**
+     * 文本原始信息
+     */
+    private String textContent;
+
+    /**
+     * 图文原始信息
+     */
+    private String newsContent;
+
+    /**
+     * 资源索引
+     */
+    private String eventKeys;
+
+    /**
+     * 书籍信息
+     */
+    private String books;
+
+    /**
+     * 关联的vip数据id
+     */
+    private Integer pid;
+
+    /**
+     * 关联的vip数据id
+     */
+    private Integer test;
+
+    private static final long serialVersionUID = 1L;
+}

+ 85 - 0
book-dao/src/main/java/com/book/dao/cps/pojo/WechatSubscribeConfig.java

@@ -0,0 +1,85 @@
+package com.book.dao.cps.pojo;
+
+import java.io.Serializable;
+import lombok.Data;
+
+/**
+ * wechat_subscribe_config
+ * @author 
+ */
+@Data
+public class WechatSubscribeConfig implements Serializable {
+    private Integer id;
+
+    /**
+     * 渠道ID
+     */
+    private Integer adminId;
+
+    /**
+     * 类型:default=系统默认,text=文字模式,news=图文模式
+     */
+    private Object type;
+
+    /**
+     * 资源事件
+     */
+    private String eventKeys;
+
+    /**
+     * 文本资源
+     */
+    private String textContent;
+
+    /**
+     * 图文资源
+     */
+    private String newsContent;
+
+    /**
+     * 是否启用自动回复:normal=启用,hidden=未启用
+     */
+    private Object status;
+
+    /**
+     * 创建时间
+     */
+    private Integer createtime;
+
+    /**
+     * 更新时间
+     */
+    private Integer updatetime;
+
+    /**
+     * 文字模式提示信息
+     */
+    private String textTipWord;
+
+    /**
+     * 签到类型,1回复签到,2自动签到
+     */
+    private Byte signType;
+
+    /**
+     * 自动签到展示文案
+     */
+    private String signTxt;
+
+    /**
+     * 标题
+     */
+    private String title;
+
+    /**
+     * 开始时间
+     */
+    private Integer starttime;
+
+    /**
+     * 结束时间
+     */
+    private Integer endtime;
+
+    private static final long serialVersionUID = 1L;
+}

+ 40 - 0
book-dao/src/main/java/com/book/dao/cps/pojo/WechatSubscribeSwitch.java

@@ -0,0 +1,40 @@
+package com.book.dao.cps.pojo;
+
+import java.io.Serializable;
+import lombok.Data;
+
+/**
+ * wechat_subscribe_switch
+ * @author 
+ */
+@Data
+public class WechatSubscribeSwitch implements Serializable {
+    private Integer id;
+
+    /**
+     * 渠道ID
+     */
+    private Integer adminId;
+
+    /**
+     * 开关;1:开;2;关
+     */
+    private Byte status;
+
+    /**
+     * 类型;1:系统;2:自定义
+     */
+    private Byte type;
+
+    /**
+     * 创建时间
+     */
+    private Integer createtime;
+
+    /**
+     * 更新时间
+     */
+    private Integer updatetime;
+
+    private static final long serialVersionUID = 1L;
+}

+ 0 - 0
book-dao/src/main/resources/mapper/ManageCoverMapper.xml → book-dao/src/main/resources/mapper/cps/ManageCoverMapper.xml


+ 0 - 0
book-dao/src/main/resources/mapper/ManageTitleMapper.xml → book-dao/src/main/resources/mapper/cps/ManageTitleMapper.xml


+ 0 - 0
book-dao/src/main/resources/mapper/SignRecommandMapper.xml → book-dao/src/main/resources/mapper/cps/SignRecommandMapper.xml


+ 0 - 0
book-dao/src/main/resources/mapper/SignedRecommandMapper.xml → book-dao/src/main/resources/mapper/cps/SignedRecommandMapper.xml


+ 7 - 0
book-dao/src/main/resources/mapper/cps/UserMapper.xml

@@ -421,4 +421,11 @@
           and kandian = #{user.kandian}
           and free_kandian = #{user.freeKandian}
     </update>
+    <update id="updateOperateTimeByOpenid">
+        update user
+        set operate_time =#{operateTime}
+          , updatetime=#{operateTime}
+        where openid = #{openid}
+
+    </update>
 </mapper>

+ 235 - 0
book-dao/src/main/resources/mapper/cps/WechatAutoreplyMapper.xml

@@ -0,0 +1,235 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.book.dao.cps.mapper.WechatAutoreplyMapper">
+  <resultMap id="BaseResultMap" type="com.book.dao.cps.pojo.WechatAutoreply">
+    <id column="id" jdbcType="INTEGER" property="id" />
+    <result column="admin_id" jdbcType="INTEGER" property="adminId" />
+    <result column="title" jdbcType="VARCHAR" property="title" />
+    <result column="text" jdbcType="VARCHAR" property="text" />
+    <result column="eventkey" jdbcType="VARCHAR" property="eventkey" />
+    <result column="remark" jdbcType="VARCHAR" property="remark" />
+    <result column="createtime" jdbcType="INTEGER" property="createtime" />
+    <result column="updatetime" jdbcType="INTEGER" property="updatetime" />
+    <result column="status" jdbcType="VARCHAR" property="status" />
+    <result column="type" jdbcType="VARCHAR" property="type" />
+    <result column="text_tip_word" jdbcType="VARCHAR" property="textTipWord" />
+    <result column="text_content" jdbcType="VARCHAR" property="textContent" />
+    <result column="news_content" jdbcType="VARCHAR" property="newsContent" />
+    <result column="event_keys" jdbcType="VARCHAR" property="eventKeys" />
+    <result column="books" jdbcType="VARCHAR" property="books" />
+    <result column="pid" jdbcType="INTEGER" property="pid" />
+    <result column="test" jdbcType="INTEGER" property="test" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    id, admin_id, title, `text`, eventkey, remark, createtime, updatetime, `status`, 
+    `type`, text_tip_word, text_content, news_content, event_keys, books, pid, test
+  </sql>
+  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
+    select 
+    <include refid="Base_Column_List" />
+    from wechat_autoreply
+    where id = #{id,jdbcType=INTEGER}
+  </select>
+  <select id="selectByText"  resultMap="BaseResultMap">
+        select  * from wechat_autoreply where text = #{text}
+
+  </select>
+  <select id="selectByAdminIdAndText" resultMap="BaseResultMap">
+          select  * from wechat_autoreply where admin_id = #{admin_id} and text = #{text}
+</select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
+    delete from wechat_autoreply
+    where id = #{id,jdbcType=INTEGER}
+  </delete>
+  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.book.dao.cps.pojo.WechatAutoreply" useGeneratedKeys="true">
+    insert into wechat_autoreply (admin_id, title, `text`, 
+      eventkey, remark, createtime, 
+      updatetime, `status`, `type`, 
+      text_tip_word, text_content, news_content, 
+      event_keys, books, pid, 
+      test)
+    values (#{adminId,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{text,jdbcType=VARCHAR}, 
+      #{eventkey,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{createtime,jdbcType=INTEGER}, 
+      #{updatetime,jdbcType=INTEGER}, #{status,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, 
+      #{textTipWord,jdbcType=VARCHAR}, #{textContent,jdbcType=VARCHAR}, #{newsContent,jdbcType=VARCHAR}, 
+      #{eventKeys,jdbcType=VARCHAR}, #{books,jdbcType=VARCHAR}, #{pid,jdbcType=INTEGER}, 
+      #{test,jdbcType=INTEGER})
+  </insert>
+  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.book.dao.cps.pojo.WechatAutoreply" useGeneratedKeys="true">
+    insert into wechat_autoreply
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="adminId != null">
+        admin_id,
+      </if>
+      <if test="title != null">
+        title,
+      </if>
+      <if test="text != null">
+        `text`,
+      </if>
+      <if test="eventkey != null">
+        eventkey,
+      </if>
+      <if test="remark != null">
+        remark,
+      </if>
+      <if test="createtime != null">
+        createtime,
+      </if>
+      <if test="updatetime != null">
+        updatetime,
+      </if>
+      <if test="status != null">
+        `status`,
+      </if>
+      <if test="type != null">
+        `type`,
+      </if>
+      <if test="textTipWord != null">
+        text_tip_word,
+      </if>
+      <if test="textContent != null">
+        text_content,
+      </if>
+      <if test="newsContent != null">
+        news_content,
+      </if>
+      <if test="eventKeys != null">
+        event_keys,
+      </if>
+      <if test="books != null">
+        books,
+      </if>
+      <if test="pid != null">
+        pid,
+      </if>
+      <if test="test != null">
+        test,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="adminId != null">
+        #{adminId,jdbcType=INTEGER},
+      </if>
+      <if test="title != null">
+        #{title,jdbcType=VARCHAR},
+      </if>
+      <if test="text != null">
+        #{text,jdbcType=VARCHAR},
+      </if>
+      <if test="eventkey != null">
+        #{eventkey,jdbcType=VARCHAR},
+      </if>
+      <if test="remark != null">
+        #{remark,jdbcType=VARCHAR},
+      </if>
+      <if test="createtime != null">
+        #{createtime,jdbcType=INTEGER},
+      </if>
+      <if test="updatetime != null">
+        #{updatetime,jdbcType=INTEGER},
+      </if>
+      <if test="status != null">
+        #{status,jdbcType=VARCHAR},
+      </if>
+      <if test="type != null">
+        #{type,jdbcType=VARCHAR},
+      </if>
+      <if test="textTipWord != null">
+        #{textTipWord,jdbcType=VARCHAR},
+      </if>
+      <if test="textContent != null">
+        #{textContent,jdbcType=VARCHAR},
+      </if>
+      <if test="newsContent != null">
+        #{newsContent,jdbcType=VARCHAR},
+      </if>
+      <if test="eventKeys != null">
+        #{eventKeys,jdbcType=VARCHAR},
+      </if>
+      <if test="books != null">
+        #{books,jdbcType=VARCHAR},
+      </if>
+      <if test="pid != null">
+        #{pid,jdbcType=INTEGER},
+      </if>
+      <if test="test != null">
+        #{test,jdbcType=INTEGER},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.book.dao.cps.pojo.WechatAutoreply">
+    update wechat_autoreply
+    <set>
+      <if test="adminId != null">
+        admin_id = #{adminId,jdbcType=INTEGER},
+      </if>
+      <if test="title != null">
+        title = #{title,jdbcType=VARCHAR},
+      </if>
+      <if test="text != null">
+        `text` = #{text,jdbcType=VARCHAR},
+      </if>
+      <if test="eventkey != null">
+        eventkey = #{eventkey,jdbcType=VARCHAR},
+      </if>
+      <if test="remark != null">
+        remark = #{remark,jdbcType=VARCHAR},
+      </if>
+      <if test="createtime != null">
+        createtime = #{createtime,jdbcType=INTEGER},
+      </if>
+      <if test="updatetime != null">
+        updatetime = #{updatetime,jdbcType=INTEGER},
+      </if>
+      <if test="status != null">
+        `status` = #{status,jdbcType=VARCHAR},
+      </if>
+      <if test="type != null">
+        `type` = #{type,jdbcType=VARCHAR},
+      </if>
+      <if test="textTipWord != null">
+        text_tip_word = #{textTipWord,jdbcType=VARCHAR},
+      </if>
+      <if test="textContent != null">
+        text_content = #{textContent,jdbcType=VARCHAR},
+      </if>
+      <if test="newsContent != null">
+        news_content = #{newsContent,jdbcType=VARCHAR},
+      </if>
+      <if test="eventKeys != null">
+        event_keys = #{eventKeys,jdbcType=VARCHAR},
+      </if>
+      <if test="books != null">
+        books = #{books,jdbcType=VARCHAR},
+      </if>
+      <if test="pid != null">
+        pid = #{pid,jdbcType=INTEGER},
+      </if>
+      <if test="test != null">
+        test = #{test,jdbcType=INTEGER},
+      </if>
+    </set>
+    where id = #{id,jdbcType=INTEGER}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.book.dao.cps.pojo.WechatAutoreply">
+    update wechat_autoreply
+    set admin_id = #{adminId,jdbcType=INTEGER},
+      title = #{title,jdbcType=VARCHAR},
+      `text` = #{text,jdbcType=VARCHAR},
+      eventkey = #{eventkey,jdbcType=VARCHAR},
+      remark = #{remark,jdbcType=VARCHAR},
+      createtime = #{createtime,jdbcType=INTEGER},
+      updatetime = #{updatetime,jdbcType=INTEGER},
+      `status` = #{status,jdbcType=VARCHAR},
+      `type` = #{type,jdbcType=VARCHAR},
+      text_tip_word = #{textTipWord,jdbcType=VARCHAR},
+      text_content = #{textContent,jdbcType=VARCHAR},
+      news_content = #{newsContent,jdbcType=VARCHAR},
+      event_keys = #{eventKeys,jdbcType=VARCHAR},
+      books = #{books,jdbcType=VARCHAR},
+      pid = #{pid,jdbcType=INTEGER},
+      test = #{test,jdbcType=INTEGER}
+    where id = #{id,jdbcType=INTEGER}
+  </update>
+</mapper>

+ 215 - 0
book-dao/src/main/resources/mapper/cps/WechatSubscribeConfigMapper.xml

@@ -0,0 +1,215 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.book.dao.cps.mapper.WechatSubscribeConfigMapper">
+    <resultMap id="BaseResultMap" type="com.book.dao.cps.pojo.WechatSubscribeConfig">
+        <id column="id" jdbcType="INTEGER" property="id"/>
+        <result column="admin_id" jdbcType="INTEGER" property="adminId"/>
+        <result column="type" jdbcType="OTHER" property="type"/>
+        <result column="event_keys" jdbcType="VARCHAR" property="eventKeys"/>
+        <result column="text_content" jdbcType="VARCHAR" property="textContent"/>
+        <result column="news_content" jdbcType="VARCHAR" property="newsContent"/>
+        <result column="status" jdbcType="OTHER" property="status"/>
+        <result column="createtime" jdbcType="INTEGER" property="createtime"/>
+        <result column="updatetime" jdbcType="INTEGER" property="updatetime"/>
+        <result column="text_tip_word" jdbcType="VARCHAR" property="textTipWord"/>
+        <result column="sign_type" jdbcType="TINYINT" property="signType"/>
+        <result column="sign_txt" jdbcType="VARCHAR" property="signTxt"/>
+        <result column="title" jdbcType="VARCHAR" property="title"/>
+        <result column="starttime" jdbcType="INTEGER" property="starttime"/>
+        <result column="endtime" jdbcType="INTEGER" property="endtime"/>
+    </resultMap>
+    <sql id="Base_Column_List">
+        id, admin_id, `type`, event_keys, text_content, news_content, `status`, createtime,
+    updatetime, text_tip_word, sign_type, sign_txt, title, starttime, endtime
+    </sql>
+    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from wechat_subscribe_config
+        where id = #{id,jdbcType=INTEGER}
+    </select>
+    <select id="selectByAdminId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from wechat_subscribe_config
+        where admin_id = #{admin_id,jdbcType=INTEGER}
+        and (UNIX_TIMESTAMP(NOW()) between starttime and endtime)
+        order by createtime desc limit 1
+    </select>
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
+        delete
+        from wechat_subscribe_config
+        where id = #{id,jdbcType=INTEGER}
+    </delete>
+    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.book.dao.cps.pojo.WechatSubscribeConfig"
+            useGeneratedKeys="true">
+        insert into wechat_subscribe_config (admin_id, `type`, event_keys,
+                                             text_content, news_content, `status`,
+                                             createtime, updatetime, text_tip_word,
+                                             sign_type, sign_txt, title,
+                                             starttime, endtime)
+        values (#{adminId,jdbcType=INTEGER}, #{type,jdbcType=OTHER}, #{eventKeys,jdbcType=VARCHAR},
+                #{textContent,jdbcType=VARCHAR}, #{newsContent,jdbcType=VARCHAR}, #{status,jdbcType=OTHER},
+                #{createtime,jdbcType=INTEGER}, #{updatetime,jdbcType=INTEGER}, #{textTipWord,jdbcType=VARCHAR},
+                #{signType,jdbcType=TINYINT}, #{signTxt,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR},
+                #{starttime,jdbcType=INTEGER}, #{endtime,jdbcType=INTEGER})
+    </insert>
+    <insert id="insertSelective" keyColumn="id" keyProperty="id"
+            parameterType="com.book.dao.cps.pojo.WechatSubscribeConfig" useGeneratedKeys="true">
+        insert into wechat_subscribe_config
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="adminId != null">
+                admin_id,
+            </if>
+            <if test="type != null">
+                `type`,
+            </if>
+            <if test="eventKeys != null">
+                event_keys,
+            </if>
+            <if test="textContent != null">
+                text_content,
+            </if>
+            <if test="newsContent != null">
+                news_content,
+            </if>
+            <if test="status != null">
+                `status`,
+            </if>
+            <if test="createtime != null">
+                createtime,
+            </if>
+            <if test="updatetime != null">
+                updatetime,
+            </if>
+            <if test="textTipWord != null">
+                text_tip_word,
+            </if>
+            <if test="signType != null">
+                sign_type,
+            </if>
+            <if test="signTxt != null">
+                sign_txt,
+            </if>
+            <if test="title != null">
+                title,
+            </if>
+            <if test="starttime != null">
+                starttime,
+            </if>
+            <if test="endtime != null">
+                endtime,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="adminId != null">
+                #{adminId,jdbcType=INTEGER},
+            </if>
+            <if test="type != null">
+                #{type,jdbcType=OTHER},
+            </if>
+            <if test="eventKeys != null">
+                #{eventKeys,jdbcType=VARCHAR},
+            </if>
+            <if test="textContent != null">
+                #{textContent,jdbcType=VARCHAR},
+            </if>
+            <if test="newsContent != null">
+                #{newsContent,jdbcType=VARCHAR},
+            </if>
+            <if test="status != null">
+                #{status,jdbcType=OTHER},
+            </if>
+            <if test="createtime != null">
+                #{createtime,jdbcType=INTEGER},
+            </if>
+            <if test="updatetime != null">
+                #{updatetime,jdbcType=INTEGER},
+            </if>
+            <if test="textTipWord != null">
+                #{textTipWord,jdbcType=VARCHAR},
+            </if>
+            <if test="signType != null">
+                #{signType,jdbcType=TINYINT},
+            </if>
+            <if test="signTxt != null">
+                #{signTxt,jdbcType=VARCHAR},
+            </if>
+            <if test="title != null">
+                #{title,jdbcType=VARCHAR},
+            </if>
+            <if test="starttime != null">
+                #{starttime,jdbcType=INTEGER},
+            </if>
+            <if test="endtime != null">
+                #{endtime,jdbcType=INTEGER},
+            </if>
+        </trim>
+    </insert>
+    <update id="updateByPrimaryKeySelective" parameterType="com.book.dao.cps.pojo.WechatSubscribeConfig">
+        update wechat_subscribe_config
+        <set>
+            <if test="adminId != null">
+                admin_id = #{adminId,jdbcType=INTEGER},
+            </if>
+            <if test="type != null">
+                `type` = #{type,jdbcType=OTHER},
+            </if>
+            <if test="eventKeys != null">
+                event_keys = #{eventKeys,jdbcType=VARCHAR},
+            </if>
+            <if test="textContent != null">
+                text_content = #{textContent,jdbcType=VARCHAR},
+            </if>
+            <if test="newsContent != null">
+                news_content = #{newsContent,jdbcType=VARCHAR},
+            </if>
+            <if test="status != null">
+                `status` = #{status,jdbcType=OTHER},
+            </if>
+            <if test="createtime != null">
+                createtime = #{createtime,jdbcType=INTEGER},
+            </if>
+            <if test="updatetime != null">
+                updatetime = #{updatetime,jdbcType=INTEGER},
+            </if>
+            <if test="textTipWord != null">
+                text_tip_word = #{textTipWord,jdbcType=VARCHAR},
+            </if>
+            <if test="signType != null">
+                sign_type = #{signType,jdbcType=TINYINT},
+            </if>
+            <if test="signTxt != null">
+                sign_txt = #{signTxt,jdbcType=VARCHAR},
+            </if>
+            <if test="title != null">
+                title = #{title,jdbcType=VARCHAR},
+            </if>
+            <if test="starttime != null">
+                starttime = #{starttime,jdbcType=INTEGER},
+            </if>
+            <if test="endtime != null">
+                endtime = #{endtime,jdbcType=INTEGER},
+            </if>
+        </set>
+        where id = #{id,jdbcType=INTEGER}
+    </update>
+    <update id="updateByPrimaryKey" parameterType="com.book.dao.cps.pojo.WechatSubscribeConfig">
+        update wechat_subscribe_config
+        set admin_id      = #{adminId,jdbcType=INTEGER},
+            `type`        = #{type,jdbcType=OTHER},
+            event_keys    = #{eventKeys,jdbcType=VARCHAR},
+            text_content  = #{textContent,jdbcType=VARCHAR},
+            news_content  = #{newsContent,jdbcType=VARCHAR},
+            `status`      = #{status,jdbcType=OTHER},
+            createtime    = #{createtime,jdbcType=INTEGER},
+            updatetime    = #{updatetime,jdbcType=INTEGER},
+            text_tip_word = #{textTipWord,jdbcType=VARCHAR},
+            sign_type     = #{signType,jdbcType=TINYINT},
+            sign_txt      = #{signTxt,jdbcType=VARCHAR},
+            title         = #{title,jdbcType=VARCHAR},
+            starttime     = #{starttime,jdbcType=INTEGER},
+            endtime       = #{endtime,jdbcType=INTEGER}
+        where id = #{id,jdbcType=INTEGER}
+    </update>
+</mapper>

+ 104 - 0
book-dao/src/main/resources/mapper/cps/WechatSubscribeSwitchMapper.xml

@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.book.dao.cps.mapper.WechatSubscribeSwitchMapper">
+  <resultMap id="BaseResultMap" type="com.book.dao.cps.pojo.WechatSubscribeSwitch">
+    <id column="id" jdbcType="INTEGER" property="id" />
+    <result column="admin_id" jdbcType="INTEGER" property="adminId" />
+    <result column="status" jdbcType="TINYINT" property="status" />
+    <result column="type" jdbcType="TINYINT" property="type" />
+    <result column="createtime" jdbcType="INTEGER" property="createtime" />
+    <result column="updatetime" jdbcType="INTEGER" property="updatetime" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    id, admin_id, `status`, `type`, createtime, updatetime
+  </sql>
+  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
+    select 
+    <include refid="Base_Column_List" />
+    from wechat_subscribe_switch
+    where id = #{id,jdbcType=INTEGER}
+  </select>
+    <select id="selectByAdminId"  parameterType="java.lang.Integer" resultMap="BaseResultMap">
+      select
+      <include refid="Base_Column_List" />
+      from wechat_subscribe_switch
+      where admin_id = #{admin_id,jdbcType=INTEGER}
+    </select>
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
+    delete from wechat_subscribe_switch
+    where id = #{id,jdbcType=INTEGER}
+  </delete>
+  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.book.dao.cps.pojo.WechatSubscribeSwitch" useGeneratedKeys="true">
+    insert into wechat_subscribe_switch (admin_id, `status`, `type`, 
+      createtime, updatetime)
+    values (#{adminId,jdbcType=INTEGER}, #{status,jdbcType=TINYINT}, #{type,jdbcType=TINYINT}, 
+      #{createtime,jdbcType=INTEGER}, #{updatetime,jdbcType=INTEGER})
+  </insert>
+  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.book.dao.cps.pojo.WechatSubscribeSwitch" useGeneratedKeys="true">
+    insert into wechat_subscribe_switch
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="adminId != null">
+        admin_id,
+      </if>
+      <if test="status != null">
+        `status`,
+      </if>
+      <if test="type != null">
+        `type`,
+      </if>
+      <if test="createtime != null">
+        createtime,
+      </if>
+      <if test="updatetime != null">
+        updatetime,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="adminId != null">
+        #{adminId,jdbcType=INTEGER},
+      </if>
+      <if test="status != null">
+        #{status,jdbcType=TINYINT},
+      </if>
+      <if test="type != null">
+        #{type,jdbcType=TINYINT},
+      </if>
+      <if test="createtime != null">
+        #{createtime,jdbcType=INTEGER},
+      </if>
+      <if test="updatetime != null">
+        #{updatetime,jdbcType=INTEGER},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.book.dao.cps.pojo.WechatSubscribeSwitch">
+    update wechat_subscribe_switch
+    <set>
+      <if test="adminId != null">
+        admin_id = #{adminId,jdbcType=INTEGER},
+      </if>
+      <if test="status != null">
+        `status` = #{status,jdbcType=TINYINT},
+      </if>
+      <if test="type != null">
+        `type` = #{type,jdbcType=TINYINT},
+      </if>
+      <if test="createtime != null">
+        createtime = #{createtime,jdbcType=INTEGER},
+      </if>
+      <if test="updatetime != null">
+        updatetime = #{updatetime,jdbcType=INTEGER},
+      </if>
+    </set>
+    where id = #{id,jdbcType=INTEGER}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.book.dao.cps.pojo.WechatSubscribeSwitch">
+    update wechat_subscribe_switch
+    set admin_id = #{adminId,jdbcType=INTEGER},
+      `status` = #{status,jdbcType=TINYINT},
+      `type` = #{type,jdbcType=TINYINT},
+      createtime = #{createtime,jdbcType=INTEGER},
+      updatetime = #{updatetime,jdbcType=INTEGER}
+    where id = #{id,jdbcType=INTEGER}
+  </update>
+</mapper>

+ 9 - 0
book-push/src/main/java/com/book/push/builder/TuWenBuilder.java

@@ -7,6 +7,8 @@ import me.chanjar.weixin.mp.bean.message.WxMpXmlOutImageMessage;
 import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
 import me.chanjar.weixin.mp.bean.message.WxMpXmlOutNewsMessage;
 
+import java.util.List;
+
 /**
  * created in 2021/8/28
  * Project: book-store
@@ -30,6 +32,13 @@ public class TuWenBuilder extends AbstractBuilder {
                 .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).build();
 
 
+        return build;
+    }
+    public WxMpXmlOutMessage build(List<WxMpXmlOutNewsMessage.Item> items, WxMpXmlMessage wxMessage, WxMpService service) {
+        WxMpXmlOutNewsMessage build = WxMpXmlOutMessage.NEWS().articles(items)
+                .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).build();
+
+
         return build;
     }
 }

+ 2 - 2
book-push/src/main/java/com/book/push/cons/UrlCons.java

@@ -11,8 +11,8 @@ public class UrlCons {
 
     public static final String OAUTH2_REDIRECT_URL_LOGIN = SchemeCons.default_scheme_prefix + "://" + "%s/wx/redirect/{appid}/login";
     public static final String OAUTH2_REDIRECT_URL_SLIENT = SchemeCons.default_scheme_prefix + "://" + "%s.%s/wx/redirect/{appid}/slient";
-    public static final String FRONT_URL = SchemeCons.default_scheme_prefix + "://" + "%s.%s/%s?channelId=%d&userId=%s";
-    public static final String MODEL_BOOK = "book";
+    public static final String FRONT_URL = SchemeCons.default_scheme_prefix + "://" + "%s.%s/home.html#/%s?channelId=%d&userId=%s";
+    public static final String MODEL_BOOK = "readDetail";
 
     public static final String BOOK_URL = SchemeCons.default_scheme_prefix + "://" + "%s.%s/%s?channelId=%d&userId=%d&bookId=%s";
 

+ 6 - 0
book-push/src/main/java/com/book/push/controller/WxEventController.java

@@ -1,7 +1,9 @@
 package com.book.push.controller;
 
 import com.book.dao.cps.pojo.Platform;
+import com.book.dao.utils.DateUtils;
 import com.book.push.service.dao.PlatformService;
+import com.book.push.service.dao.UserService;
 import com.book.push.service.wx.WxThirdPartService;
 import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
@@ -30,6 +32,8 @@ public class WxEventController {
     private WxThirdPartService thirdPartService;
     @Autowired
     private PlatformService platformService;
+    @Autowired
+    private UserService userService;
 
     @RequestMapping("/mpapi/appid/{appId}")
     public Object callback(@RequestBody(required = false) String requestBody,
@@ -69,6 +73,8 @@ public class WxEventController {
             }
         } else {
             WxMpXmlOutMessage outMessage = thirdPartService.getWxThirdPartMessageRouter().route(inMessage, platform.getId(), appId);
+            //todo update user operate time
+            userService.updateOperateTimeByOpenid(inMessage.getFromUser(), DateUtils.getNow());
             if (outMessage != null) {
                 out = WxOpenXmlMessage.wxMpOutXmlMessageToEncryptedXml(outMessage, wxOpenService.getWxOpenConfigStorage());
             }

+ 3 - 3
book-push/src/main/java/com/book/push/handler/MenuHandler.java

@@ -10,7 +10,6 @@ import com.book.push.cons.SiteCons;
 import com.book.push.service.dao.*;
 import com.book.push.service.push.PushService;
 import com.book.push.service.wx.WxThirdPartService;
-import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.common.session.WxSessionManager;
 import me.chanjar.weixin.mp.api.WxMpService;
 import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
@@ -20,9 +19,8 @@ import me.chanjar.weixin.mp.bean.message.WxMpXmlOutTextMessage;
 import me.chanjar.weixin.mp.builder.kefu.NewsBuilder;
 import me.chanjar.weixin.open.api.WxOpenMpService;
 import me.chanjar.weixin.open.api.WxOpenService;
-import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Component;
 
 import java.util.Map;
@@ -43,6 +41,7 @@ public class MenuHandler extends AbstractHandler {
     private AdminConfigService adminConfigService;
     @Autowired
     private PlatformService platformService;
+    @Lazy
     @Autowired
     private WxThirdPartService wxThirdPartService;
     @Autowired
@@ -69,6 +68,7 @@ public class MenuHandler extends AbstractHandler {
         if (EventType.VIEW.equals(wxMessage.getEvent())) {
             return null;
         }
+
         String appid = wxMessage.getToUser();
         User user = userService.selectByOpenId(wxMessage.getFromUser());
         Config config = configService.selectByName(SiteCons.SIGN_KANDIAN);

+ 64 - 17
book-push/src/main/java/com/book/push/handler/MsgHandler.java

@@ -1,16 +1,31 @@
 package com.book.push.handler;
 
 import com.alibaba.fastjson.JSON;
+import com.book.dao.cps.pojo.AdminConfig;
+import com.book.dao.cps.pojo.User;
+import com.book.dao.cps.pojo.WechatAutoreply;
 import com.book.push.builder.TextBuilder;
+import com.book.push.builder.TuWenBuilder;
+import com.book.push.cons.UrlCons;
+import com.book.push.service.dao.AdminConfigService;
+import com.book.push.service.dao.OpHostService;
+import com.book.push.service.dao.UserService;
+import com.book.push.service.dao.WechatAutoreplayService;
+import com.book.push.utils.JsonUtils;
+import com.book.push.vo.NewsMsgContent;
+import com.book.push.vo.TextMsgContent;
 import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.common.session.WxSessionManager;
 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.message.WxMpXmlOutNewsMessage;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.logging.log4j.core.util.JsonUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType;
@@ -20,33 +35,65 @@ import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType;
  */
 @Component
 public class MsgHandler extends AbstractHandler {
+    @Autowired
+    private WechatAutoreplayService wechatAutoreplayService;
+    @Autowired
+    private AdminConfigService adminConfigService;
+    @Autowired
+    private UserService userService;
+    @Autowired
+    private OpHostService opHostService;
 
     @Override
     public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                     Map<String, Object> context, WxMpService weixinService,
                                     WxSessionManager sessionManager) {
 
-        if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) {
-            //TODO 可以选择将消息保存到本地
-        }
 
-        //当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
-        try {
-            if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服")
-                && weixinService.getKefuService().kfOnlineList()
-                .getKfOnlineList().size() > 0) {
-                return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE()
-                    .fromUser(wxMessage.getToUser())
-                    .toUser(wxMessage.getFromUser()).build();
+        AdminConfig adminConfig = adminConfigService.selectByAppid(wxMessage.getToUser());
+        WechatAutoreply wechatAutoreply = wechatAutoreplayService.selectByAdminIdAndText(adminConfig.getAdminId(), wxMessage.getContent());
+        User user = userService.selectByOpenId(wxMessage.getFromUser());
+        String host = opHostService.selectById(adminConfig.getOphostId()).getHost();
+        if (wechatAutoreply != null) {
+            String type = wechatAutoreply.getType();
+            if ("text".equals(type)) {
+                String textContent = wechatAutoreply.getTextContent();
+                List<TextMsgContent> textMsgContents = JsonUtils.getList(textContent, TextMsgContent.class);
+                StringBuilder sb = new StringBuilder();
+                for (TextMsgContent textMsgContent : textMsgContents) {
+                    sb.append(String.format("<a href='%s'>%s</a>\n", textMsgContent.getUrl().replace("{$ophost}", host), textMsgContent.getTitle()));
+                }
+                String nickname = user.getNickname();
+                String json = adminConfig.getJson().toString();
+                AdminConfig.Info info = JsonUtils.getObject(json, AdminConfig.Info.class);
+                String nick_name = info.getAuthorizer_info().getNick_name();
+                String msg = "@%s,欢迎关注 [%s],点击下方继续阅读 %s\n\r为了方便下次阅读,请置顶公众号";
+                msg = String.format(msg, nickname, nick_name, sb.toString());
+                return new TextBuilder().build(msg, wxMessage, weixinService);
+            } else if ("news".equals(type)) {
+
+                List<NewsMsgContent> newsMsgContents = JsonUtils.getList(wechatAutoreply.getNewsContent(), NewsMsgContent.class);
+                List<WxMpXmlOutNewsMessage.Item> items = new ArrayList<>();
+                for (NewsMsgContent newsMsgContent : newsMsgContents) {
+                    WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
+                    item.setTitle(newsMsgContent.getTitle());
+                    item.setPicUrl(newsMsgContent.getImage());
+                    item.setDescription(newsMsgContent.getDescription());
+                    String url = newsMsgContent.getUrl().replace("{$ophost}", host);
+                    if (!StringUtils.isEmpty(newsMsgContent.getBook_id())) {
+                        url = String.format(UrlCons.FRONT_URL, adminConfig.getAppid(), host, UrlCons.MODEL_BOOK, adminConfig.getAdminId(), user.getId() + "")
+                                .concat("&bookId=").concat(newsMsgContent.getBook_id()).concat("&").concat(newsMsgContent.getChapter_id());
+                    }
+                    item.setUrl(url);
+                }
+
+                new TuWenBuilder().build(items, wxMessage, weixinService);
             }
-        } catch (WxErrorException e) {
-            e.printStackTrace();
+
         }
 
-        //TODO 组装回复消息
-        String content = "收到信息内容:" + JSON.toJSONString(wxMessage);
 
-        return new TextBuilder().build(content, wxMessage, weixinService);
+        return new TextBuilder().build("success", wxMessage, weixinService);
 
     }
 

+ 83 - 9
book-push/src/main/java/com/book/push/handler/SubscribeHandler.java

@@ -2,19 +2,30 @@ package com.book.push.handler;
 
 import com.book.dao.cps.pojo.AdminConfig;
 import com.book.dao.cps.pojo.User;
+import com.book.dao.cps.pojo.WechatSubscribeConfig;
+import com.book.dao.cps.pojo.WechatSubscribeSwitch;
 import com.book.push.builder.TextBuilder;
-import com.book.push.service.dao.AdminConfigService;
-import com.book.push.service.dao.UserService;
+import com.book.push.builder.TuWenBuilder;
+import com.book.push.cons.UrlCons;
+import com.book.push.service.dao.*;
+import com.book.push.utils.JsonUtils;
+import com.book.push.vo.NewsMsgContent;
+import com.book.push.vo.TextMsgContent;
+import com.sun.xml.internal.fastinfoset.tools.FI_DOM_Or_XML_DOM_SAX_SAXEvent;
 import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.common.session.WxSessionManager;
 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.message.WxMpXmlOutNewsMessage;
 import me.chanjar.weixin.mp.bean.result.WxMpUser;
+import org.apache.commons.lang3.StringUtils;
 import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -26,6 +37,12 @@ public class SubscribeHandler extends AbstractHandler {
     private UserService userService;
     @Autowired
     private AdminConfigService adminConfigService;
+    @Autowired
+    private WechatSubscribeSwitchService wechatSubscribeSwitchService;
+    @Autowired
+    private WechatSubscribeConfigService wechatSubscribeConfigService;
+    @Autowired
+    private OpHostService opHostService;
     @Override
     public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                     Map<String, Object> context, WxMpService weixinService,
@@ -34,17 +51,22 @@ public class SubscribeHandler extends AbstractHandler {
         this.logger.info("新关注用户 OPENID: " + wxMessage.getFromUser());
 
         // 获取微信用户基本信息
+        WxMpUser userWxInfo ;
+        String openId = StringUtils.isEmpty(wxMessage.getOpenId())?wxMessage.getOpenId():wxMessage.getFromUser();
+        String appid = StringUtils.isEmpty(wxMessage.getAuthorizeAppId())?wxMessage.getToUser():wxMessage.getAuthorizeAppId();
+        AdminConfig adminConfig = adminConfigService.selectByAppid(appid);
+        User user = userService.selectByOpenId(openId);
         try {
-            WxMpUser userWxInfo = weixinService.getUserService()
+             userWxInfo = weixinService.getUserService()
                     .userInfo(wxMessage.getFromUser(), null);
             if (userWxInfo != null) {
                 // TODO 可以添加关注用户到本地数据库
 
-                String openId = userWxInfo.getOpenId();
-                User user = userService.selectByOpenId(openId);
+
+
                 if (user==null){
-                    AdminConfig adminConfig = adminConfigService.selectByAppid(wxMessage.getToUser());
-                    userService.createUserByWxUser(userWxInfo,adminConfig.getAdminId());
+
+                  user =   userService.createUserByWxUser(userWxInfo,adminConfig.getAdminId());
 
                 }
 
@@ -67,13 +89,65 @@ public class SubscribeHandler extends AbstractHandler {
             return responseResult;
         }
 
+
+
+
+
         try {
-            return new TextBuilder().build("感谢关注", wxMessage, weixinService);
+            WechatSubscribeSwitch wechatSubscribeSwitch = wechatSubscribeSwitchService.selectByAdminId(adminConfig.getAdminId());
+            Byte status = wechatSubscribeSwitch.getStatus();
+            if (status.intValue() == 0){
+
+                return new TextBuilder().build(String.format("@%s,感谢关注啦",user.getNickname()), wxMessage, weixinService);
+            }
+            if (wechatSubscribeSwitch.getType()==1){
+                return new TextBuilder().build(String.format("@%s,感谢关注啦",user.getNickname()), wxMessage, weixinService);
+            }
+            WechatSubscribeConfig wechatSubscribeConfig = wechatSubscribeConfigService.selectByAdminId(adminConfig.getAdminId());
+            if (wechatSubscribeConfig!=null){
+                String host = opHostService.selectById(adminConfig.getOphostId()).getHost();
+                String type = wechatSubscribeConfig.getType().toString();
+                if ("text".equals(type)){
+                    String textContent = wechatSubscribeConfig.getTextContent();
+                    List<TextMsgContent> textMsgContents = JsonUtils.getList(textContent, TextMsgContent.class);
+                    StringBuilder sb = new StringBuilder();
+                    for (TextMsgContent textMsgContent : textMsgContents) {
+                        sb.append(String.format("<a href='%s'>%s</a>\n", textMsgContent.getUrl().replace("{$ophost}", host), textMsgContent.getTitle()));
+                    }
+                    String nickname = user.getNickname();
+                    String json = adminConfig.getJson().toString();
+                    AdminConfig.Info info = JsonUtils.getObject(json, AdminConfig.Info.class);
+                    String nick_name = info.getAuthorizer_info().getNick_name();
+                    String msg = "@%s,欢迎关注 [%s],点击下方继续阅读 %s\n";
+                    msg = String.format(msg, nickname, nick_name, sb.toString());
+                    return new TextBuilder().build(msg, wxMessage, weixinService);
+                }else if ("news".equals(type)){
+                    List<NewsMsgContent> newsMsgContents = JsonUtils.getList(wechatSubscribeConfig.getNewsContent(), NewsMsgContent.class);
+                    List<WxMpXmlOutNewsMessage.Item> items = new ArrayList<>();
+                    for (NewsMsgContent newsMsgContent : newsMsgContents) {
+                        WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
+                        item.setTitle(newsMsgContent.getTitle());
+                        item.setPicUrl(newsMsgContent.getImage());
+                        item.setDescription(newsMsgContent.getDescription());
+                        String url = newsMsgContent.getUrl().replace("{$ophost}", host);
+                        if (!StringUtils.isEmpty(newsMsgContent.getBook_id())) {
+                            url = String.format(UrlCons.FRONT_URL, adminConfig.getAppid(), host, UrlCons.MODEL_BOOK, adminConfig.getAdminId(), user.getId() + "")
+                                    .concat("&bookId=").concat(newsMsgContent.getBook_id()).concat("&").concat(newsMsgContent.getChapter_id());
+                        }
+                        item.setUrl(url);
+                    }
+
+                 return    new TuWenBuilder().build(items, wxMessage, weixinService);
+
+                }
+            }
+
+
         } catch (Exception e) {
             this.logger.error(e.getMessage(), e);
         }
 
-        return null;
+           return new TextBuilder().build(String.format("@%s,感谢关注啦",user.getNickname()), wxMessage, weixinService);
     }
 
     /**

+ 13 - 6
book-push/src/main/java/com/book/push/service/dao/UserService.java

@@ -16,10 +16,17 @@ import java.util.Map;
  */
 
 public interface UserService {
-     User selectUserByUser(User user);
-     User selectByOpenId(String openId);
-     User selectById(Long id);
-     User createUserByWxUser(WxMpUser wxMpUser,int channel_id);
-     AdminConfig selectAdminConfigByOpenid(String openid);
-     List<User>  selectListByPushMap(Map map);
+    User selectUserByUser(User user);
+
+    User selectByOpenId(String openId);
+
+    User selectById(Long id);
+
+    User createUserByWxUser(WxMpUser wxMpUser, int channel_id);
+
+    AdminConfig selectAdminConfigByOpenid(String openid);
+
+    List<User> selectListByPushMap(Map map);
+
+    void updateOperateTimeByOpenid(String openid, Integer operateTime);
 }

+ 17 - 0
book-push/src/main/java/com/book/push/service/dao/WechatAutoreplayService.java

@@ -0,0 +1,17 @@
+package com.book.push.service.dao;
+
+import com.book.dao.cps.pojo.WechatAutoreply;
+
+/**
+ * created in 2021/8/30
+ * Project: book-store
+ *
+ * @author win7
+ */
+
+public interface WechatAutoreplayService {
+     WechatAutoreply selectByText(String text);
+     WechatAutoreply selectByAdminIdAndText(Integer adminId,String text);
+
+
+}

+ 14 - 0
book-push/src/main/java/com/book/push/service/dao/WechatSubscribeConfigService.java

@@ -0,0 +1,14 @@
+package com.book.push.service.dao;
+
+import com.book.dao.cps.pojo.WechatSubscribeConfig;
+
+/**
+ * created in 2021/8/30
+ * Project: book-store
+ *
+ * @author win7
+ */
+
+public interface WechatSubscribeConfigService {
+    WechatSubscribeConfig selectByAdminId(Integer adminId);
+}

+ 14 - 0
book-push/src/main/java/com/book/push/service/dao/WechatSubscribeSwitchService.java

@@ -0,0 +1,14 @@
+package com.book.push.service.dao;
+
+import com.book.dao.cps.pojo.WechatSubscribeSwitch;
+
+/**
+ * created in 2021/8/30
+ * Project: book-store
+ *
+ * @author win7
+ */
+
+public interface WechatSubscribeSwitchService {
+    WechatSubscribeSwitch selectByAdminId(Integer adminId);
+}

+ 5 - 0
book-push/src/main/java/com/book/push/service/dao/impl/UserServiceImpl.java

@@ -78,4 +78,9 @@ public class UserServiceImpl implements UserService {
 
         return userMapper.selectListByPushMap(map);
     }
+
+    @Override
+    public void updateOperateTimeByOpenid(String openid, Integer operateTime) {
+        userMapper.updateOperateTimeByOpenid(openid,operateTime);
+    }
 }

+ 27 - 0
book-push/src/main/java/com/book/push/service/dao/impl/WechatAutoreplayServiceImpl.java

@@ -0,0 +1,27 @@
+package com.book.push.service.dao.impl;
+
+import com.book.dao.cps.mapper.WechatAutoreplyMapper;
+import com.book.dao.cps.pojo.WechatAutoreply;
+import com.book.push.service.dao.WechatAutoreplayService;
+import org.springframework.stereotype.Service;
+
+/**
+ * created in 2021/8/30
+ * Project: book-store
+ *
+ * @author win7
+ */
+@Service
+public class WechatAutoreplayServiceImpl implements WechatAutoreplayService {
+    private WechatAutoreplyMapper wechatAutoreplyMapper;
+
+    @Override
+    public WechatAutoreply selectByText(String text) {
+        return wechatAutoreplyMapper.selectByText(text);
+    }
+
+    @Override
+    public WechatAutoreply selectByAdminIdAndText(Integer adminId,String text) {
+        return wechatAutoreplyMapper.selectByAdminIdAndText(adminId,text);
+    }
+}

+ 24 - 0
book-push/src/main/java/com/book/push/service/dao/impl/WechatSubscribeConfigServiceImpl.java

@@ -0,0 +1,24 @@
+package com.book.push.service.dao.impl;
+
+import com.book.dao.cps.mapper.WechatSubscribeConfigMapper;
+import com.book.dao.cps.pojo.WechatSubscribeConfig;
+import com.book.push.service.dao.WechatSubscribeConfigService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * created in 2021/8/30
+ * Project: book-store
+ *
+ * @author win7
+ */
+@Service
+public class WechatSubscribeConfigServiceImpl implements WechatSubscribeConfigService {
+    @Autowired
+    private WechatSubscribeConfigMapper wechatSubscribeConfigMapper;
+
+    @Override
+    public WechatSubscribeConfig selectByAdminId(Integer adminId) {
+        return wechatSubscribeConfigMapper.selectByAdminId(adminId);
+    }
+}

+ 23 - 0
book-push/src/main/java/com/book/push/service/dao/impl/WechatSubscribeSwitchServiceImpl.java

@@ -0,0 +1,23 @@
+package com.book.push.service.dao.impl;
+
+import com.book.dao.cps.mapper.WechatSubscribeSwitchMapper;
+import com.book.dao.cps.pojo.WechatSubscribeSwitch;
+import com.book.push.service.dao.WechatSubscribeSwitchService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * created in 2021/8/30
+ * Project: book-store
+ *
+ * @author win7
+ */
+@Service
+public class WechatSubscribeSwitchServiceImpl implements WechatSubscribeSwitchService {
+    @Autowired
+    private WechatSubscribeSwitchMapper wechatSubscribeSwitchMapper;
+    @Override
+    public WechatSubscribeSwitch selectByAdminId(Integer adminId) {
+        return wechatSubscribeSwitchMapper.selectByAdminId(adminId);
+    }
+}

+ 23 - 0
book-push/src/main/java/com/book/push/vo/NewsMsgContent.java

@@ -0,0 +1,23 @@
+package com.book.push.vo;
+
+import lombok.Data;
+
+/**
+ * created in 2021/8/30
+ * Project: book-store
+ *
+ * @author win7
+ */
+@Data
+public class NewsMsgContent {
+ private String book_id;
+ private String chapter_id;
+ private int image_type;
+ private String activity_url;
+ private String referral_url;
+ private String give_activity_url;
+ private String title;
+ private String image;
+ private String url;
+ private String description;
+}

+ 19 - 0
book-push/src/main/java/com/book/push/vo/TextMsgContent.java

@@ -0,0 +1,19 @@
+package com.book.push.vo;
+
+import lombok.Data;
+
+/**
+ * created in 2021/8/30
+ * Project: book-store
+ *
+ * @author win7
+ */
+@Data
+public class TextMsgContent {
+ private String title;
+ private String book_id;
+ private String chapter_id;
+ private int image_type;
+ private String referral_url;
+ private String url;
+}