| | |
| | | try { |
| | | String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=" + token; |
| | | String result = getActicle(url); |
| | | // log.info("通过token获取文章列表成功,返回结果:" + result); |
| | | log.info("通过token获取文章列表成功,返回结果:" + result); |
| | | |
| | | JSONObject resultJson = JSON.parseObject(result); |
| | | if(resultJson != null){ |
| | | List<JSONObject> itemList = JSON.parseArray(resultJson.getString("item"),JSONObject.class); |
| | | if(!itemList.isEmpty()){ |
| | | for (JSONObject object : itemList) { |
| | | String mediaId = object.getString("media_id"); |
| | | String newsId = object.getString("media_id"); |
| | | JSONObject contentJson = JSON.parseObject(object.getString("content")); |
| | | List<JSONObject> newsItemList = JSON.parseArray(contentJson.getString("news_item"),JSONObject.class); |
| | | String newsUrl = newsItemList.get(0).getString("url"); |
| | | log.info("对象信息设置前:" + newsItemList.get(0)); |
| | | newsItemList.get(0).put("news_id",mediaId); |
| | | log.info("对象信息设置后:" + newsItemList.get(0)); |
| | | log.info("对象集合数据:" + newsItemList); |
| | | |
| | | newsItemList.get(0).put("news_id",newsId); |
| | | contentJson.put("news_item",newsItemList); |
| | | object.put("content",contentJson); |
| | | |
| | | ValueOperations<String, String> valueOperations = stringRedisTemplate.opsForValue(); |
| | | valueOperations.set(UserConstants.NEWS_ID + mediaId, newsUrl + "", 2, TimeUnit.DAYS); |
| | | valueOperations.set(UserConstants.NEWS_ID + newsId, newsUrl + "", 2, TimeUnit.DAYS); |
| | | } |
| | | } |
| | | resultJson.put("item",itemList); |
| | |
| | | |
| | | @ApiOperation(value = "获取公众号文章链接") |
| | | @GetMapping(value = "/get/noToken") |
| | | public R getDiscuss(@RequestParam("mediaId") Long mediaId){ |
| | | public R getDiscuss(@RequestParam("mediaId") String mediaId){ |
| | | |
| | | String key = UserConstants.NEWS_ID + mediaId; |
| | | Boolean hasKey = stringRedisTemplate.hasKey(key); |