首页 > 其他 > 详细

获取请求体中图片的二进制流直接解析成图片

时间:2019-12-12 12:02:57      阅读:292      评论:0      收藏:0      [点我收藏+]
//对path进行urlEncode
        path = UrlEncodeDecodeUtil.urlEnode(path);
        String url = "https://api.weixin.qq.com/wxa/get_qrcode?access_token={access_token}&path={path}";
        //新的业务逻辑
        final String imageJpeg = "image/jpeg";
        HttpHeaders headers = new HttpHeaders();
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            List list = new ArrayList<>();
            list.add(MediaType.valueOf(imageJpeg));
            headers.setAccept(list);

            ResponseEntity<byte[]> response = restTemplate.exchange(
                    url,
                    HttpMethod.GET,
                    new HttpEntity<byte[]>(headers),
                    byte[].class,authorization.getAuthorizerAccessToken(),path);

            byte[] result = response.getBody();

            BussinessLogger.printLogger(this,"二维码返回结果result:"+result);
//            inputStream = new ByteArrayInputStream(result);
            return result;
//            File file = new File(System.currentTimeMillis()+".jpeg");
//            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();

        }finally {
            if(inputStream != null){
                inputStream.close();
            }
            if(outputStream != null){
                outputStream.close();
            }
        }
//controller
@GetMapping(value = "qrCode",produces = MediaType.IMAGE_JPEG_VALUE)
public Object getQrcode(@RequestParam("appId") String appId,
                                          @RequestParam(value = "path",required = false) String path) throws IOException {}

  

获取请求体中图片的二进制流直接解析成图片

原文:https://www.cnblogs.com/liangmm/p/12027845.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!