Skip to content

Commit d5e130d

Browse files
committed
Server: 新增支持热更新 远程函数、请求校验、权限校验 的配置;reload/aceess 接口改为 reload 接口,支持重载 Access, Function, Request;优化相关代码
1 parent fa96a85 commit d5e130d

File tree

6 files changed

+370
-103
lines changed

6 files changed

+370
-103
lines changed

APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/demo/server/APIJSONApplication.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public static void main(String[] args) throws Exception {
4040

4141
Log.DEBUG = true; //上线生产环境前改为 false,可不输出 APIJSONORM 的日志 以及 SQLException 的原始(敏感)信息
4242

43-
System.out.println("\n\n\n\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON >>>>>>>>>>>>>>>>>>>>>>>>\n");
43+
System.out.println("\n\n\n\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON 开始启动 >>>>>>>>>>>>>>>>>>>>>>>>\n");
44+
4445
System.out.println("开始测试:远程函数 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
4546
try {
4647
DemoFunction.test();
@@ -57,15 +58,34 @@ public static void main(String[] args) throws Exception {
5758
e.printStackTrace();
5859
}
5960
System.out.println("\n完成测试:请求校验 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
60-
61+
62+
63+
System.out.println("\n\n\n开始初始化:远程函数配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
6164
try {
62-
DemoVerifier.init();
65+
DemoFunction.init(true);
6366
} catch (Exception e) {
6467
e.printStackTrace();
6568
}
69+
System.out.println("\n完成初始化:远程函数配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
6670

71+
System.out.println("\n\n\n开始初始化:请求校验配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
72+
try {
73+
StructureUtil.init(true);
74+
} catch (Exception e) {
75+
e.printStackTrace();
76+
}
77+
System.out.println("\n完成初始化:请求校验配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
78+
79+
System.out.println("\n\n\n开始初始化:权限校验配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
80+
try {
81+
DemoVerifier.init(true);
82+
} catch (Exception e) {
83+
e.printStackTrace();
84+
}
85+
System.out.println("\n完成初始化:权限校验配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
86+
6787

68-
System.out.println("\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON已启动 >>>>>>>>>>>>>>>>>>>>>>>>\n");
88+
System.out.println("\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON 启动完成,试试调用自动化 API 吧 ^_^ >>>>>>>>>>>>>>>>>>>>>>>>\n");
6989
}
7090

7191

APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/demo/server/Controller.java

Lines changed: 100 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
import zuo.biao.apijson.server.exception.ConflictException;
5252
import zuo.biao.apijson.server.exception.NotExistException;
5353
import zuo.biao.apijson.server.exception.OutOfRangeException;
54+
import zuo.biao.apijson.server.model.Access;
55+
import zuo.biao.apijson.server.model.Function;
56+
import zuo.biao.apijson.server.model.Request;
5457

5558

5659
/**request controller
@@ -190,50 +193,22 @@ public String openHead(@PathVariable String request, HttpSession session) {
190193

191194

192195

193-
/**生成验证码,修改为post请求
194-
* @param request
195-
* @return
196-
*/
197-
@PostMapping("reload/access")
198-
public JSONObject reloadAccess(@RequestBody String request) {
199-
JSONObject requestObject = null;
200-
String phone;
201-
String verify;
202-
try {
203-
requestObject = DemoParser.parseRequest(request);
204-
phone = requestObject.getString(PHONE);
205-
verify = requestObject.getString(VERIFY);
206-
} catch (Exception e) {
207-
return DemoParser.extendErrorResult(requestObject, e);
208-
}
209-
210-
JSONResponse response = new JSONResponse(headVerify(Verify.TYPE_RELOAD_ACCESS, phone, verify));
211-
response = response.getJSONResponse(VERIFY_);
212-
if (JSONResponse.isExist(response) == false) {
213-
return DemoParser.extendErrorResult(requestObject, new ConditionErrorException("手机号或验证码错误"));
214-
}
215-
216-
try {
217-
DemoVerifier.init();
218-
} catch (ServerException e) {
219-
e.printStackTrace();
220-
return DemoParser.extendErrorResult(requestObject, e);
221-
}
222-
223-
return DemoParser.newSuccessResult();
224-
}
225-
226-
227-
228-
229196

230197

231198

232199

200+
public static final String FUNCTION_;
201+
public static final String REQUEST_;
202+
public static final String ACCESS_;
203+
233204
public static final String USER_;
234205
public static final String PRIVACY_;
235206
public static final String VERIFY_; //加下划线后缀是为了避免 Verify 和 verify 都叫VERIFY,分不清
236207
static {
208+
FUNCTION_ = Function.class.getSimpleName();
209+
REQUEST_ = Request.class.getSimpleName();
210+
ACCESS_ = Access.class.getSimpleName();
211+
237212
USER_ = User.class.getSimpleName();
238213
PRIVACY_ = Privacy.class.getSimpleName();
239214
VERIFY_ = Verify.class.getSimpleName();
@@ -258,11 +233,84 @@ public JSONObject reloadAccess(@RequestBody String request) {
258233

259234
public static final String TYPE = "type";
260235

236+
237+
238+
/**重新加载配置
239+
* @param request
240+
* @return
241+
* @see
242+
* <pre>
243+
{
244+
"type": "ALL", //重载对象,ALL, FUNCTION, REQUEST, ACCESS,非必须
245+
"phone": "13000082001",
246+
"verify": "1234567" //验证码,对应类型为 Verify.TYPE_RELOAD
247+
}
248+
* </pre>
249+
*/
250+
@PostMapping("reload")
251+
public JSONObject reload(@RequestBody String request) {
252+
JSONObject requestObject = null;
253+
String type;
254+
String phone;
255+
String verify;
256+
try {
257+
requestObject = DemoParser.parseRequest(request);
258+
type = requestObject.getString(TYPE);
259+
phone = requestObject.getString(PHONE);
260+
verify = requestObject.getString(VERIFY);
261+
} catch (Exception e) {
262+
return DemoParser.extendErrorResult(requestObject, e);
263+
}
264+
265+
JSONResponse response = new JSONResponse(headVerify(Verify.TYPE_RELOAD, phone, verify));
266+
response = response.getJSONResponse(VERIFY_);
267+
if (JSONResponse.isExist(response) == false) {
268+
return DemoParser.extendErrorResult(requestObject, new ConditionErrorException("手机号或验证码错误"));
269+
}
261270

271+
JSONObject result = DemoParser.newSuccessResult();
272+
273+
boolean reloadAll = StringUtil.isEmpty(type, true) || "ALL".equals(type);
274+
275+
if (reloadAll || "FUNCTION".equals(type)) {
276+
try {
277+
result.put(FUNCTION_, DemoFunction.init());
278+
} catch (ServerException e) {
279+
e.printStackTrace();
280+
result.put(FUNCTION_, DemoParser.newErrorResult(e));
281+
}
282+
}
283+
284+
if (reloadAll || "REQUEST".equals(type)) {
285+
try {
286+
result.put(REQUEST_, StructureUtil.init());
287+
} catch (ServerException e) {
288+
e.printStackTrace();
289+
result.put(REQUEST_, DemoParser.newErrorResult(e));
290+
}
291+
}
292+
293+
if (reloadAll || "ACCESS".equals(type)) {
294+
try {
295+
result.put(ACCESS_, DemoVerifier.init());
296+
} catch (ServerException e) {
297+
e.printStackTrace();
298+
result.put(ACCESS_, DemoParser.newErrorResult(e));
299+
}
300+
}
301+
302+
return result;
303+
}
262304

263305
/**生成验证码,修改为post请求
264306
* @param request
265-
* @return
307+
* @see
308+
* <pre>
309+
{
310+
"type": 0, //类型,0,1,2,3,4,非必须
311+
"phone": "13000082001"
312+
}
313+
* </pre>
266314
*/
267315
@PostMapping("post/verify")
268316
public JSONObject postVerify(@RequestBody String request) {
@@ -302,7 +350,13 @@ public JSONObject postVerify(@RequestBody String request) {
302350

303351
/**获取验证码
304352
* @param request
305-
* @return
353+
* @see
354+
* <pre>
355+
{
356+
"type": 0, //类型,0,1,2,3,4,非必须
357+
"phone": "13000082001"
358+
}
359+
* </pre>
306360
*/
307361
@PostMapping("gets/verify")
308362
public JSONObject getVerify(@RequestBody String request) {
@@ -321,7 +375,14 @@ public JSONObject getVerify(@RequestBody String request) {
321375

322376
/**校验验证码
323377
* @param request
324-
* @return
378+
* @see
379+
* <pre>
380+
{
381+
"type": 0, //类型,0,1,2,3,4,非必须
382+
"phone": "13000082001",
383+
"verify": "123456"
384+
}
385+
* </pre>
325386
*/
326387
@PostMapping("heads/verify")
327388
public JSONObject headVerify(@RequestBody String request) {

0 commit comments

Comments
 (0)