| | |
| | | } |
| | | return accessToken; |
| | | } |
| | | |
| | | /** |
| | | * 发布消息时重新设置access_token 防止过期 |
| | | * @param appId |
| | | * @param appSecret |
| | | * @throws Exception |
| | | */ |
| | | public void setAppAccessTokenToCache(String appId,String appSecret) throws Exception{ |
| | | String accessToken = "0"; |
| | | try { |
| | | log.info("获取微信token参数:appid=" + appId + ",appSecret=" + appSecret); |
| | | String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + appId + "&secret=" + appSecret; |
| | | String result = HttpClientUtil.httpGet(accessTokenUrl, null, null); |
| | | Map<String, Object> resultMap = JSON.parseObject(result, Map.class); |
| | | if (resultMap.containsKey("access_token")) { |
| | | accessToken = resultMap.get("access_token").toString(); |
| | | wxXCXTempSend.stringRedisTemplate.opsForValue().set("access_token:access_token:" + appId, accessToken, EXPIRE_TIME,TimeUnit.HOURS); |
| | | } |
| | | } catch (IOException ioe) { |
| | | log.error("小程序http请求异常"); |
| | | ioe.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public String getAccessTokenNoValid(String appId) throws Exception { |
| | | String accessToken = ""; |
| | | accessToken=wxXCXTempSend.stringRedisTemplate.boundValueOps("access_token:access_token:"+appId).get(); |
| | | return accessToken; |
| | | } |
| | | public String getWsAccessToken() throws Exception { |
| | | String accessToken = "0"; |
| | | try { |
| | |
| | | } |
| | | @RabbitListener(queues = ACID_MESSAGE_QUEUE) |
| | | public void sendMessage(ComActDynVO comActDynVO){ |
| | | try{ |
| | | List<String> openIds=sysUserDao.selectOpenId(); |
| | | String appId = "wx118de8a734d269f0"; |
| | | String appSecret = "0264342daefde5cd70a6adada09ee5b1"; |
| | | WxXCXTempSend wxXCXTempSend=new WxXCXTempSend(); |
| | | wxXCXTempSend.setAppAccessTokenToCache(appId,appSecret); |
| | | for(String openId:openIds){ |
| | | try { |
| | | WxUtil.sendLongTimeTemplate(openId,wxXCXTempSend.getAccessToken("wx118de8a734d269f0"),"疫情快讯",comActDynVO.getTitle().length()>10?comActDynVO.getTitle().substring(0,10)+"..":comActDynVO.getTitle(),"/pages/community_child/community/detail?id="+comActDynVO.getId()+"&title=疫情快讯详情"); |
| | | WxUtil.sendLongTimeTemplate(openId,wxXCXTempSend.getAccessTokenNoValid(appId),"疫情快讯",comActDynVO.getTitle().length()>10?comActDynVO.getTitle().substring(0,10)+"..":comActDynVO.getTitle(),"/pages/community_child/community/detail?id="+comActDynVO.getId()+"&title=疫情快讯详情"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | } |