diff --git a/postdischarge-common/src/main/java/com/xinelu/common/entity/MessageValueEntity.java b/postdischarge-common/src/main/java/com/xinelu/common/entity/MessageValueEntity.java new file mode 100644 index 00000000..6f3d8f24 --- /dev/null +++ b/postdischarge-common/src/main/java/com/xinelu/common/entity/MessageValueEntity.java @@ -0,0 +1,21 @@ +package com.xinelu.common.entity; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Description 消息推送信息实体类 + * @Author 纪寒 + * @Date 2024-03-26 17:09:50 + */ +@Data +public class MessageValueEntity implements Serializable { + private static final long serialVersionUID = -1257378392221120423L; + + private String value; + + public MessageValueEntity(String value) { + this.value = value; + } +} diff --git a/postdischarge-common/src/main/java/com/xinelu/common/enums/OfficialAccountEventEnum.java b/postdischarge-common/src/main/java/com/xinelu/common/enums/OfficialAccountEventEnum.java new file mode 100644 index 00000000..88c827dd --- /dev/null +++ b/postdischarge-common/src/main/java/com/xinelu/common/enums/OfficialAccountEventEnum.java @@ -0,0 +1,34 @@ +package com.xinelu.common.enums; + +import lombok.Getter; + +/** + * @Description 微信公众号事件枚举 + * @Author 纪寒 + * @Date 2024-03-25 14:38:27 + * @Version 1.0 + */ +@Getter +public enum OfficialAccountEventEnum { + /** + * 模板消息推送事件 + */ + TEMPLATESENDJOBFINISH("TEMPLATESENDJOBFINISH"), + + /** + * 关系公众号事件 + */ + SUBSCRIBE("subscribe"), + + /** + * 取关公众号事件 + */ + UNSUBSCRIBE("unsubscribe"), + ; + + final private String info; + + OfficialAccountEventEnum(String info) { + this.info = info; + } +} diff --git a/postdischarge-common/src/main/java/com/xinelu/common/enums/TemplateEventSendStatusEnum.java b/postdischarge-common/src/main/java/com/xinelu/common/enums/TemplateEventSendStatusEnum.java deleted file mode 100644 index 8d45922a..00000000 --- a/postdischarge-common/src/main/java/com/xinelu/common/enums/TemplateEventSendStatusEnum.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.xinelu.common.enums; - -import lombok.Getter; - -/** - * @Description 微信公众号模板事件消息发送状态枚举 - * @Author 纪寒 - * @Date 2024-03-25 14:38:27 - * @Version 1.0 - */ -@Getter -public enum TemplateEventSendStatusEnum { - /** - * 成功 - */ - SUCCESS("success"), - - /** - * 用户拒绝接收 - */ - REJECT("failed:user block"), - - /** - * 发送失败 - */ - FAILED("failed:system failed"), - ; - - final private String info; - - TemplateEventSendStatusEnum(String info) { - this.info = info; - } -} diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/domain/officialaccountsubscribeevent/OfficialAccountSubscribeEvent.java b/postdischarge-manage/src/main/java/com/xinelu/manage/domain/officialaccountsubscribeevent/OfficialAccountSubscribeEvent.java new file mode 100644 index 00000000..7096dbf2 --- /dev/null +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/domain/officialaccountsubscribeevent/OfficialAccountSubscribeEvent.java @@ -0,0 +1,94 @@ +package com.xinelu.manage.domain.officialaccountsubscribeevent; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.xinelu.common.annotation.Excel; +import com.xinelu.common.core.domain.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.time.LocalDateTime; + +/** + * 微信公众号关注和取消事件信息对象 official_account_subscribe_event + * + * @author xinelu + * @date 2024-03-26 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "微信公众号关注和取消事件信息对象", description = "official_account_subscribe_event") +public class OfficialAccountSubscribeEvent extends BaseEntity { + private static final long serialVersionUID = 4235213866159646854L; + /** + * 主键id + */ + private Long id; + + /** + * 微信公众号openid + */ + @ApiModelProperty(value = "微信公众号openid") + @Excel(name = "微信公众号openid") + private String openid; + + /** + * 微信公众号id + */ + @ApiModelProperty(value = "微信公众号id") + @Excel(name = "微信公众号id") + private String officialAccountAppId; + + /** + * 消息创建时间 ,yyyy-MM-dd HH:mm:ss + */ + @ApiModelProperty(value = "消息创建时间 ,yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "消息创建时间 ,yyyy-MM-dd HH:mm:ss", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime sendTime; + + /** + * 消息类型是事件,固定取值为:event + */ + @ApiModelProperty(value = "消息类型是事件,固定取值为:event") + @Excel(name = "消息类型是事件,固定取值为:event") + private String msgType; + + /** + * 事件类型,订阅:subscribe,取消订阅:unsubscribe + */ + @ApiModelProperty(value = "事件类型,订阅:subscribe,取消订阅:unsubscribe") + @Excel(name = "事件类型,订阅:subscribe,取消订阅:unsubscribe") + private String eventType; + + /** + * 订阅状态,关注:FOCUS,取消:CANCEL + */ + @ApiModelProperty(value = "订阅状态,关注:FOCUS,取消:CANCEL") + @Excel(name = "订阅状态,关注:FOCUS,取消:CANCEL") + private String subscribeStatus; + + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("openid", getOpenid()) + .append("officialAccountAppId", getOfficialAccountAppId()) + .append("sendTime", getSendTime()) + .append("msgType", getMsgType()) + .append("eventType", getEventType()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .toString(); + } +} diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/domain/officialaccounttemplateevent/OfficialAccountTemplateEvent.java b/postdischarge-manage/src/main/java/com/xinelu/manage/domain/officialaccounttemplateevent/OfficialAccountTemplateEvent.java index 0b1d7bd6..44d8c73f 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/domain/officialaccounttemplateevent/OfficialAccountTemplateEvent.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/domain/officialaccounttemplateevent/OfficialAccountTemplateEvent.java @@ -47,7 +47,7 @@ public class OfficialAccountTemplateEvent extends BaseEntity { private String patientName; /** - * 微信用户openid + * 微信公众号openid */ @ApiModelProperty(value = "微信用户openid") @Excel(name = "微信用户openid") diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/officialaccountsubscribeevent/OfficialAccountSubscribeEventMapper.java b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/officialaccountsubscribeevent/OfficialAccountSubscribeEventMapper.java new file mode 100644 index 00000000..ede879d7 --- /dev/null +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/officialaccountsubscribeevent/OfficialAccountSubscribeEventMapper.java @@ -0,0 +1,77 @@ +package com.xinelu.manage.mapper.officialaccountsubscribeevent; + +import com.xinelu.manage.domain.officialaccountsubscribeevent.OfficialAccountSubscribeEvent; + +import java.util.List; + +/** + * 微信公众号关注和取消事件信息Mapper接口 + * + * @author xinelu + * @date 2024-03-26 + */ +public interface OfficialAccountSubscribeEventMapper { + /** + * 查询微信公众号关注和取消事件信息 + * + * @param id 微信公众号关注和取消事件信息主键 + * @return 微信公众号关注和取消事件信息 + */ + OfficialAccountSubscribeEvent selectOfficialAccountSubscribeEventById(Long id); + + /** + * 查询微信公众号关注和取消事件信息列表 + * + * @param officialAccountSubscribeEvent 微信公众号关注和取消事件信息 + * @return 微信公众号关注和取消事件信息集合 + */ + List selectOfficialAccountSubscribeEventList(OfficialAccountSubscribeEvent officialAccountSubscribeEvent); + + /** + * 新增微信公众号关注和取消事件信息 + * + * @param officialAccountSubscribeEvent 微信公众号关注和取消事件信息 + * @return 结果 + */ + int insertOfficialAccountSubscribeEvent(OfficialAccountSubscribeEvent officialAccountSubscribeEvent); + + /** + * 修改微信公众号关注和取消事件信息 + * + * @param officialAccountSubscribeEvent 微信公众号关注和取消事件信息 + * @return 结果 + */ + int updateOfficialAccountSubscribeEvent(OfficialAccountSubscribeEvent officialAccountSubscribeEvent); + + /** + * 删除微信公众号关注和取消事件信息 + * + * @param id 微信公众号关注和取消事件信息主键 + * @return 结果 + */ + int deleteOfficialAccountSubscribeEventById(Long id); + + /** + * 批量删除微信公众号关注和取消事件信息 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + int deleteOfficialAccountSubscribeEventByIds(Long[] ids); + + /** + * 根据openid查询用户是否订阅公众号 + * + * @param openId 公众号openID + * @return 结果 + */ + int getSubscribeEventInfo(String openId); + + /** + * 根据openid修改订阅信息 + * + * @param officialAccountSubscribeEvent 微信公众号关注和取消事件信息 + * @return 结果 + */ + int updateSubscribeEventInfo(OfficialAccountSubscribeEvent officialAccountSubscribeEvent); +} diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/officialaccountsubscribeevent/IOfficialAccountSubscribeEventService.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/officialaccountsubscribeevent/IOfficialAccountSubscribeEventService.java new file mode 100644 index 00000000..2e855f12 --- /dev/null +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/officialaccountsubscribeevent/IOfficialAccountSubscribeEventService.java @@ -0,0 +1,61 @@ +package com.xinelu.manage.service.officialaccountsubscribeevent; + +import com.xinelu.manage.domain.officialaccountsubscribeevent.OfficialAccountSubscribeEvent; + +import java.util.List; + +/** + * 微信公众号关注和取消事件信息Service接口 + * + * @author xinelu + * @date 2024-03-26 + */ +public interface IOfficialAccountSubscribeEventService { + /** + * 查询微信公众号关注和取消事件信息 + * + * @param id 微信公众号关注和取消事件信息主键 + * @return 微信公众号关注和取消事件信息 + */ + OfficialAccountSubscribeEvent selectOfficialAccountSubscribeEventById(Long id); + + /** + * 查询微信公众号关注和取消事件信息列表 + * + * @param officialAccountSubscribeEvent 微信公众号关注和取消事件信息 + * @return 微信公众号关注和取消事件信息集合 + */ + List selectOfficialAccountSubscribeEventList(OfficialAccountSubscribeEvent officialAccountSubscribeEvent); + + /** + * 新增微信公众号关注和取消事件信息 + * + * @param officialAccountSubscribeEvent 微信公众号关注和取消事件信息 + * @return 结果 + */ + int insertOfficialAccountSubscribeEvent(OfficialAccountSubscribeEvent officialAccountSubscribeEvent); + + /** + * 修改微信公众号关注和取消事件信息 + * + * @param officialAccountSubscribeEvent 微信公众号关注和取消事件信息 + * @return 结果 + */ + int updateOfficialAccountSubscribeEvent(OfficialAccountSubscribeEvent officialAccountSubscribeEvent); + + /** + * 批量删除微信公众号关注和取消事件信息 + * + * @param ids 需要删除的微信公众号关注和取消事件信息主键集合 + * @return 结果 + */ + int deleteOfficialAccountSubscribeEventByIds(Long[] ids); + + /** + * 删除微信公众号关注和取消事件信息信息 + * + * @param id 微信公众号关注和取消事件信息主键 + * @return 结果 + */ + int deleteOfficialAccountSubscribeEventById(Long id); +} diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/officialaccountsubscribeevent/impl/OfficialAccountSubscribeEventServiceImpl.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/officialaccountsubscribeevent/impl/OfficialAccountSubscribeEventServiceImpl.java new file mode 100644 index 00000000..ec306baf --- /dev/null +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/officialaccountsubscribeevent/impl/OfficialAccountSubscribeEventServiceImpl.java @@ -0,0 +1,91 @@ +package com.xinelu.manage.service.officialaccountsubscribeevent.impl; + + +import com.xinelu.manage.domain.officialaccountsubscribeevent.OfficialAccountSubscribeEvent; +import com.xinelu.manage.mapper.officialaccountsubscribeevent.OfficialAccountSubscribeEventMapper; +import com.xinelu.manage.service.officialaccountsubscribeevent.IOfficialAccountSubscribeEventService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.util.List; + +/** + * 微信公众号关注和取消事件信息Service业务层处理 + * + * @author xinelu + * @date 2024-03-26 + */ +@Service +public class OfficialAccountSubscribeEventServiceImpl implements IOfficialAccountSubscribeEventService { + @Resource + private OfficialAccountSubscribeEventMapper officialAccountSubscribeEventMapper; + + /** + * 查询微信公众号关注和取消事件信息 + * + * @param id 微信公众号关注和取消事件信息主键 + * @return 微信公众号关注和取消事件信息 + */ + @Override + public OfficialAccountSubscribeEvent selectOfficialAccountSubscribeEventById(Long id) { + return officialAccountSubscribeEventMapper.selectOfficialAccountSubscribeEventById(id); + } + + /** + * 查询微信公众号关注和取消事件信息列表 + * + * @param officialAccountSubscribeEvent 微信公众号关注和取消事件信息 + * @return 微信公众号关注和取消事件信息 + */ + @Override + public List selectOfficialAccountSubscribeEventList(OfficialAccountSubscribeEvent officialAccountSubscribeEvent) { + return officialAccountSubscribeEventMapper.selectOfficialAccountSubscribeEventList(officialAccountSubscribeEvent); + } + + /** + * 新增微信公众号关注和取消事件信息 + * + * @param officialAccountSubscribeEvent 微信公众号关注和取消事件信息 + * @return 结果 + */ + @Override + public int insertOfficialAccountSubscribeEvent(OfficialAccountSubscribeEvent officialAccountSubscribeEvent) { + officialAccountSubscribeEvent.setCreateTime(LocalDateTime.now()); + return officialAccountSubscribeEventMapper.insertOfficialAccountSubscribeEvent(officialAccountSubscribeEvent); + } + + /** + * 修改微信公众号关注和取消事件信息 + * + * @param officialAccountSubscribeEvent 微信公众号关注和取消事件信息 + * @return 结果 + */ + @Override + public int updateOfficialAccountSubscribeEvent(OfficialAccountSubscribeEvent officialAccountSubscribeEvent) { + officialAccountSubscribeEvent.setUpdateTime(LocalDateTime.now()); + return officialAccountSubscribeEventMapper.updateOfficialAccountSubscribeEvent(officialAccountSubscribeEvent); + } + + /** + * 批量删除微信公众号关注和取消事件信息 + * + * @param ids 需要删除的微信公众号关注和取消事件信息主键 + * @return 结果 + */ + @Override + public int deleteOfficialAccountSubscribeEventByIds(Long[] ids) { + return officialAccountSubscribeEventMapper.deleteOfficialAccountSubscribeEventByIds(ids); + } + + /** + * 删除微信公众号关注和取消事件信息信息 + * + * @param id 微信公众号关注和取消事件信息主键 + * @return 结果 + */ + @Override + public int deleteOfficialAccountSubscribeEventById(Long id) { + return officialAccountSubscribeEventMapper.deleteOfficialAccountSubscribeEventById(id); + } +} diff --git a/postdischarge-manage/src/main/resources/mapper/manage/officialaccountsubscribeevent/OfficialAccountSubscribeEventMapper.xml b/postdischarge-manage/src/main/resources/mapper/manage/officialaccountsubscribeevent/OfficialAccountSubscribeEventMapper.xml new file mode 100644 index 00000000..f4628ed3 --- /dev/null +++ b/postdischarge-manage/src/main/resources/mapper/manage/officialaccountsubscribeevent/OfficialAccountSubscribeEventMapper.xml @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + select id, openid, official_account_app_id, send_time, msg_type, event_type, subscribe_status, create_by, create_time, update_by, update_time from official_account_subscribe_event + + + + + + + + insert into official_account_subscribe_event + + openid, + + official_account_app_id, + + send_time, + + msg_type, + + event_type, + + subscribe_status, + + create_by, + + create_time, + + update_by, + + update_time, + + + + #{openid}, + + #{officialAccountAppId}, + + #{sendTime}, + + #{msgType}, + + #{eventType}, + + #{subscribeStatus}, + + #{createBy}, + + #{createTime}, + + #{updateBy}, + + #{updateTime}, + + + + + + update official_account_subscribe_event + + openid = + #{openid}, + + official_account_app_id = + #{officialAccountAppId}, + + send_time = + #{sendTime}, + + msg_type = + #{msgType}, + + event_type = + #{eventType}, + + subscribe_status = + #{subscribeStatus}, + + create_by = + #{createBy}, + + create_time = + #{createTime}, + + update_by = + #{updateBy}, + + update_time = + #{updateTime}, + + + where id = #{id} + + + + delete from official_account_subscribe_event where id = #{id} + + + + delete from official_account_subscribe_event where id in + + #{id} + + + + + + + update official_account_subscribe_event + + openid = + #{openid}, + + official_account_app_id = + #{officialAccountAppId}, + + send_time = + #{sendTime}, + + msg_type = + #{msgType}, + + event_type = + #{eventType}, + + subscribe_status = + #{subscribeStatus}, + + create_by = + #{createBy}, + + create_time = + #{createTime}, + + update_by = + #{updateBy}, + + update_time = + #{updateTime}, + + + where openid = #{openid} + + \ No newline at end of file diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/controller/wechatofficialaccountcallback/WeChatOfficialAccountCallbackController.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/controller/wechatofficialaccountcallback/WeChatOfficialAccountCallbackController.java index 225dfdf6..18ad196a 100644 --- a/postdischarge-mobile/src/main/java/com/xinelu/mobile/controller/wechatofficialaccountcallback/WeChatOfficialAccountCallbackController.java +++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/controller/wechatofficialaccountcallback/WeChatOfficialAccountCallbackController.java @@ -1,6 +1,7 @@ package com.xinelu.mobile.controller.wechatofficialaccountcallback; import com.xinelu.common.config.WeChatOfficialAccountConfig; +import com.xinelu.common.enums.OfficialAccountEventEnum; import com.xinelu.common.utils.aes.AesException; import com.xinelu.common.utils.aes.WXBizMsgCrypt; import com.xinelu.mobile.dto.wechatappletcallback.MessageSignDTO; @@ -71,7 +72,15 @@ public class WeChatOfficialAccountCallbackController { log.info("院后微信公众号模板消息事件解析事件数据为空!"); return; } - weChatOfficialAccountCallbackService.handleOfficialAccountTemplateEvent(eventPush); + //微信模板公众号消息事件 + if (OfficialAccountEventEnum.TEMPLATESENDJOBFINISH.getInfo().equals(eventPush.getEvent())) { + weChatOfficialAccountCallbackService.handleOfficialAccountTemplateEvent(eventPush); + } + //微信公众号关注和取消事件 + if (OfficialAccountEventEnum.SUBSCRIBE.getInfo().equals(eventPush.getEvent()) || + OfficialAccountEventEnum.UNSUBSCRIBE.getInfo().equals(eventPush.getEvent())) { + weChatOfficialAccountCallbackService.handleOfficialAccountSubscribeEvent(eventPush); + } } } diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatofficialaccountcallback/WeChatOfficialAccountCallbackService.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatofficialaccountcallback/WeChatOfficialAccountCallbackService.java index 27e4c650..72ced160 100644 --- a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatofficialaccountcallback/WeChatOfficialAccountCallbackService.java +++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatofficialaccountcallback/WeChatOfficialAccountCallbackService.java @@ -15,4 +15,11 @@ public interface WeChatOfficialAccountCallbackService { * @param eventPushVO 模板消息事件回调数据 */ void handleOfficialAccountTemplateEvent(WeChatOfficialAccountEventPushVO eventPushVO); + + /** + * 院后微信公众号取消和关注事件回调处理 + * + * @param eventPushVO 公众号取消和关注事件回调数据 + */ + void handleOfficialAccountSubscribeEvent(WeChatOfficialAccountEventPushVO eventPushVO); } diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatofficialaccountcallback/impl/WeChatOfficialAccountCallbackServiceImpl.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatofficialaccountcallback/impl/WeChatOfficialAccountCallbackServiceImpl.java index 0f68d8af..454c8b63 100644 --- a/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatofficialaccountcallback/impl/WeChatOfficialAccountCallbackServiceImpl.java +++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/service/wechatofficialaccountcallback/impl/WeChatOfficialAccountCallbackServiceImpl.java @@ -1,9 +1,13 @@ package com.xinelu.mobile.service.wechatofficialaccountcallback.impl; +import com.xinelu.common.enums.OfficialAccountEventEnum; +import com.xinelu.common.enums.SubscribeStatusEnum; import com.xinelu.common.exception.ServiceException; import com.xinelu.common.utils.DateUtils; +import com.xinelu.manage.domain.officialaccountsubscribeevent.OfficialAccountSubscribeEvent; import com.xinelu.manage.domain.officialaccounttemplateevent.OfficialAccountTemplateEvent; import com.xinelu.manage.domain.patientinfo.PatientInfo; +import com.xinelu.manage.mapper.officialaccountsubscribeevent.OfficialAccountSubscribeEventMapper; import com.xinelu.manage.mapper.officialaccounttemplateevent.OfficialAccountTemplateEventMapper; import com.xinelu.manage.mapper.patientinfo.PatientInfoMapper; import com.xinelu.mobile.service.wechatofficialaccountcallback.WeChatOfficialAccountCallbackService; @@ -14,6 +18,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.time.LocalDateTime; import java.util.Objects; /** @@ -30,6 +35,8 @@ public class WeChatOfficialAccountCallbackServiceImpl implements WeChatOfficialA private PatientInfoMapper patientInfoMapper; @Resource private OfficialAccountTemplateEventMapper officialAccountTemplateEventMapper; + @Resource + private OfficialAccountSubscribeEventMapper officialAccountSubscribeEventMapper; /** * 院后微信公众号模板消息事件回调处理 @@ -55,6 +62,8 @@ public class WeChatOfficialAccountCallbackServiceImpl implements WeChatOfficialA templateEvent.setEventType(StringUtils.isBlank(eventPushVO.getEvent()) ? "" : eventPushVO.getEvent()); templateEvent.setMsgId(StringUtils.isBlank(eventPushVO.getMsgId()) ? "" : eventPushVO.getMsgId()); templateEvent.setStatus(StringUtils.isBlank(eventPushVO.getStatus()) ? "" : eventPushVO.getStatus()); + templateEvent.setCreateTime(LocalDateTime.now()); + templateEvent.setCreateBy("xinyilu"); int insertTemplateEventCount = officialAccountTemplateEventMapper.insertOfficialAccountTemplateEvent(templateEvent); if (insertTemplateEventCount < 0) { log.error("院后微信公众号模板事件推送,新增模板事件消息信息失败,信息为:[{}]", templateEvent); @@ -62,4 +71,63 @@ public class WeChatOfficialAccountCallbackServiceImpl implements WeChatOfficialA } log.info("院后微信公众号模板事件推送处理成功!"); } + + /** + * 院后微信公众号取消和关注事件回调处理 + * + * @param eventPushVO 公众号取消和关注事件回调数据 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void handleOfficialAccountSubscribeEvent(WeChatOfficialAccountEventPushVO eventPushVO) { + //关注公众号事件 + if (OfficialAccountEventEnum.SUBSCRIBE.getInfo().equals(eventPushVO.getEvent())) { + handleSubscribeEventInfo(eventPushVO, SubscribeStatusEnum.accept.getValue()); + } + //取消关注公众号事件 + if (OfficialAccountEventEnum.UNSUBSCRIBE.getInfo().equals(eventPushVO.getEvent())) { + handleSubscribeEventInfo(eventPushVO, SubscribeStatusEnum.rejet.getValue()); + } + } + + /** + * 处理公众号订阅信息 + * + * @param eventPushVO 公众号取消和关注事件回调数据 + * @param subscribeStatus 订阅状态 + */ + private void handleSubscribeEventInfo(WeChatOfficialAccountEventPushVO eventPushVO, String subscribeStatus) { + int subscribeEventCount = officialAccountSubscribeEventMapper.getSubscribeEventInfo(eventPushVO.getFromUserName()); + if (subscribeEventCount == 0) { + //没有订阅过,直接新增 + OfficialAccountSubscribeEvent subscribeEvent = new OfficialAccountSubscribeEvent(); + subscribeEvent.setOpenid(eventPushVO.getFromUserName()); + subscribeEvent.setOfficialAccountAppId(StringUtils.isBlank(eventPushVO.getToUserName()) ? "" : eventPushVO.getToUserName()); + subscribeEvent.setSendTime(StringUtils.isBlank(eventPushVO.getCreateTime()) ? null : DateUtils.timestampToLocalDateTime(Long.parseLong(eventPushVO.getCreateTime()) * 1000L)); + subscribeEvent.setMsgType(StringUtils.isBlank(eventPushVO.getMsgType()) ? "" : eventPushVO.getMsgType()); + subscribeEvent.setEventType(StringUtils.isBlank(eventPushVO.getEvent()) ? "" : eventPushVO.getEvent()); + subscribeEvent.setSubscribeStatus(subscribeStatus); + subscribeEvent.setCreateTime(LocalDateTime.now()); + subscribeEvent.setCreateBy("xinyilu"); + int insertSubscribeEvent = officialAccountSubscribeEventMapper.insertOfficialAccountSubscribeEvent(subscribeEvent); + if (insertSubscribeEvent < 0) { + log.error("院后微信公众号关注和取消事件,新增信息失败,信息为:[{}]", subscribeEvent); + throw new ServiceException("新增院后微信公众号关注和取消事件信息失败!"); + } + } else { + //订阅过,修改 + OfficialAccountSubscribeEvent subscribeEvent = new OfficialAccountSubscribeEvent(); + subscribeEvent.setOpenid(eventPushVO.getFromUserName()); + subscribeEvent.setSendTime(StringUtils.isBlank(eventPushVO.getCreateTime()) ? null : DateUtils.timestampToLocalDateTime(Long.parseLong(eventPushVO.getCreateTime()) * 1000L)); + subscribeEvent.setEventType(StringUtils.isBlank(eventPushVO.getEvent()) ? "" : eventPushVO.getEvent()); + subscribeEvent.setSubscribeStatus(subscribeStatus); + subscribeEvent.setUpdateTime(LocalDateTime.now()); + subscribeEvent.setUpdateBy("xinyilu"); + int updateSubscribeEvent = officialAccountSubscribeEventMapper.updateSubscribeEventInfo(subscribeEvent); + if (updateSubscribeEvent < 0) { + log.error("院后微信公众号关注和取消事件,修改信息失败,信息为:[{}]", subscribeEvent); + throw new ServiceException("修改院后微信公众号关注和取消事件信息失败!"); + } + } + } } diff --git a/postdischarge-mobile/src/main/java/com/xinelu/mobile/utils/WeChatOfficialAccountUtils.java b/postdischarge-mobile/src/main/java/com/xinelu/mobile/utils/WeChatOfficialAccountUtils.java index 6c3a3f93..37d6bdb3 100644 --- a/postdischarge-mobile/src/main/java/com/xinelu/mobile/utils/WeChatOfficialAccountUtils.java +++ b/postdischarge-mobile/src/main/java/com/xinelu/mobile/utils/WeChatOfficialAccountUtils.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSON; import com.xinelu.common.config.WeChatOfficialAccountConfig; import com.xinelu.common.constant.Constants; import com.xinelu.common.entity.AccessToken; +import com.xinelu.common.entity.MessageValueEntity; import com.xinelu.common.exception.ServiceException; import com.xinelu.common.utils.http.HttpUtils; import lombok.extern.slf4j.Slf4j; @@ -81,7 +82,7 @@ public class WeChatOfficialAccountUtils { String accessToken = this.getWeChatOfficialAccountAccessToken(); //定义模板内容,公众模板内容 Map paramsMap = new LinkedHashMap<>(); - paramsMap.put("touser", "oHBuH5T90TghJdYKfBlxE4fhayBc"); + paramsMap.put("touser", "oSwvX5qknp3DrAXfBgFjoMvG6WCI"); paramsMap.put("template_id", "WUCYtSbH-QFRV_fMcfmn86QLsz1zo881QW7fQNTWOjc"); //微信小程序跳转内容 Map miniprogramMap = new LinkedHashMap<>(); @@ -89,11 +90,11 @@ public class WeChatOfficialAccountUtils { miniprogramMap.put("pagepath", "pages/startup/startup"); //微信小程序模板data内容 Map dataMap = new LinkedHashMap<>(); - dataMap.put("phrase7", "泉医陪护服务"); - dataMap.put("character_string3", "000026315412331612100"); - dataMap.put("time6", "2024-03-25 16:21:32"); - dataMap.put("time10", "2024-03-27 10:00:00"); - dataMap.put("thing11", "济南市槐荫区首诺城市之光东座22楼E10"); + dataMap.put("phrase7", new MessageValueEntity("泉医陪护")); + dataMap.put("character_string3", new MessageValueEntity("000026315412331612100")); + dataMap.put("time6", new MessageValueEntity("2024-03-25 16:21:32")); + dataMap.put("time10", new MessageValueEntity("2024-03-27 10:00:00")); + dataMap.put("thing11", new MessageValueEntity("济南市槐荫区首诺城市之光东座22楼E10")); paramsMap.put("miniprogram", miniprogramMap); paramsMap.put("data", dataMap); //拼接请求地址并发送