From 4d2ed89d41a11d661de73192ec18029419be400c Mon Sep 17 00:00:00 2001 From: zhangheng <3226558941@qq.com> Date: Thu, 30 May 2024 10:47:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xinelu/common/constant/Constants.java | 5 ++ .../impl/SpecialDiseaseNodeServiceImpl.java | 17 +++---- .../SpecialDiseaseNodeVO.java | 3 +- .../utils/WeChatOfficialAccountUtils.java | 51 +++++++++++-------- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/postdischarge-common/src/main/java/com/xinelu/common/constant/Constants.java b/postdischarge-common/src/main/java/com/xinelu/common/constant/Constants.java index a4b39c7e..5886c10a 100644 --- a/postdischarge-common/src/main/java/com/xinelu/common/constant/Constants.java +++ b/postdischarge-common/src/main/java/com/xinelu/common/constant/Constants.java @@ -348,4 +348,9 @@ public class Constants { * 资讯编码前缀 */ public static final String INFO_CODE = "IC"; + + /** + * 泉医微信小程序ACCESS_TOKEN前缀(测试使用) + */ + public static final String NURSE_STATION_APPLET_ACCESS_TOKEN = "NURSE_STATION_APPLET_ACCESS_TOKEN"; } diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/specialdiseasenode/impl/SpecialDiseaseNodeServiceImpl.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/specialdiseasenode/impl/SpecialDiseaseNodeServiceImpl.java index 476baa93..a40f93d0 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/service/specialdiseasenode/impl/SpecialDiseaseNodeServiceImpl.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/specialdiseasenode/impl/SpecialDiseaseNodeServiceImpl.java @@ -19,16 +19,6 @@ import com.xinelu.manage.mapper.specialdiseaseroute.SpecialDiseaseRouteMapper; import com.xinelu.manage.service.specialdiseasenode.ISpecialDiseaseNodeService; import com.xinelu.manage.vo.specialdiseasenode.SpecialDiseaseNodeVO; import com.xinelu.manage.vo.specialdiseaseroute.SpecialDiseaseRouteVO; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.TreeSet; -import java.util.stream.Collectors; -import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -39,6 +29,12 @@ import org.jsoup.select.Elements; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.stream.Collectors; + /** * 专病路径-管理节点信息Service业务层处理 * @@ -147,6 +143,7 @@ public class SpecialDiseaseNodeServiceImpl implements ISpecialDiseaseNodeService if (StringUtils.isNotBlank(diseaseNode.getRouteNodeName()) && Objects.nonNull(diseaseNode.getRouteNodeDay()) && StringUtils.isNotBlank(diseaseNode.getTaskType()) && StringUtils.isNotBlank(diseaseNode.getTaskSubdivision()) && StringUtils.isNotBlank(diseaseNode.getTaskStatus())) { diseaseNode.setRouteId(specialDiseaseRoute.getId()); diseaseNode.setRouteName(specialDiseaseNode.getRouteName()); + diseaseNode.setTemplateType(diseaseNode.getTaskSubdivisiontemplateType()); diseaseNode.setUpdateTime(LocalDateTime.now()); diseaseNode.setUpdateBy(SecurityUtils.getUsername()); specialDiseaseNodeVOS.add(diseaseNode); diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/vo/specialdiseasenode/SpecialDiseaseNodeVO.java b/postdischarge-manage/src/main/java/com/xinelu/manage/vo/specialdiseasenode/SpecialDiseaseNodeVO.java index 0da12319..ed28b426 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/vo/specialdiseasenode/SpecialDiseaseNodeVO.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/vo/specialdiseasenode/SpecialDiseaseNodeVO.java @@ -1,7 +1,6 @@ package com.xinelu.manage.vo.specialdiseasenode; import com.xinelu.manage.domain.specialdiseasenode.SpecialDiseaseNode; -import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -22,4 +21,6 @@ public class SpecialDiseaseNodeVO extends SpecialDiseaseNode { private String taskSubdivisionName; private String taskStatusName; + + private String taskSubdivisiontemplateType; } 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 09edb168..934b3779 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 @@ -6,13 +6,8 @@ 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.enums.PatientTypeEnum; -import com.xinelu.common.enums.RouteNodeNameEnum; -import com.xinelu.common.enums.SubscribeStatusEnum; import com.xinelu.common.exception.ServiceException; import com.xinelu.common.utils.http.HttpUtils; -import com.xinelu.manage.service.specialdiseaseroute.ISpecialDiseaseRouteService; -import com.xinelu.mobile.mapper.homepage.HomePageMapper; import com.xinelu.mobile.vo.wechatofficialaccountcallback.PatientVO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -21,9 +16,10 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.time.LocalDate; -import java.util.*; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; /** * @Description 院后公众号公众方法工具类 @@ -39,6 +35,8 @@ public class WeChatOfficialAccountUtils { private RedisTemplate redisTemplate; @Resource private WeChatOfficialAccountConfig weChatOfficialAccountConfig; + @Resource + private WeChatAppletChatConfig weChatAppletChatConfig; /** @@ -53,12 +51,18 @@ public class WeChatOfficialAccountUtils { */ public String getWeChatOfficialAccountAccessToken() { String accessToken; - String accessTokenRedisKey = Constants.WE_CHAT_OFFICIAL_ACCOUNT_ACCESS_TOKEN + "accessToken"; + //小程序 + String accessTokenRedisKey = Constants.NURSE_STATION_APPLET_ACCESS_TOKEN + "accessToken"; + //公众号 + //String accessTokenRedisKey = Constants.WE_CHAT_OFFICIAL_ACCOUNT_ACCESS_TOKEN + "accessToken"; //从Redis中取出accessToken Object object = redisTemplate.opsForValue().get(accessTokenRedisKey); if (Objects.isNull(object)) { //没有,获取accessToken - String accessTokenUrl = Constants.WE_CHAT_ACCESS_TOKEN_URL + "&appid=" + weChatOfficialAccountConfig.getOfficialAccountAppId() + "&secret=" + weChatOfficialAccountConfig.getOfficialAccountAppSecret(); + //小程序 + String accessTokenUrl = Constants.WE_CHAT_ACCESS_TOKEN_URL + "&appid=" + weChatAppletChatConfig.getAppletId() + "&secret=" + weChatAppletChatConfig.getSecret(); + //公众号 + //String accessTokenUrl = Constants.WE_CHAT_ACCESS_TOKEN_URL + "&appid=" + weChatOfficialAccountConfig.getOfficialAccountAppId() + "&secret=" + weChatOfficialAccountConfig.getOfficialAccountAppSecret(); //发送请求 String result = HttpUtils.sendGet(accessTokenUrl); if (StringUtils.isBlank(result)) { @@ -92,22 +96,26 @@ public class WeChatOfficialAccountUtils { //定义模板内容,公众模板内容 Map paramsMap = new LinkedHashMap<>(); paramsMap.put("touser", patientVO.getOpenId()); - paramsMap.put("template_id", "WUCYtSbH-QFRV_fMcfmn86QLsz1zo881QW7fQNTWOjc"); + paramsMap.put("template_id", "S_c9bR4znSWpXg-6ACIMn7AkaR11dzo113XM8w4CKz0"); + paramsMap.put("page", "/postDischarge/homePage/subscriptionMessage?id =" + patientVO.getSignPatientManageRouteNodeId()); //微信小程序跳转内容 - Map miniprogramMap = new LinkedHashMap<>(); - miniprogramMap.put("appid", "wxdc32268eca6b78f9"); - miniprogramMap.put("pagepath", "pages/startup/startup"); + // Map miniprogramMap = new LinkedHashMap<>(); + //miniprogramMap.put("appid", "wxdc32268eca6b78f9"); + // miniprogramMap.put("pagepath", "/postDischarge/homePage/subscriptionMessage?id =" + patientVO.getSignPatientManageRouteNodeId()); //微信小程序模板data内容 Map dataMap = new LinkedHashMap<>(); - 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); +// 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); + dataMap.put("thing1", new MessageValueEntity("每日签到")); + dataMap.put("thing2", new MessageValueEntity(LocalDate.now().getYear() + "年" + LocalDate.now().getMonthValue() + "月" + LocalDate.now().getDayOfMonth() + "日签到成功")); + dataMap.put("thing3", new MessageValueEntity(patientVO.getRouteNodeName() + "第" + patientVO.getRouteNodeDay())); paramsMap.put("data", dataMap); //拼接请求地址并发送 - String messageUrl = Constants.OFFICIAL_ACCOUNT_TEMPLATE_SEND_URL + accessToken; + String messageUrl = Constants.OFFICIAL_ACCOUNT_SUBSCRIBE_SEND_URL + accessToken; String param = JSON.toJSONString(paramsMap); String result = HttpUtils.sendPostJson(messageUrl, param); //返回参数映射 @@ -132,6 +140,9 @@ public class WeChatOfficialAccountUtils { case Constants.ARGUMENT_INVALID: log.error("参数无效!"); break; + case Constants.API_UNAUTHORIZED: + log.error("API 功能未授权!"); + break; case Constants.DENY_SUBSCRIPTION: log.error("用户拒接订阅!"); break;