| | |
| | | * @return 文章内容 |
| | | */ |
| | | public static R 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); |
| | | // 请求与响应 |
| | | String resp = HttpClientUtil.get(url, getWxHeaderMap()); |
| | | String resp = HttpClientUtil.get(url, getWxHeaderMap(),paramBody); |
| | | log.info(resp); |
| | | return R.ok(resp); |
| | | } |
| | |
| | | * @param headerMap 请求头 |
| | | * @return 响应文本 |
| | | */ |
| | | public static String get(String url, Map<String, String> headerMap) { |
| | | public static String get(String url, Map<String, String> headerMap,String param) { |
| | | // 请求地址,以及参数设置 |
| | | HttpPost post = new HttpPost(url); |
| | | if (headerMap != null) { |
| | |
| | | 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); |
| | | } |