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

      

  • 相关阅读:
    Python-list
    C3P0数据库连接池使用中的问题
    不变类和可变类
    apollo配置中心部署文档
    Apollo使用文档(Java)
    Redis偶发连接失败案例分析
    创建Kibana耗时报表
    Session服务器配置,如何保存在专门的StateServer服务器中
    Linux命令对应的英文全称
    IIS记录真实来源IP,Advanced Logging(高级日志)的安装以及X-Forwarded-For的配置
  • 原文地址:https://www.cnblogs.com/liangmm/p/12027845.html
Copyright © 2011-2022 走看看