小程序码生成错误图片
代码demo:
public Map getminiqrQr(String accessToken) { RestTemplate rest = new RestTemplate(); InputStream inputStream = null ; OutputStream outputStream = null ; try { String url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" +accessToken; Mapparam = new HashMap<>(); param.put( "page" , "pages/index/index" ); param.put( "width" , 430 ); param.put( "auto_color" , false ); Mapline_color = new HashMap<>(); line_color.put( "r" , 0 ); line_color.put( "g" , 0 ); line_color.put( "b" , 0 ); param.put( "line_color" , line_color); LOG.info( "调用生成微信URL接口传参:" + param); MultiValueMapheaders = new LinkedMultiValueMap<>(); HttpEntity requestEntity = new HttpEntity(param, headers); ResponseEntityentity = rest.exchange(url, HttpMethod.POST, requestEntity, byte []. class , new Object[ 0 ]); LOG.info( "调用小程序生成微信永久小程序码URL接口返回结果:" + entity.getBody()); byte [] result = entity.getBody(); LOG.info(Base64.encodeBase64String(result)); inputStream = new ByteArrayInputStream(result); File file = new File( "C:/Users/wangqiulin/Desktop/1.png" ); if (!file.exists()){ file.createNewFile(); } outputStream = new FileOutputStream(file); int len = 0 ; byte [] buf = new byte [ 1024 ]; while ((len = inputStream.read(buf, 0 , 1024 )) != - 1 ) { outputStream.write(buf, 0 , len); } outputStream.flush(); } catch (Exception e) { LOG.error( "调用小程序生成微信永久小程序码URL接口异常" ,e); } finally { if (inputStream != null ){ try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } if (outputStream != null ){ try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return null ; } |
生成如下图片信息
这种现象偶然发生,有时多次调用后就可以成功,请问是什么问题