获取小程序码图片保存本地无法打开,postman返回图片能正常查看
发布于 6 年前 作者 xcui 14373 次浏览 来自 问答




public Map gen(String accessToken) {

RestTemplate rest = new RestTemplate();
   InputStream inputStream = null;
   OutputStream outputStream = null;
   try {
String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+accessToken;
       Map<String,Object> param = new HashMap<>();
       param.put("scene", "");
       param.put("page", "pages/index/index");
       param.put("width", 430);
       param.put("auto_color", false);
       Map<String,Object> line_color = new HashMap<>();
       line_color.put("r", 0);
       line_color.put("g", 0);
       line_color.put("b", 0);
       param.put("line_color", line_color);
     
       MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
       HttpEntity requestEntity = new HttpEntity(param, headers);
       ResponseEntity<byte[]> entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]);
       byte[] result = entity.getBody();
       
       FileOutputStream fs = new FileOutputStream("C:/Users/Administrator/Desktop/1.jpg");
       FileCopyUtils.copy(new ByteArrayInputStream(result), fs);
   } catch (Exception e) {
e.printStackTrace();
   } finally {

}
return null;
}
回到顶部