From 1936559ec4565a4e9ac7ecf2844eca06c9712905 Mon Sep 17 00:00:00 2001 From: huanghongfa <huanghongfa123456> Date: 星期五, 23 七月 2021 10:42:47 +0800 Subject: [PATCH] 修改bug --- springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/WxOfficialApi.java | 22 ++++++++++++---------- 1 files changed, 12 insertions(+), 10 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/WxOfficialApi.java b/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/WxOfficialApi.java index 2bbad89..7865967 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/WxOfficialApi.java +++ b/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/WxOfficialApi.java @@ -1,11 +1,11 @@ package com.panzhihua.applets.api; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.utlis.StringUtils; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; -import org.checkerframework.checker.units.qual.A; import org.springframework.web.bind.annotation.*; import java.io.*; @@ -72,7 +72,7 @@ Map<String, Object> map = new HashMap<>(); map.put("type", "news"); // news表示图文类型的素材,具体看API文档 map.put("offset", 0); - map.put("count", 1); + map.put("count", 5); // 将map转换成json字符串 String paramBody = JSON.toJSONString(map); // 这里用了Alibaba的fastjson @@ -82,20 +82,21 @@ 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 = in.read(b)) != -1) { - sb.append(new String(b,0,len)); + while((len = br.read()) != -1) { + sb.append(new String(b,0,len,"utf-8")); } in.close(); return sb.toString(); } - @ApiOperation(value = "拉取公众号列表") - @GetMapping("/list/noToken") + @GetMapping(value = "/list/noToken") public R pageDiscuss() throws Exception{ WxOfficialApi officialApi = new WxOfficialApi(); @@ -104,19 +105,20 @@ for (int i = 0; i < appidList.size(); i++) { String token = officialApi.getToken(appidList.get(i),secretList.get(i)); log.info("通过appid:"+appidList.get(i)+"获取token返回参数:" + token); - if(StringUtils.isNotEmpty(token)){ - tokenList.add(token); + JSONObject tokenJson = JSON.parseObject(token); + if(StringUtils.isNotEmpty(tokenJson)){ + tokenList.add(tokenJson.getString("access_token")); } } } - List<String> resultList = new ArrayList<>(); + List<JSONObject> resultList = new ArrayList<>(); if(!tokenList.isEmpty()){ tokenList.forEach(token -> { try { String result = officialApi.getContentList(token); log.info("通过token获取文章列表成功,返回结果:" + result); - resultList.add(result); + resultList.add(JSON.parseObject(result)); }catch (Exception e){ log.error("通过token获取文章列表失败,错误原因:" + e.getMessage()); } -- Gitblit v1.7.1