springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/WxOfficialApi.java
@@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.utlis.HttpClientUtil; import com.panzhihua.common.utlis.StringUtils; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -13,10 +14,8 @@ import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.nio.charset.Charset; import java.util.*; @Slf4j @RestController @@ -77,26 +76,55 @@ String paramBody = JSON.toJSONString(map); // 这里用了Alibaba的fastjson OutputStream out = connection.getOutputStream(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out,"utf-8")); bw.write(paramBody); // 向流中写入参数字符串 bw.flush(); InputStream in = connection.getInputStream(); BufferedReader br = new BufferedReader( new InputStreamReader(in,"utf-8")); byte[] b = new byte[100]; int len = -1; StringBuffer sb = new StringBuffer(); while((len = br.read()) != -1) { sb.append(new String(b,0,len,"utf-8")); while((len = in.read(b)) != -1) { sb.append(new String(b,0,len)); } in.close(); return sb.toString(); } /** * 微信公众号请求头设置 */ public static Map<String, String> getWxHeaderMap() { Map<String, String> map = new HashMap<>(new LinkedHashMap()); map.put("Accept", "text/html, application/xhtml+xml, image/jxr, */*"); map.put("Accept-Encoding", "gzip, deflate"); map.put("Accept-Language", "zh-Hans-CN, zh-Hans; q=0.8, en-US; q=0.5, en; q=0.3"); map.put("Host", "mp.weixin.qq.com"); map.put("If-Modified-Since", "Sat, 04 Jan 2020 12:23:43 GMT"); map.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"); return map; } /** * 根据文章链接抓取文章内容 * * @param url 文章链接 * @return 文章内容 */ public static String getActicle(String url) { // post发送的参数 Map<String, Object> map = new HashMap<>(); map.put("type", "news"); // news表示图文类型的素材,具体看API文档 map.put("offset", 0); map.put("count", 5); // 将map转换成json字符串 String paramBody = JSON.toJSONString(map); return HttpClientUtil.get(url, getWxHeaderMap(),paramBody); } @ApiOperation(value = "拉取公众号列表") @GetMapping(value = "/list/noToken") @GetMapping(value = "/list/noToken",produces="application/json;charset=utf-8") public R pageDiscuss() throws Exception{ WxOfficialApi officialApi = new WxOfficialApi(); @@ -116,7 +144,8 @@ if(!tokenList.isEmpty()){ tokenList.forEach(token -> { try { String result = officialApi.getContentList(token); String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=" + token; String result = getActicle(url); log.info("通过token获取文章列表成功,返回结果:" + result); resultList.add(JSON.parseObject(result)); }catch (Exception e){ springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/community/screen/event/EventGridMemberVO.java
New file @@ -0,0 +1,23 @@ package com.panzhihua.common.model.vos.community.screen.event; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data @ApiModel("网格员列表返回参数") public class EventGridMemberVO { @ApiModelProperty("网格员id") @JsonSerialize(using = ToStringSerializer.class) private Long userId; @ApiModelProperty("网格员名称") private String nickName; @ApiModelProperty("网格员联系方式") private String phone; } springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/service/user/UserService.java
@@ -771,4 +771,7 @@ @PostMapping("user/getUserGrids") R getGridIsOk(@RequestParam("userId")Long userId); @GetMapping("getGridsMemberList") R getGridsMemberList(@RequestParam("communityId")Long communityId); } springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/HttpClientUtil.java
@@ -9,16 +9,15 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicHeader; import org.apache.http.util.EntityUtils; import org.springframework.util.ObjectUtils; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.*; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -247,7 +246,77 @@ } } /** * get请求 * @param url 请求地址(get请求时参数自己组装到url上) * @param headerMap 请求头 * @return 响应文本 */ public static String get(String url, Map<String, String> headerMap,String param) { // 请求地址,以及参数设置 HttpPost post = new HttpPost(url); if (headerMap != null) { for (Map.Entry<String, String> entry : headerMap.entrySet()) { post.setHeader(entry.getKey(), entry.getValue()); } } if (StringUtils.isNotBlank(param)) { log.info("参数值:{}", param); HttpEntity httpEntity = new StringEntity(param, "utf-8"); post.setEntity(httpEntity); } // 执行请求,获取相应 return getRespString(post); } /** * 获取响应信息(String) */ public static String getRespString(HttpUriRequest request) { // 获取响应流 InputStream in = getRespInputStream(request); StringBuilder sb = new StringBuilder(); String line; BufferedReader br = new BufferedReader(new InputStreamReader(in)); try { while ((line = br.readLine()) != null) { sb.append(line); } } catch (IOException e) { e.printStackTrace(); } String str = sb.toString(); return str; } /** * 获取响应信息(InputStream) */ public static InputStream getRespInputStream(HttpUriRequest request) { // 获取响应对象 HttpResponse response = null; try { response = HttpClients.createDefault().execute(request); } catch (Exception e) { e.printStackTrace(); } if (response == null) { return null; } // 获取Entity对象 HttpEntity entity = response.getEntity(); // 获取响应信息流 InputStream in = null; if (entity != null) { try { in = entity.getContent(); } catch (Exception e) { e.printStackTrace(); } } return in; } } springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/BigScreenStatisticsApi.java
@@ -12,6 +12,7 @@ import com.panzhihua.common.model.vos.screen.ScreenDrawEventVO; import com.panzhihua.common.service.community.CommunityService; import com.panzhihua.common.service.grid.GridService; import com.panzhihua.common.service.user.UserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -29,6 +30,8 @@ private CommunityService communityService; @Resource private GridService gridService; @Resource private UserService userService; @ApiOperation(value = "大屏测试接口") @GetMapping("/test/noToken") @@ -99,7 +102,7 @@ return gridService.getCivilDrawList(eventListDTO); } @ApiOperation(value = "事件大屏画圈展示事件坐标点接口@lyq",response = ScreenDrawEventPopulationTotalVO.class) @ApiOperation(value = "根据小区id获取小区信息@lyq",response = ScreenDrawEventPopulationTotalVO.class) @GetMapping("/civil/village/statistics/noToken") public R civilVillageStatistics(@RequestParam("villageId") Long villageId) { if(villageId == null){ @@ -107,4 +110,13 @@ } return gridService.civilVillageStatistics(villageId); } @ApiOperation(value = "获取社区网格员列表接口@lyq",response = EventGridMemberVO.class) @GetMapping("/grids/member/noToken") public R getGridsMemberList(@RequestParam("communityId") Long communityId) { if(communityId == null){ return R.fail("参数错误"); } return userService.getGridsMemberList(communityId); } } springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/api/UserApi.java
@@ -983,4 +983,9 @@ return userService.getGridIsOk(userId); } @GetMapping("getGridsMemberList") public R getGridsMemberList(@RequestParam("communityId") Long communityId) { return userService.getGridsMemberList(communityId); } } springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/dao/UserDao.java
@@ -16,6 +16,7 @@ import com.panzhihua.common.model.vos.LoginUserInfoVO; import com.panzhihua.common.model.vos.community.ComActVO; import com.panzhihua.common.model.vos.community.ComMngVolunteerMngVO; import com.panzhihua.common.model.vos.community.screen.event.EventGridMemberVO; import com.panzhihua.common.model.vos.grid.GridMemberVO; import com.panzhihua.common.model.vos.user.AdministratorsUserVO; import com.panzhihua.common.model.vos.user.SysUserNoticeVO; @@ -428,4 +429,7 @@ @Select("select count(id) from event_grid_member_relation where grid_member_id = #{userId}") Integer getGridIsOk(@Param("userId") Long userId); @Select("select user_id,nick_name,phone from sys_user where type = 6 and community_id = #{communityId} limit 3") List<EventGridMemberVO> getGridsMemberList(@Param("communityId") Long communityId); } springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/UserService.java
@@ -469,4 +469,6 @@ R listAgreements(Long communityId); R getGridIsOk(Long userId); R getGridsMemberList(Long communityId); } springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
@@ -2172,4 +2172,9 @@ return R.fail(); } } @Override public R getGridsMemberList(Long communityId){ return R.ok(this.userDao.getGridsMemberList(communityId)); } }