From da612570a0caa58c3119f21650d6c2ea41226192 Mon Sep 17 00:00:00 2001 From: shiyang Date: Thu, 24 Mar 2022 14:23:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=8F=B7=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E9=9C=80=E8=A6=81=E7=9A=84=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lyms/talkonlineweb/task/PushArticleTask.java | 40 ++++++++++++++++++---- .../com/lyms/talkonlineweb/util/WeiXinUtil.java | 39 +++++++++++++++++---- 2 files changed, 66 insertions(+), 13 deletions(-) diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java index 335cc18..6f612ce 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java @@ -1,6 +1,7 @@ package com.lyms.talkonlineweb.task; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.lyms.talkonlineweb.domain.*; import com.lyms.talkonlineweb.result.BaseResponse; import com.lyms.talkonlineweb.service.*; @@ -33,9 +34,10 @@ public class PushArticleTask { private LymsPushedartService lymsPushedartService;//推送的历史记录 @Autowired private PushArticleService pushArticleService;//推送文章新逻辑shiy改 - @Autowired - LymsPushMessagesService lymsPushMessagesService; + private LymsPatientService lymsPatientService; + @Autowired + private LymsPushMessagesService lymsPushMessagesService; @Autowired private LymsDictService lymsDictService; @@ -128,8 +130,10 @@ public class PushArticleTask { map.put("keyword1",new DataEntity(lymsPushMessage.getPname(),"#173177")); map.put("keyword2",new DataEntity(lymsPushMessage.getHname(),"#173177")); map.put("keyword3",new DataEntity(lymsPushMessage.getDname(),"#173177")); - map.put("remark",new DataEntity("预祝您早日康复","#173177")); - Integer code= WeiXinUtil.SendWeChatMsg(lymsPushMessage.getGzopenid(), Constant.GZ_TEMPLATE_ID,map); + map.put("remark",new DataEntity("预祝您早日康复!","#173177")); + //公众号跳转小程序需要的登录信息 + Map mapInfo =pLoginInfo(lymsPushMessage); + Integer code= WeiXinUtil.SendWeChatMsg(lymsPushMessage.getGzopenid(), Constant.GZ_TEMPLATE_ID,map,mapInfo); if(null==code||code!=0){ //更新到LymsPushMessages记录 lymsPushMessage.setState(2);//推送状态:0待推送 1成功 2失败。(在备注写失败原因) @@ -161,8 +165,10 @@ public class PushArticleTask { map.put("keyword1",new DataEntity(lymsPushMessage.getPname(),"#173177")); map.put("keyword2",new DataEntity(lymsPushMessage.getHname(),"#173177")); map.put("keyword3",new DataEntity(lymsPushMessage.getDname(),"#173177")); - map.put("remark",new DataEntity("预祝您早日康复","#173177")); - Integer code= WeiXinUtil.SendWeChatMsg(lymsPushMessage.getGzopenid(),Constant.GZ_TEMPLATE_ID,map); + map.put("remark",new DataEntity("预祝您早日康复!","#173177")); + //公众号跳转小程序需要的登录信息 + Map mapInfo =pLoginInfo(lymsPushMessage); + Integer code= WeiXinUtil.SendWeChatMsg(lymsPushMessage.getGzopenid(),Constant.GZ_TEMPLATE_ID,map,mapInfo); if(null==code||code!=0){ //更新到LymsPushMessages记录 lymsPushMessage.setState(2);//推送状态:0待推送 1成功 2失败。(在备注写失败原因) @@ -195,9 +201,31 @@ public class PushArticleTask { } } } +public Map pLoginInfo(LymsPushMessages lymsPushMessage){ + //获取登录信息 + Map map=new HashMap<>(); + String plogin=null; + LymsPatient lymsPatient = lymsPatientService.getById(lymsPushMessage.getPid()); + if(StringUtil.isNotEmpty(lymsPatient.getEnrolmentPhone())){ + if(StringUtil.isNotEmpty(lymsPatient.getEnrolmentPhone())){ + plogin=lymsPatient.getEnrolmentPhone(); + + } + }else { + List pLst=patientInfoService.list(new QueryWrapper().eq("id", lymsPatient.getId()) + .eq("iid", lymsPushMessage.getIid())); + if(CollectionUtils.isNotEmpty(pLst)){ + plogin=pLst.get(0).getMobile(); + } + } + map.put("plogin", plogin); + map.put("passwd", lymsPatient.getPpasswd()); + return map; +} } + @Data class DataEntity { //内容 diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java index e6a026d..62fa2ac 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java @@ -2,14 +2,29 @@ package com.lyms.talkonlineweb.util; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.extension.service.IService; +import com.lyms.talkonlineweb.domain.LymsPatient; +import com.lyms.talkonlineweb.domain.LymsPushMessages; +import com.lyms.talkonlineweb.domain.PatientInfo; import com.lyms.talkonlineweb.result.BaseResponse; +import com.lyms.talkonlineweb.service.LymsPatientService; +import com.lyms.talkonlineweb.service.PatientInfoService; +import com.lyms.talkonlineweb.service.impl.LymsPatientServiceImpl; +import com.lyms.talkonlineweb.service.impl.PatientInfoServiceImpl; import com.lyms.talkonlineweb.task.AccessTokenServlet; import lombok.extern.log4j.Log4j2; -import org.springframework.util.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; +import java.net.URL; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.TreeMap; /** * @ProjectName: talkonline @@ -20,9 +35,12 @@ import java.util.Map; * @Date: 2021-09-13 18:10 * @Version: */ +@Component @Log4j2 public class WeiXinUtil { - //微信返回的key定义 + /** + * 微信返回的key定义 + */ private static final String OPEN_ID_KEY = "openid"; /** * 获取微信用户的openid @@ -64,7 +82,7 @@ public class WeiXinUtil { * @param template_id 公众号消息模板id * @param dataMap 推送内容消息主题显示相关map */ - public static Integer SendWeChatMsg(String openid, String template_id, Map dataMap) { + public static Integer SendWeChatMsg(String openid, String template_id, Map dataMap, Map mapInfo) { // 接口地址 String sendMsgApi = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+AccessTokenServlet.accessToken; //整体参数map @@ -72,10 +90,17 @@ public class WeiXinUtil { paramMap.put("touser", openid); paramMap.put("template_id", template_id); //跳转到小程序用到miniprogram集合参数 -// Map miniprogramMap = new HashMap(); -// miniprogramMap.put("appid",Constant.PAT_APP_ID); -// miniprogramMap.put("pagepath","/pages/login/login"); -// paramMap.put("miniprogram", miniprogramMap); + paramMap.put("url", "http://weixin.qq.com"); + TreeMap miniprogram = new TreeMap(); + miniprogram.put("appid",Constant.PAT_APP_ID); + //登录数据 + if(CollectionUtils.isNotEmpty(mapInfo) && null!=mapInfo.get("plogin") && null!=mapInfo.get("passwd")){ + miniprogram.put("pagepath","pages/news/news?plogin="+mapInfo.get("plogin")+"&passwd="+mapInfo.get("passwd"));// 注意,这里是支持传参的!!! + }else { + //意外情况自行登录 + miniprogram.put("pagepath","pages/enroll/enroll");// 注意,这里是支持传参的!!! + } + paramMap.put("miniprogram", miniprogram); paramMap.put("data", dataMap); String result= repeatDoGetPost(sendMsgApi,"POST",paramMap); if(StringUtil.isEmpty(result)){ -- 1.8.3.1