Commit d752c1fdbadd4baed6685e9ada76dc3bef3dc031
1 parent
eef7ebb420
Exists in
master
and in
1 other branch
文章推送优化3
Showing 5 changed files with 22 additions and 11 deletions
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/ArticleController.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTaskData.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java
talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/ArticleController.java
View file @
d752c1f
... | ... | @@ -378,9 +378,9 @@ |
378 | 378 | QueryWrapper<LymsPushMessages> queryWrapper = new QueryWrapper<>(); |
379 | 379 | queryWrapper.setEntity(lymsPushMessages); |
380 | 380 | if(null!=lymsPushMessages.getStartDate()&&null!=lymsPushMessages.getEndDate()){ |
381 | - queryWrapper.ge("plan_time", lymsPushMessages.getStartDate()).le("plan_time",lymsPushMessages.getEndDate()); | |
381 | + queryWrapper.ge("push_time", lymsPushMessages.getStartDate()).le("push_time",lymsPushMessages.getEndDate()); | |
382 | 382 | } |
383 | - queryWrapper.orderByDesc("plan_time"); | |
383 | + queryWrapper.orderByDesc("push_time"); | |
384 | 384 | Page<LymsPushMessages> lymsPushMessagesPage=lymsPushMessagesService.page(page,queryWrapper); |
385 | 385 | baseResponse.setObject(lymsPushMessagesPage); |
386 | 386 | baseResponse.setErrormsg("成功"); |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java
View file @
d752c1f
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | import com.lyms.talkonlineweb.domain.*; |
5 | 5 | import com.lyms.talkonlineweb.result.BaseResponse; |
6 | 6 | import com.lyms.talkonlineweb.service.*; |
7 | +import com.lyms.talkonlineweb.util.Constant; | |
7 | 8 | import com.lyms.talkonlineweb.util.DateUtil; |
8 | 9 | import com.lyms.talkonlineweb.util.StringUtil; |
9 | 10 | import com.lyms.talkonlineweb.util.WeiXinUtil; |
... | ... | @@ -39,10 +40,10 @@ |
39 | 40 | @Autowired |
40 | 41 | private LymsDictService lymsDictService; |
41 | 42 | |
42 | -// final String gzopenid ="oQEmP6rFmf0lOb--mUf4_MAZPXEQ";//测试:公众号关注的微信openId | |
43 | - final String template_id ="ZDxcRDJ3okC9Lbzpfhr_v4e8W1VWrho-f5uHW_VZHTg";//公众号模板:诊后注意事项id | |
44 | - | |
45 | - @Scheduled(cron = "0 0 9 * * ?")//每天上午9点执行文章推送 | |
43 | + /** | |
44 | + * 每天上午9点执行文章推送 | |
45 | + */ | |
46 | + @Scheduled(cron = "0 0 9 * * ?") | |
46 | 47 | public void pushArtcle(){ |
47 | 48 | String token= AccessTokenServlet.accessToken; |
48 | 49 | Map<String,Object> param=new HashMap<>(); |
... | ... | @@ -108,7 +109,7 @@ |
108 | 109 | map.put("keyword2",new DataEntity(lymsPushMessage.getHname(),"#173177")); |
109 | 110 | map.put("keyword3",new DataEntity(lymsPushMessage.getDname(),"#173177")); |
110 | 111 | map.put("remark",new DataEntity("预祝您早日康复","#173177")); |
111 | - Integer code= WeiXinUtil.SendWeChatMsg(token,lymsPushMessage.getGzopenid(),template_id,map); | |
112 | + Integer code= WeiXinUtil.SendWeChatMsg(token,lymsPushMessage.getGzopenid(), Constant.GZ_TEMPLATE_ID,map); | |
112 | 113 | if(null==code||code!=0){ |
113 | 114 | //更新到LymsPushMessages记录 |
114 | 115 | lymsPushMessage.setState(2);//推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) |
... | ... | @@ -131,7 +132,7 @@ |
131 | 132 | map.put("keyword2",new DataEntity(lymsPushMessage.getHname(),"#173177")); |
132 | 133 | map.put("keyword3",new DataEntity(lymsPushMessage.getDname(),"#173177")); |
133 | 134 | map.put("remark",new DataEntity("预祝您早日康复","#173177")); |
134 | - Integer code= WeiXinUtil.SendWeChatMsg(token,lymsPushMessage.getGzopenid(),template_id,map); | |
135 | + Integer code= WeiXinUtil.SendWeChatMsg(token,lymsPushMessage.getGzopenid(),Constant.GZ_TEMPLATE_ID,map); | |
135 | 136 | if(null==code||code!=0){ |
136 | 137 | //更新到LymsPushMessages记录 |
137 | 138 | lymsPushMessage.setState(2);//推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTaskData.java
View file @
d752c1f
... | ... | @@ -44,8 +44,10 @@ |
44 | 44 | @Autowired |
45 | 45 | private LymsDictService lymsDictService; |
46 | 46 | |
47 | - | |
48 | - @Scheduled(cron = "0 0 0 * * ?")//每天0点执行-要推送的文章存到数据库 | |
47 | + /** | |
48 | + * 每天0点执行-要推送的文章存到数据库 | |
49 | + */ | |
50 | + @Scheduled(cron = "0 0 0 * * ?") | |
49 | 51 | public void pushArtcleData(){ |
50 | 52 | Map<String,Object> param=new HashMap<>(); |
51 | 53 | param.put("vtype",999); |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java
View file @
d752c1f
... | ... | @@ -46,6 +46,10 @@ |
46 | 46 | */ |
47 | 47 | public static final String WX_SECRET = "005ab68859ca2504b7217dac4c903cd2"; |
48 | 48 | /** |
49 | + * 公众号发送消息模板 | |
50 | + */ | |
51 | + public static final String GZ_TEMPLATE_ID ="ZDxcRDJ3okC9Lbzpfhr_v4e8W1VWrho-f5uHW_VZHTg"; | |
52 | + /** | |
49 | 53 | * 公众号的appid |
50 | 54 | */ |
51 | 55 | public static final String GZ_APP_ID ="wxd3c36244d006cb90"; |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java
View file @
d752c1f
... | ... | @@ -72,6 +72,11 @@ |
72 | 72 | Map<String, Object> paramMap = new HashMap<String, Object>(); |
73 | 73 | paramMap.put("touser", openid); |
74 | 74 | paramMap.put("template_id", template_id); |
75 | + //跳转到小程序用到miniprogram集合参数 | |
76 | + Map<String, Object> miniprogramMap = new HashMap<String, Object>(); | |
77 | + miniprogramMap.put("appid",Constant.PAT_APP_ID); | |
78 | + miniprogramMap.put("pagepath","/pages/login/login"); | |
79 | + paramMap.put("miniprogram", miniprogramMap); | |
75 | 80 | paramMap.put("data", dataMap); |
76 | 81 | String result= repeatDoGetPost(sendMsgApi,"POST",paramMap); |
77 | 82 | if(StringUtil.isEmpty(result)){ |
... | ... | @@ -98,7 +103,6 @@ |
98 | 103 | // 接口地址 |
99 | 104 | String reqUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + Constant.GZ_APP_ID + "&secret=" + Constant.GZ_SECRET + "&code=" + code + "&grant_type="+Constant.GZ_AUTH; |
100 | 105 | log.info(reqUrl); |
101 | -// String result = HttpUtil.getData(reqUrl); | |
102 | 106 | String result = repeatDoGetPost(reqUrl,"GET",null); |
103 | 107 | log.info("result :" + result); |
104 | 108 | if (StringUtils.isEmpty(result)) { |