wangrenhuang
2022-06-24 c3b1c7fc5e317ed328180c1755845e5d41851f86
新增二维码加上版本参数
1个文件已修改
86 ■■■■■ 已修改文件
src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java 86 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java
@@ -605,4 +605,90 @@
        return obj;
    }
    /**生成无限二维码,并上传到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)
    {
        String imgUrl = null;
        InputStream in = null;
        HttpURLConnection conn = null;
        try {
            //生成发送数据
            JSONObject obj = new JSONObject();
            obj.put("scene", scene);
            obj.put("width", width);
            obj.put("page", page);
            obj.put("auto_color", autoColor);
            obj.put("line_color", lineColor);
            obj.put("is_hyaline", isHyaline);
            obj.put("env_version", env_version);
            // 创建url资源
            URL url = new URL(StringUtils.format(URL_UNLIMIT_SQUARE, at));
            // 建立http连接
            conn = (HttpURLConnection) url.openConnection();
            // 设置允许输出
            conn.setDoOutput(true);
            conn.setDoInput(true);
            // 设置不用缓存
            conn.setUseCaches(false);
            // 设置传递方式
            conn.setRequestMethod("POST");
            // 设置维持长连接
            conn.setRequestProperty("Connection", "Keep-Alive");
            // 设置文件字符集:
            conn.setRequestProperty("Charset", "UTF-8");
            // 设置文件类型:
            conn.setRequestProperty("contentType", "application/json");
            // 开始连接请求
            conn.connect();
            OutputStream out = conn.getOutputStream();
            // 写入请求的字符串
            out.write((obj.toString()).getBytes());
            out.flush();
            out.close();
            // 请求返回的状态
            if (conn.getResponseCode() == 200) {
                // 请求返回的数据
                in = conn.getInputStream();
                imgUrl = OSSUtil.uploadImg(fileName, in, keyId, keySecret, endPoint, bucket);
                conn.disconnect();
                conn = null;
            }
            if (in != null) {
                in.close();
                in = null;
            }
            if (conn != null) {
                conn.disconnect();
                conn = null;
            }
        }catch (Exception e)
        {
            e.printStackTrace();
            if (in != null) {
                try {
                    in.close();
                }catch (Exception ep)
                {
                    ep.printStackTrace();
                }
                in = null;
            }
            if (conn != null) {
                conn.disconnect();
                conn = null;
            }
        }
        return imgUrl;
    }
}