zoukankan      html  css  js  c++  java
  • 获取请求体中图片的二进制流直接解析成图片

    //对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 {}
    

      

  • 相关阅读:
    JZOJ5809 数羊
    P3313 [SDOI2014]旅行
    2019.10.22 NOIP模拟测试 day2
    P4322 [JSOI2016]最佳团体
    P1850 换教室
    P3225 [HNOI2012]矿场搭建
    P2607 [ZJOI2008]骑士
    2019.10.21 NOIP模拟测试 day1
    AFO
    禁止加载浏览器图片
  • 原文地址:https://www.cnblogs.com/liangmm/p/12027845.html
Copyright © 2011-2022 走看看