处理问题

This commit is contained in:
wanggeng 2022-08-23 12:02:47 +08:00
parent dd7fe484db
commit ab63d88141
2 changed files with 84 additions and 51 deletions

View File

@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import ink.wgink.common.manager.env.EnvManager; import ink.wgink.common.manager.env.EnvManager;
import ink.wgink.login.base.manager.ConfigManager; import ink.wgink.login.base.manager.ConfigManager;
import org.apache.commons.lang3.StringUtils;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.io.*; import java.io.*;
@ -34,7 +35,9 @@ import java.util.Map.Entry;
*/ */
public class SMCHttpUtil { public class SMCHttpUtil {
/** 请求超时时间 */ /**
* 请求超时时间
*/
private static Integer TIMEOUT = 3000; private static Integer TIMEOUT = 3000;
private static final String CHECK_MEETING_URL = "huaweiSmcCheckMeetingUrl"; private static final String CHECK_MEETING_URL = "huaweiSmcCheckMeetingUrl";
private static final String CHECK_MEETING_NAME_URL = "huaweiSmcCheckMeetingNameUrl"; private static final String CHECK_MEETING_NAME_URL = "huaweiSmcCheckMeetingNameUrl";
@ -50,6 +53,9 @@ public class SMCHttpUtil {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override @Override
public boolean verify(String urlHostName, SSLSession session) { public boolean verify(String urlHostName, SSLSession session) {
if (StringUtils.isBlank(urlHostName)) {
return false;
}
return true; return true;
} }
}); });
@ -60,7 +66,7 @@ public class SMCHttpUtil {
private static void trustAllHttpsCertificates() throws NoSuchAlgorithmException, KeyManagementException { private static void trustAllHttpsCertificates() throws NoSuchAlgorithmException, KeyManagementException {
TrustManager[] trustAllCerts = new TrustManager[1]; TrustManager[] trustAllCerts = new TrustManager[1];
trustAllCerts[0] = new TrustAllManager(); trustAllCerts[0] = new TrustAllManager();
SSLContext sc = SSLContext.getInstance("SSL"); SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, trustAllCerts, null); sc.init(null, trustAllCerts, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} }
@ -71,33 +77,41 @@ public class SMCHttpUtil {
} }
public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {
if (certs == null && StringUtils.isBlank(authType)) {
throw new CertificateException("异常");
}
} }
public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
if (certs == null && StringUtils.isBlank(authType)) {
throw new CertificateException("异常");
}
} }
} }
/** /**
* 删除会议室 * 删除会议室
*
* @param meetingId 会议室ID * @param meetingId 会议室ID
* @return * @return
* @throws Exception * @throws Exception
*/ */
public void deleteMeeting(String meetingId) throws Exception { public void deleteMeeting(String meetingId) throws Exception {
List<Map<String,String>> list = new ArrayList<Map<String,String>>(); List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String,String> param = new HashMap<String,String>(); Map<String, String> param = new HashMap<String, String>();
param.put("id", meetingId); param.put("id", meetingId);
list.add(param); list.add(param);
String json = JSONObject.toJSONString(list); String json = JSONObject.toJSONString(list);
String result = doJson(EnvManager.getInstance().getValue(DELETE_MEETING_URL), "DELETE", json); String result = doJson(EnvManager.getInstance().getValue(DELETE_MEETING_URL), "DELETE", json);
if(result.contains("error")) { if (result.contains("error")) {
throw new Exception("删除会议室失败"); throw new Exception("删除会议室失败");
} }
} }
/** /**
* 创建会议室 * 创建会议室
* @param name 名称 ( : 集宁区-张三丰) *
* @param name 名称 ( : 集宁区-张三丰)
* @param username 账号 * @param username 账号
* @return * @return
* @throws Exception * @throws Exception
@ -107,7 +121,7 @@ public class SMCHttpUtil {
params.put("name", username); params.put("name", username);
// 判断是否已存在 // 判断是否已存在
Boolean exists = checkMeetingExists(username); Boolean exists = checkMeetingExists(username);
if(exists) { if (exists) {
throw new Exception("该账号已存在会议室"); throw new Exception("该账号已存在会议室");
} }
// 判断是否已存在 // 判断是否已存在
@ -130,7 +144,7 @@ public class SMCHttpUtil {
String json = JSONObject.toJSONString(create); String json = JSONObject.toJSONString(create);
try { try {
String result = doJson(EnvManager.getInstance().getValue(CREATE_MEETING_URL), "POST", json); String result = doJson(EnvManager.getInstance().getValue(CREATE_MEETING_URL), "POST", json);
if(result.contains("MEETINGROOM_NAME_EXIST")) { if (result.contains("MEETINGROOM_NAME_EXIST")) {
throw new Exception("该名称已存在会议室"); throw new Exception("该名称已存在会议室");
} }
SMCMeetingDTO dto = new SMCMeetingDTO(); SMCMeetingDTO dto = new SMCMeetingDTO();
@ -139,13 +153,14 @@ public class SMCHttpUtil {
dto.setNumber(number); dto.setNumber(number);
dto.setUsername(username); dto.setUsername(username);
return dto; return dto;
}catch (Exception e) { } catch (Exception e) {
throw e; throw e;
} }
} }
/** /**
* 获取随机的会议终端号码 * 获取随机的会议终端号码
*
* @return * @return
*/ */
private String getMeetingNumber() throws Exception { private String getMeetingNumber() throws Exception {
@ -153,7 +168,7 @@ public class SMCHttpUtil {
// params.put("zoneid", "06e26a21-36b9-47e9-aabd-944eb7a33e23"); // params.put("zoneid", "06e26a21-36b9-47e9-aabd-944eb7a33e23");
params.put("number", 1); // 数量 params.put("number", 1); // 数量
String result = doPost(EnvManager.getInstance().getValue(GET_MEETING_NUMBER_URL), params, null); String result = doPost(EnvManager.getInstance().getValue(GET_MEETING_NUMBER_URL), params, null);
if(result.contains("error")) { if (result.contains("error")) {
throw new Exception("获取随机的会议终端号失败"); throw new Exception("获取随机的会议终端号失败");
} }
JSONArray jsonArray = JSONObject.parseArray(result); JSONArray jsonArray = JSONObject.parseArray(result);
@ -162,6 +177,7 @@ public class SMCHttpUtil {
/** /**
* 验证会议室是否已经存在 * 验证会议室是否已经存在
*
* @return * @return
*/ */
public Boolean checkMeetingExists(String username) throws Exception { public Boolean checkMeetingExists(String username) throws Exception {
@ -175,6 +191,7 @@ public class SMCHttpUtil {
/** /**
* 验证会议室是否已经存在 * 验证会议室是否已经存在
*
* @return * @return
*/ */
public Boolean checkMeetingNameExists(String name) throws Exception { public Boolean checkMeetingNameExists(String name) throws Exception {
@ -213,12 +230,13 @@ public class SMCHttpUtil {
/** /**
* jsonPost请求 * jsonPost请求
* @Description: TODO *
* @param @param postUrl * @param @param postUrl
* @param @param json * @param @param json
* @param @return * @param @return
* @return String * @return String
* @throws * @throws
* @Description: TODO
* @author 崔宝铖 * @author 崔宝铖
* @date 2019年6月19日 * @date 2019年6月19日
*/ */
@ -236,9 +254,9 @@ public class SMCHttpUtil {
httpUrlConnection.setRequestMethod(type); httpUrlConnection.setRequestMethod(type);
httpUrlConnection.setRequestProperty("X-HW-ID", "697db861-bc1b-4e31-bc75-969e1ab5a9a5"); httpUrlConnection.setRequestProperty("X-HW-ID", "697db861-bc1b-4e31-bc75-969e1ab5a9a5");
httpUrlConnection.setRequestProperty("X-HW-APPKEY", "H!UkcRIWb/lI1034/w5T3h%c5..4#8.+L-085%g!3Kq$w.vg3w$QD0!%i#nqE=83"); httpUrlConnection.setRequestProperty("X-HW-APPKEY", "H!UkcRIWb/lI1034/w5T3h%c5..4#8.+L-085%g!3Kq$w.vg3w$QD0!%i#nqE=83");
httpUrlConnection.setRequestProperty("Connection","keep-Alive"); httpUrlConnection.setRequestProperty("Connection", "keep-Alive");
//设置发送文件类型 //设置发送文件类型
httpUrlConnection.setRequestProperty("Content-Type","application/json"); httpUrlConnection.setRequestProperty("Content-Type", "application/json");
// 输入 输出 都打开 // 输入 输出 都打开
httpUrlConnection.setDoOutput(true); httpUrlConnection.setDoOutput(true);
httpUrlConnection.setDoInput(true); httpUrlConnection.setDoInput(true);
@ -249,24 +267,28 @@ public class SMCHttpUtil {
out.write(json.getBytes()); out.write(json.getBytes());
out.flush(); out.flush();
// 读取数据 // 读取数据
br = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream(),"utf-8")); br = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream(), "utf-8"));
String line = null; String line = null;
while (null != (line=br.readLine())){ while (null != (line = br.readLine())) {
response += line; response += line;
} }
// 获得URL的响应状态码 // 获得URL的响应状态码
status = new Integer(httpUrlConnection.getResponseCode()).toString(); status = new Integer(httpUrlConnection.getResponseCode()).toString();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}finally { } finally {
try { try {
if (out != null) { out.close();} if (out != null) {
if (br != null) {br.close();} out.close();
}
if (br != null) {
br.close();
}
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
if(!status.startsWith("2")) { if (!status.startsWith("2")) {
System.out.println(response); System.out.println(response);
throw new Exception("请求结果状态不是200"); throw new Exception("请求结果状态不是200");
} }
@ -275,20 +297,21 @@ public class SMCHttpUtil {
/** /**
* Post请求 * Post请求
* @Description: TODO *
* @param @param postUrl * @param @param postUrl
* @param @param param * @param @param param
* @param @return * @param @return
* @return String * @return String
* @throws IOException * @throws IOException
* @throws * @throws
* @Description: TODO
* @author 崔宝铖 * @author 崔宝铖
* @date 2019年6月19日 * @date 2019年6月19日
*/ */
private static String doPost(String postUrl, Map<String,Object> param, JSONObject jsonObject) throws Exception { private static String doPost(String postUrl, Map<String, Object> param, JSONObject jsonObject) throws Exception {
// 封装发送的请求参数 // 封装发送的请求参数
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
if(param != null) { if (param != null) {
buffer.append("?"); buffer.append("?");
int x = 0; int x = 0;
for (Entry<String, Object> map : param.entrySet()) { for (Entry<String, Object> map : param.entrySet()) {
@ -317,14 +340,14 @@ public class SMCHttpUtil {
String status = "";// 响应状态 String status = "";// 响应状态
PrintWriter out = null; PrintWriter out = null;
BufferedReader in = null; BufferedReader in = null;
try{ try {
// 获取URLConnection对象对应的输出流 // 获取URLConnection对象对应的输出流
out = new PrintWriter(httpUrlConnection.getOutputStream()); out = new PrintWriter(httpUrlConnection.getOutputStream());
// 发送请求参数 // 发送请求参数
if(buffer.toString().length() > 0) { if (buffer.toString().length() > 0) {
out.write(buffer.toString()); out.write(buffer.toString());
} }
if(jsonObject != null) { if (jsonObject != null) {
String json = java.net.URLEncoder.encode(jsonObject.toString(), "utf-8"); String json = java.net.URLEncoder.encode(jsonObject.toString(), "utf-8");
out.write(json); out.write(json);
} }
@ -339,17 +362,21 @@ public class SMCHttpUtil {
} }
// 获得URL的响应状态码 // 获得URL的响应状态码
status = new Integer(httpUrlConnection.getResponseCode()).toString(); status = new Integer(httpUrlConnection.getResponseCode()).toString();
}catch(Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}finally { } finally {
try { try {
if (out != null) { out.close();} if (out != null) {
if (in != null) {in.close();} out.close();
}
if (in != null) {
in.close();
}
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
if(!status.startsWith("2")) { if (!status.startsWith("2")) {
System.out.println(response); System.out.println(response);
throw new Exception("请求结果状态不是200"); throw new Exception("请求结果状态不是200");
} }
@ -358,37 +385,39 @@ public class SMCHttpUtil {
/** /**
* Get请求 * Get请求
* @Description: TODO *
* @param @param getUrl 请求地址 * @param @param getUrl 请求地址
* @param @param param 请求参数 * @param @param param 请求参数
* @param @return * @param @return
* @param @throws Exception * @param @throws Exception
* @return RetBody<PageData> * @return RetBody<PageData>
* @throws * @throws
* @Description: TODO
* @author 崔宝铖 * @author 崔宝铖
* @date 2019年6月19日 * @date 2019年6月19日
*/ */
private static String doGet(String getUrl, Map<String,Object> param, Map<String,String> property) throws Exception { private static String doGet(String getUrl, Map<String, Object> param, Map<String, String> property) throws Exception {
return doInitToken(getUrl, param, property); return doInitToken(getUrl, param, property);
} }
/** /**
* 初始化Token * 初始化Token
*
* @param getUrl * @param getUrl
* @param param * @param param
* @param property * @param property
* @return * @return
* @throws Exception * @throws Exception
*/ */
private static String doInitToken(String getUrl, Map<String,Object> param, Map<String,String> property) throws Exception { private static String doInitToken(String getUrl, Map<String, Object> param, Map<String, String> property) throws Exception {
// 封装发送的请求参数 // 封装发送的请求参数
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
if(param != null) { if (param != null) {
buffer.append("?"); buffer.append("?");
int x = 0; int x = 0;
for(Entry<String, Object> map : param.entrySet()) { for (Entry<String, Object> map : param.entrySet()) {
buffer.append(map.getKey()).append("=").append(map.getValue().toString()); buffer.append(map.getKey()).append("=").append(map.getValue().toString());
if(x != param.size()-1) { if (x != param.size() - 1) {
buffer.append("&"); buffer.append("&");
} }
x++; x++;
@ -396,7 +425,7 @@ public class SMCHttpUtil {
} }
String urlPath = getUrl + buffer.toString(); String urlPath = getUrl + buffer.toString();
URL url = new URL(urlPath); URL url = new URL(urlPath);
URLConnection urlConnection = url.openConnection(); URLConnection urlConnection = url.openConnection();
HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection; HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection;
httpUrlConnection.setConnectTimeout(TIMEOUT); httpUrlConnection.setConnectTimeout(TIMEOUT);
// 设置请求头属性参数 // 设置请求头属性参数
@ -408,7 +437,7 @@ public class SMCHttpUtil {
httpUrlConnection.setRequestProperty("charset", "UTF-8"); httpUrlConnection.setRequestProperty("charset", "UTF-8");
httpUrlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); httpUrlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpUrlConnection.setRequestProperty("accept", "application/json"); httpUrlConnection.setRequestProperty("accept", "application/json");
if(property != null) { if (property != null) {
for (Entry<String, String> map : property.entrySet()) { for (Entry<String, String> map : property.entrySet()) {
httpUrlConnection.setRequestProperty(map.getKey(), map.getValue()); httpUrlConnection.setRequestProperty(map.getKey(), map.getValue());
} }
@ -417,7 +446,7 @@ public class SMCHttpUtil {
String status = "";// 响应状态6 String status = "";// 响应状态6
PrintWriter out = null; PrintWriter out = null;
BufferedReader in = null; BufferedReader in = null;
try{ try {
// httpUrlConnection.connect(); // httpUrlConnection.connect();
// 定义BufferedReader输入流来读取URL的响应数据 // 定义BufferedReader输入流来读取URL的响应数据
in = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream(), "UTF-8")); in = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream(), "UTF-8"));
@ -427,17 +456,21 @@ public class SMCHttpUtil {
} }
// 获得URL的响应状态码 // 获得URL的响应状态码
status = new Integer(httpUrlConnection.getResponseCode()).toString(); status = new Integer(httpUrlConnection.getResponseCode()).toString();
}catch(Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}finally { } finally {
try { try {
if (out != null) { out.close();} if (out != null) {
if (in != null) {in.close();} out.close();
}
if (in != null) {
in.close();
}
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
if(!status.startsWith("2")) { if (!status.startsWith("2")) {
System.out.println(response); System.out.println(response);
throw new Exception("请求结果状态不是200"); throw new Exception("请求结果状态不是200");
} }

View File

@ -156,7 +156,7 @@ logging:
file: file:
name: /project/logs/usercenter-logs.log name: /project/logs/usercenter-logs.log
level: level:
root: error root: debug
org.springframework.data.mongodb: debug org.springframework.data.mongodb: debug
org.springframework.boot.autoconfigure.security.servlet: debug org.springframework.boot.autoconfigure.security.servlet: debug
ink.wgink: debug ink.wgink: debug