From c3b1c7fc5e317ed328180c1755845e5d41851f86 Mon Sep 17 00:00:00 2001 From: wangrenhuang <wangren_huang@163.com> Date: 星期五, 24 六月 2022 18:32:15 +0800 Subject: [PATCH] 新增二维码加上版本参数 --- src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 86 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java b/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java index 2035142..8a52d18 100644 --- a/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java +++ b/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; + } + } -- Gitblit v1.8.0