URL url = new URL("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + access_token);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
JSONObject paramJson = new JSONObject();
paramJson.put("scene", userId);
paramJson.put("page", "/pages/index/index");
paramJson.put("width", 280);
paramJson.put("is_hyaline", true);
paramJson.put("check_path", false);
paramJson.put("env_version", "trial");
PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream());
printWriter.write(paramJson.toString());
printWriter.flush();
BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream());
int responseCode = httpURLConnection.getResponseCode();
System.out.println("二维码返回码" + responseCode);
return bis;
这里 responseCode 返回的内容是 200
证明api调用成功,图片已获取到。但是通过 BufferedInputStream 进行存储成图片后,图片变成了损坏状态
小程序已经发布体验版了
求解答:
如何知道一定返回图片?
然后我是通过存起来的图片通过BufferedImage把图片文件再读出来校验图像是否有效