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

      

  • 相关阅读:
    Problem C: 爬楼梯
    Problem E: 倒水(Water)
    Problem H: tmk买礼物
    HDU 1078 FatMouse and Cheese
    POJ 3186 Treats for the Cows
    POJ 1661 Help Jimmy
    POJ 1458 Common Subsequence
    2018-软工机试-D-定西
    2018-软工机试-F-庙会
    2018-软工机试-C-和你在一起
  • 原文地址:https://www.cnblogs.com/liangmm/p/12027845.html
Copyright © 2011-2022 走看看