chenjiahe
2022-06-27 a0ad14b0a0fb60604b0a9cf978a537e64479a8d4
src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java
@@ -606,14 +606,25 @@
   }
   /**生成无限二维码,并上传到OSS*/
   public static String createUnlimitQrCode(String at, String scene, String page, int width, boolean autoColor,
                                  JSONObject lineColor, boolean isHyaline, String fileName, String keyId,
                                  String keySecret, String endPoint, String bucket, String env_version)
   {
   /**生成无限二维码,返回临时文
    * @param at 微信token
    * @param scene 参数,只能32位,最好不要中文
    * @param page 跳转链接
    * @param width 宽度
    * @param autoColor 默认false
    * @param lineColor 默认null
    * @param isHyaline 默认false
    * @return
    */
   public static File createUnlimitQrCode(String at, String scene, String page, int width, boolean autoColor,
                                 JSONObject lineColor, boolean isHyaline, String env_version) throws IOException {
      String imgUrl = null;
      InputStream in = null;
      HttpURLConnection conn = null;
      //创建临时文件
      File file = File.createTempFile("temp", ".jpg");
      try {
         //生成发送数据
@@ -654,7 +665,15 @@
         if (conn.getResponseCode() == 200) {
            // 请求返回的数据
            in = conn.getInputStream();
            imgUrl = OSSUtil.uploadImg(fileName, in, keyId, keySecret, endPoint, bucket);
            //输入到临时文件
            /*OutputStream os = new FileOutputStream(file);
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
               os.write(buffer, 0, bytesRead);
            }*/
            FileUtils.copyInputStreamToFile(in, file);
            conn.disconnect();
            conn = null;
         }
@@ -668,15 +687,12 @@
            conn.disconnect();
            conn = null;
         }
      }catch (Exception e)
      {
      }catch (Exception e) {
         e.printStackTrace();
         if (in != null) {
            try {
               in.close();
            }catch (Exception ep)
            {
            }catch (Exception ep) {
               ep.printStackTrace();
            }
            in = null;
@@ -686,9 +702,10 @@
            conn.disconnect();
            conn = null;
         }
      }finally {
         file.deleteOnExit();
      }
      return imgUrl;
      return file;
   }
}