try{
JSONObject parentJSON = new JSONObject();
parentJSON.put("page", "pages/gu_life/discount_coupon/discount_coupon");
parentJSON.put("scene", coupon_id);
//token 小程序apptoken
String sendUrl="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+token;
//临时生成 所以直接放到项目中 生成后截图就行 单个文件 生成新的直接覆盖旧的 不会浪费内存 如果有需求需要保存的 直接数据库持久化存储即可
byte[] data = HttpsClientUtils.createHttpsInstance().postByte(sendUrl, parentJSON.toString());
HttpServletResponse response = this.getHttpResponse();
String path="coupon.jpg";
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(path, "UTF-8"));
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
bos.write(data);
//new一个文件对象用来保存图片
File imageFile = new File(path);
outStream = new FileOutputStream(imageFile);
//写入数据
outStream.write(data);
} catch (Exception e) {
e.printStackTrace();
}finally{
// 释放资源
try{
if(outStream!=null){
outStream.close();
outStream = null;
}
}catch(Exception e){
LogUtil.e(e.getMessage(),e);
}
}
return null;