From 045b55722b25ccc77d88671c5d6df309edb8a66d Mon Sep 17 00:00:00 2001
From: 钟日健 <5689795+arsn@user.noreply.gitee.com>
Date: Tue, 22 Feb 2022 16:00:34 +0800
Subject: [PATCH] 1. 保安员新增异步推送数据至群访用户表 2. 会员标记接口新增,会员标记成功,则创建会员记录和会员题库记录(包含120道题目) 3. web 端考试开始,查询题目判断用户是否为会员,如果为会员则从会员题库获取当前人员的考试题目(从120道题中随机抽取60道)

---
 src/main/java/org/springblade/common/utils/HttpReqUtil.java |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/src/main/java/org/springblade/common/utils/HttpReqUtil.java b/src/main/java/org/springblade/common/utils/HttpReqUtil.java
index 39f99a0..3242d0d 100644
--- a/src/main/java/org/springblade/common/utils/HttpReqUtil.java
+++ b/src/main/java/org/springblade/common/utils/HttpReqUtil.java
@@ -107,6 +107,21 @@
 		return postJson(url, json, header);
 	}
 
+	public String doPostJsons(String url, Map<String, Object> params, Map<String, String> header) throws Exception {
+		String json = null;
+		if (params != null && !params.isEmpty()) {
+			for (Iterator<Entry<String, Object>> it = params.entrySet().iterator(); it.hasNext();) {
+				Entry<String, Object> entry = (Entry<String, Object>) it.next();
+				Object object = entry.getValue();
+				if (object == null) {
+					it.remove();
+				}
+			}
+			json = JSON.toJSONString(params);
+		}
+		return postJsons(url, json, header);
+	}
+
 	public String doPostJson(String url, String json) throws Exception {
 		return doPostJson(url, json, null);
 	}
@@ -144,6 +159,35 @@
 		return body;
 	}
 
+	private String postJsons(String url, String json, Map<String, String> header) throws Exception {
+		String body = null;
+		try {
+			// Post请求
+			LOG.debug(" protocol: POST");
+			LOG.debug("      url: " + url);
+			HttpPost httpPost = new HttpPost(url.trim());
+			// 设置参数
+			LOG.debug("   params: " + json);
+			httpPost.setEntity(new StringEntity(json, ContentType.DEFAULT_TEXT.withCharset(charset)));
+			httpPost.setHeader(new BasicHeader("Content-Type", "application/json"));
+			LOG.debug("     type: JSON");
+			// 设置Header
+			if (header != null && !header.isEmpty()) {
+				LOG.debug("   header: " + JSON.toJSONString(header));
+				for (Iterator<Entry<String, String>> it = header.entrySet().iterator(); it.hasNext();) {
+					Entry<String, String> entry = (Entry<String, String>) it.next();
+					httpPost.setHeader(new BasicHeader(entry.getKey(), entry.getValue()));
+				}
+			}
+			// 发送请求,获取返回数据
+			body = execute(httpPost);
+		} catch (Exception e) {
+			throw e;
+		}
+		LOG.debug("  result: " + body);
+		return body;
+	}
+
 	/**
 	 * get请求
 	 */

--
Gitblit v1.9.3