Commit da612570a0caa58c3119f21650d6c2ea41226192
1 parent
d19b200452
Exists in
master
and in
1 other branch
公众号跳转小程序需要的登录信息
Showing 2 changed files with 66 additions and 13 deletions
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java
View file @
da61257
1 | 1 | package com.lyms.talkonlineweb.task; |
2 | 2 | |
3 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
4 | +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | |
4 | 5 | import com.lyms.talkonlineweb.domain.*; |
5 | 6 | import com.lyms.talkonlineweb.result.BaseResponse; |
6 | 7 | import com.lyms.talkonlineweb.service.*; |
7 | 8 | |
... | ... | @@ -33,9 +34,10 @@ |
33 | 34 | private LymsPushedartService lymsPushedartService;//推送的历史记录 |
34 | 35 | @Autowired |
35 | 36 | private PushArticleService pushArticleService;//推送文章新逻辑shiy改 |
36 | - | |
37 | 37 | @Autowired |
38 | - LymsPushMessagesService lymsPushMessagesService; | |
38 | + private LymsPatientService lymsPatientService; | |
39 | + @Autowired | |
40 | + private LymsPushMessagesService lymsPushMessagesService; | |
39 | 41 | |
40 | 42 | @Autowired |
41 | 43 | private LymsDictService lymsDictService; |
... | ... | @@ -128,8 +130,10 @@ |
128 | 130 | map.put("keyword1",new DataEntity(lymsPushMessage.getPname(),"#173177")); |
129 | 131 | map.put("keyword2",new DataEntity(lymsPushMessage.getHname(),"#173177")); |
130 | 132 | map.put("keyword3",new DataEntity(lymsPushMessage.getDname(),"#173177")); |
131 | - map.put("remark",new DataEntity("预祝您早日康复","#173177")); | |
132 | - Integer code= WeiXinUtil.SendWeChatMsg(lymsPushMessage.getGzopenid(), Constant.GZ_TEMPLATE_ID,map); | |
133 | + map.put("remark",new DataEntity("预祝您早日康复!","#173177")); | |
134 | + //公众号跳转小程序需要的登录信息 | |
135 | + Map<String,Object> mapInfo =pLoginInfo(lymsPushMessage); | |
136 | + Integer code= WeiXinUtil.SendWeChatMsg(lymsPushMessage.getGzopenid(), Constant.GZ_TEMPLATE_ID,map,mapInfo); | |
133 | 137 | if(null==code||code!=0){ |
134 | 138 | //更新到LymsPushMessages记录 |
135 | 139 | lymsPushMessage.setState(2);//推送状态:0待推送 1成功 2失败。(在备注写失败原因) |
... | ... | @@ -161,8 +165,10 @@ |
161 | 165 | map.put("keyword1",new DataEntity(lymsPushMessage.getPname(),"#173177")); |
162 | 166 | map.put("keyword2",new DataEntity(lymsPushMessage.getHname(),"#173177")); |
163 | 167 | map.put("keyword3",new DataEntity(lymsPushMessage.getDname(),"#173177")); |
164 | - map.put("remark",new DataEntity("预祝您早日康复","#173177")); | |
165 | - Integer code= WeiXinUtil.SendWeChatMsg(lymsPushMessage.getGzopenid(),Constant.GZ_TEMPLATE_ID,map); | |
168 | + map.put("remark",new DataEntity("预祝您早日康复!","#173177")); | |
169 | + //公众号跳转小程序需要的登录信息 | |
170 | + Map<String,Object> mapInfo =pLoginInfo(lymsPushMessage); | |
171 | + Integer code= WeiXinUtil.SendWeChatMsg(lymsPushMessage.getGzopenid(),Constant.GZ_TEMPLATE_ID,map,mapInfo); | |
166 | 172 | if(null==code||code!=0){ |
167 | 173 | //更新到LymsPushMessages记录 |
168 | 174 | lymsPushMessage.setState(2);//推送状态:0待推送 1成功 2失败。(在备注写失败原因) |
169 | 175 | |
170 | 176 | |
171 | 177 | |
... | ... | @@ -195,9 +201,31 @@ |
195 | 201 | } |
196 | 202 | } |
197 | 203 | } |
204 | +public Map<String,Object> pLoginInfo(LymsPushMessages lymsPushMessage){ | |
205 | + //获取登录信息 | |
206 | + Map<String,Object> map=new HashMap<>(); | |
207 | + String plogin=null; | |
208 | + LymsPatient lymsPatient = lymsPatientService.getById(lymsPushMessage.getPid()); | |
209 | + if(StringUtil.isNotEmpty(lymsPatient.getEnrolmentPhone())){ | |
210 | + if(StringUtil.isNotEmpty(lymsPatient.getEnrolmentPhone())){ | |
211 | + plogin=lymsPatient.getEnrolmentPhone(); | |
198 | 212 | |
213 | + } | |
199 | 214 | |
215 | + }else { | |
216 | + List<PatientInfo> pLst=patientInfoService.list(new QueryWrapper<PatientInfo>().eq("id", lymsPatient.getId()) | |
217 | + .eq("iid", lymsPushMessage.getIid())); | |
218 | + if(CollectionUtils.isNotEmpty(pLst)){ | |
219 | + plogin=pLst.get(0).getMobile(); | |
220 | + } | |
221 | + } | |
222 | + map.put("plogin", plogin); | |
223 | + map.put("passwd", lymsPatient.getPpasswd()); | |
224 | + return map; | |
200 | 225 | } |
226 | + | |
227 | +} | |
228 | + | |
201 | 229 | @Data |
202 | 230 | class DataEntity { |
203 | 231 | //内容 |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java
View file @
da61257
... | ... | @@ -2,14 +2,29 @@ |
2 | 2 | |
3 | 3 | import com.alibaba.fastjson.JSON; |
4 | 4 | import com.alibaba.fastjson.JSONObject; |
5 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
6 | +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | |
7 | +import com.baomidou.mybatisplus.extension.service.IService; | |
8 | +import com.lyms.talkonlineweb.domain.LymsPatient; | |
9 | +import com.lyms.talkonlineweb.domain.LymsPushMessages; | |
10 | +import com.lyms.talkonlineweb.domain.PatientInfo; | |
5 | 11 | import com.lyms.talkonlineweb.result.BaseResponse; |
12 | +import com.lyms.talkonlineweb.service.LymsPatientService; | |
13 | +import com.lyms.talkonlineweb.service.PatientInfoService; | |
14 | +import com.lyms.talkonlineweb.service.impl.LymsPatientServiceImpl; | |
15 | +import com.lyms.talkonlineweb.service.impl.PatientInfoServiceImpl; | |
6 | 16 | import com.lyms.talkonlineweb.task.AccessTokenServlet; |
7 | 17 | import lombok.extern.log4j.Log4j2; |
8 | -import org.springframework.util.CollectionUtils; | |
18 | +import org.springframework.beans.factory.annotation.Autowired; | |
19 | +import org.springframework.stereotype.Component; | |
20 | +import org.springframework.stereotype.Service; | |
9 | 21 | import org.springframework.util.StringUtils; |
10 | 22 | |
23 | +import java.net.URL; | |
11 | 24 | import java.util.HashMap; |
25 | +import java.util.List; | |
12 | 26 | import java.util.Map; |
27 | +import java.util.TreeMap; | |
13 | 28 | |
14 | 29 | /** |
15 | 30 | * @ProjectName: talkonline |
16 | 31 | |
... | ... | @@ -20,9 +35,12 @@ |
20 | 35 | * @Date: 2021-09-13 18:10 |
21 | 36 | * @Version: |
22 | 37 | */ |
38 | +@Component | |
23 | 39 | @Log4j2 |
24 | 40 | public class WeiXinUtil { |
25 | - //微信返回的key定义 | |
41 | + /** | |
42 | + * 微信返回的key定义 | |
43 | + */ | |
26 | 44 | private static final String OPEN_ID_KEY = "openid"; |
27 | 45 | /** |
28 | 46 | * 获取微信用户的openid |
... | ... | @@ -64,7 +82,7 @@ |
64 | 82 | * @param template_id 公众号消息模板id |
65 | 83 | * @param dataMap 推送内容消息主题显示相关map |
66 | 84 | */ |
67 | - public static Integer SendWeChatMsg(String openid, String template_id, Map<String,Object> dataMap) { | |
85 | + public static Integer SendWeChatMsg(String openid, String template_id, Map<String,Object> dataMap, Map<String,Object> mapInfo) { | |
68 | 86 | // 接口地址 |
69 | 87 | String sendMsgApi = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+AccessTokenServlet.accessToken; |
70 | 88 | //整体参数map |
... | ... | @@ -72,10 +90,17 @@ |
72 | 90 | paramMap.put("touser", openid); |
73 | 91 | paramMap.put("template_id", template_id); |
74 | 92 | //跳转到小程序用到miniprogram集合参数 |
75 | -// Map<String, Object> miniprogramMap = new HashMap<String, Object>(); | |
76 | -// miniprogramMap.put("appid",Constant.PAT_APP_ID); | |
77 | -// miniprogramMap.put("pagepath","/pages/login/login"); | |
78 | -// paramMap.put("miniprogram", miniprogramMap); | |
93 | + paramMap.put("url", "http://weixin.qq.com"); | |
94 | + TreeMap<String, String> miniprogram = new TreeMap<String, String>(); | |
95 | + miniprogram.put("appid",Constant.PAT_APP_ID); | |
96 | + //登录数据 | |
97 | + if(CollectionUtils.isNotEmpty(mapInfo) && null!=mapInfo.get("plogin") && null!=mapInfo.get("passwd")){ | |
98 | + miniprogram.put("pagepath","pages/news/news?plogin="+mapInfo.get("plogin")+"&passwd="+mapInfo.get("passwd"));// 注意,这里是支持传参的!!! | |
99 | + }else { | |
100 | + //意外情况自行登录 | |
101 | + miniprogram.put("pagepath","pages/enroll/enroll");// 注意,这里是支持传参的!!! | |
102 | + } | |
103 | + paramMap.put("miniprogram", miniprogram); | |
79 | 104 | paramMap.put("data", dataMap); |
80 | 105 | String result= repeatDoGetPost(sendMsgApi,"POST",paramMap); |
81 | 106 | if(StringUtil.isEmpty(result)){ |