Skip to content

Commit f20e3cf

Browse files
committed
Server:Parser.noVerify 改成 needVerify
1 parent 143cd08 commit f20e3cf

File tree

12 files changed

+88
-83
lines changed

12 files changed

+88
-83
lines changed

APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/boot/DemoController.java

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ public class DemoController extends APIJSONController {
105105
* @see {@link RequestMethod#GET}
106106
*/
107107
@PostMapping(value = "get")
108+
@Override
108109
public String get(@RequestBody String request, HttpSession session) {
109-
return new DemoParser(GET).setSession(session).parse(request);
110+
return super.get(request, session);
110111
}
111112

112113
/**计数
@@ -116,8 +117,9 @@ public String get(@RequestBody String request, HttpSession session) {
116117
* @see {@link RequestMethod#HEAD}
117118
*/
118119
@PostMapping("head")
120+
@Override
119121
public String head(@RequestBody String request, HttpSession session) {
120-
return new DemoParser(HEAD).setSession(session).parse(request);
122+
return super.head(request, session);
121123
}
122124

123125
/**限制性GET,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
@@ -127,8 +129,9 @@ public String head(@RequestBody String request, HttpSession session) {
127129
* @see {@link RequestMethod#GETS}
128130
*/
129131
@PostMapping("gets")
132+
@Override
130133
public String gets(@RequestBody String request, HttpSession session) {
131-
return new DemoParser(GETS).setSession(session).parse(request);
134+
return super.gets(request, session);
132135
}
133136

134137
/**限制性HEAD,request和response都非明文,浏览器看不到,用于对安全性要求高的HEAD请求
@@ -138,8 +141,9 @@ public String gets(@RequestBody String request, HttpSession session) {
138141
* @see {@link RequestMethod#HEADS}
139142
*/
140143
@PostMapping("heads")
144+
@Override
141145
public String heads(@RequestBody String request, HttpSession session) {
142-
return new DemoParser(HEADS).setSession(session).parse(request);
146+
return super.heads(request, session);
143147
}
144148

145149
/**新增
@@ -149,8 +153,9 @@ public String heads(@RequestBody String request, HttpSession session) {
149153
* @see {@link RequestMethod#POST}
150154
*/
151155
@PostMapping("post")
156+
@Override
152157
public String post(@RequestBody String request, HttpSession session) {
153-
return new DemoParser(POST).setSession(session).parse(request);
158+
return super.post(request, session);
154159
}
155160

156161
/**修改
@@ -160,8 +165,9 @@ public String post(@RequestBody String request, HttpSession session) {
160165
* @see {@link RequestMethod#PUT}
161166
*/
162167
@PostMapping("put")
168+
@Override
163169
public String put(@RequestBody String request, HttpSession session) {
164-
return new DemoParser(PUT).setSession(session).parse(request);
170+
return super.put(request, session);
165171
}
166172

167173
/**删除
@@ -171,8 +177,9 @@ public String put(@RequestBody String request, HttpSession session) {
171177
* @see {@link RequestMethod#DELETE}
172178
*/
173179
@PostMapping("delete")
180+
@Override
174181
public String delete(@RequestBody String request, HttpSession session) {
175-
return new DemoParser(DELETE).setSession(session).parse(request);
182+
return super.delete(request, session);
176183
}
177184

178185

@@ -340,9 +347,9 @@ public JSONObject postVerify(@RequestBody String request) {
340347
return DemoParser.extendErrorResult(requestObject, e);
341348
}
342349

343-
new DemoParser(DELETE, true).parse(newVerifyRequest(type, phone, null));
350+
new DemoParser(DELETE, false).parse(newVerifyRequest(type, phone, null));
344351

345-
JSONObject response = new DemoParser(POST, true).parseResponse(
352+
JSONObject response = new DemoParser(POST, false).parseResponse(
346353
newVerifyRequest(type, phone, "" + (new Random().nextInt(9999) + 1000))
347354
);
348355

@@ -352,7 +359,7 @@ public JSONObject postVerify(@RequestBody String request) {
352359
} catch (Exception e) {}
353360

354361
if (verify == null || JSONResponse.isSuccess(verify.getIntValue(JSONResponse.KEY_CODE)) == false) {
355-
new DemoParser(DELETE, true).parseResponse(new JSONRequest(new Verify(type, phone)));
362+
new DemoParser(DELETE, false).parseResponse(new JSONRequest(new Verify(type, phone)));
356363
return response;
357364
}
358365

@@ -385,7 +392,7 @@ public JSONObject getVerify(@RequestBody String request) {
385392
} catch (Exception e) {
386393
return DemoParser.extendErrorResult(requestObject, e);
387394
}
388-
return new DemoParser(GETS, true).parseResponse(newVerifyRequest(type, phone, null));
395+
return new DemoParser(GETS, false).parseResponse(newVerifyRequest(type, phone, null));
389396
}
390397

391398
/**校验验证码
@@ -425,7 +432,7 @@ public JSONObject headVerify(@RequestBody String request) {
425432
*/
426433
public JSONObject headVerify(int type, String phone, String code) {
427434
JSONResponse response = new JSONResponse(
428-
new DemoParser(GETS, true).parseResponse(
435+
new DemoParser(GETS, false).parseResponse(
429436
new JSONRequest(
430437
new Verify(type, phone)
431438
.setVerify(code)
@@ -442,14 +449,14 @@ public JSONObject headVerify(int type, String phone, String code) {
442449
long time = BaseModel.getTimeMillis(verify.getDate());
443450
long now = System.currentTimeMillis();
444451
if (now > 60*1000 + time) {
445-
new DemoParser(DELETE, true).parseResponse(
452+
new DemoParser(DELETE, false).parseResponse(
446453
new JSONRequest(new Verify(type, phone)).setTag(VERIFY_)
447454
);
448455
return DemoParser.newErrorResult(new TimeoutException("验证码已过期!"));
449456
}
450457

451458
return new JSONResponse(
452-
new DemoParser(HEADS, true).parseResponse(
459+
new DemoParser(HEADS, false).parseResponse(
453460
new JSONRequest(new Verify(type, phone).setVerify(code)).setFormat(true)
454461
)
455462
);
@@ -532,7 +539,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
532539

533540

534541
//手机号是否已注册
535-
JSONObject phoneResponse = new DemoParser(HEADS, true).parseResponse(
542+
JSONObject phoneResponse = new DemoParser(HEADS, false).parseResponse(
536543
new JSONRequest(
537544
new Privacy().setPhone(phone)
538545
)
@@ -546,7 +553,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
546553
}
547554

548555
//根据phone获取User
549-
JSONObject privacyResponse = new DemoParser(GETS, true).parseResponse(
556+
JSONObject privacyResponse = new DemoParser(GETS, false).parseResponse(
550557
new JSONRequest(
551558
new Privacy().setPhone(phone)
552559
).setFormat(true)
@@ -562,7 +569,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
562569
//校验凭证
563570
if (isPassword) {//password密码登录
564571
response = new JSONResponse(
565-
new DemoParser(HEADS, true).parseResponse(
572+
new DemoParser(HEADS, false).parseResponse(
566573
new JSONRequest(new Privacy(userId).setPassword(password))
567574
)
568575
);
@@ -578,7 +585,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
578585
}
579586

580587
response = new JSONResponse(
581-
new DemoParser(GETS, true).parseResponse(
588+
new DemoParser(GETS, false).parseResponse(
582589
new JSONRequest(new User(userId)).setFormat(true)
583590
)
584591
);
@@ -693,7 +700,7 @@ public JSONObject register(@RequestBody String request) {
693700
}
694701
requestObject.put(JSONRequest.KEY_FORMAT, true);
695702
response = new JSONResponse(
696-
new DemoParser(POST).setNoVerifyLogin(true).parseResponse(requestObject)
703+
new DemoParser(POST).setNeedVerifyLogin(false).parseResponse(requestObject)
697704
);
698705

699706
//验证User和Privacy
@@ -707,10 +714,10 @@ public JSONObject register(@RequestBody String request) {
707714
}
708715

709716
if (e != null) { //出现错误,回退
710-
new DemoParser(DELETE, true).parseResponse(
717+
new DemoParser(DELETE, false).parseResponse(
711718
new JSONRequest(new User(userId))
712719
);
713-
new DemoParser(DELETE, true).parseResponse(
720+
new DemoParser(DELETE, false).parseResponse(
714721
new JSONRequest(new Privacy(userId2))
715722
);
716723
}
@@ -822,7 +829,7 @@ public JSONObject putPassword(@RequestBody String request){
822829
privacy.setPayPassword(oldPassword);
823830
}
824831
JSONResponse response = new JSONResponse(
825-
new DemoParser(HEAD, true).parseResponse(
832+
new DemoParser(HEAD, false).parseResponse(
826833
new JSONRequest(privacy).setFormat(true)
827834
)
828835
);
@@ -839,7 +846,7 @@ else if (StringUtil.isPhone(phone) && StringUtil.isVerify(verify)) {
839846
return DemoParser.extendErrorResult(response, new ConditionErrorException("手机号或验证码错误!"));
840847
}
841848
response = new JSONResponse(
842-
new DemoParser(GET, true).parseResponse(
849+
new DemoParser(GET, false).parseResponse(
843850
new JSONRequest(
844851
new Privacy().setPhone(phone)
845852
)
@@ -860,7 +867,7 @@ else if (StringUtil.isPhone(phone) && StringUtil.isVerify(verify)) {
860867
// requestObject.put(JSONRequest.KEY_TAG, "Password");
861868
requestObject.put(JSONRequest.KEY_FORMAT, true);
862869
//修改密码
863-
return new DemoParser(PUT, true).parseResponse(requestObject);
870+
return new DemoParser(PUT, false).parseResponse(requestObject);
864871
}
865872

866873

@@ -913,7 +920,7 @@ public JSONObject putBalance(@RequestBody String request, HttpSession session) {
913920

914921
privacyObj.remove("balance+");
915922
JSONResponse response = new JSONResponse(
916-
new DemoParser(HEADS, true).setSession(session).parseResponse(
923+
new DemoParser(HEADS, false).setSession(session).parseResponse(
917924
new JSONRequest(PRIVACY_, privacyObj)
918925
)
919926
);
@@ -938,7 +945,7 @@ public JSONObject putBalance(@RequestBody String request, HttpSession session) {
938945

939946
if (change < 0) {//提现
940947
response = new JSONResponse(
941-
new DemoParser(GETS, true).parseResponse(
948+
new DemoParser(GETS, false).parseResponse(
942949
new JSONRequest(
943950
new Privacy(userId)
944951
)

APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/boot/DemoFunctionParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public int deleteCommentOfMoment(@NotNull JSONObject rq, @NotNull String momentI
110110
request.put("Comment", comment);
111111
//Comment>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
112112

113-
JSONObject rp = new DemoParser(RequestMethod.DELETE).setNoVerify(true).parseResponse(request);
113+
JSONObject rp = new DemoParser(RequestMethod.DELETE).setNeedVerify(false).parseResponse(request);
114114

115115
JSONObject c = rp.getJSONObject("Comment");
116116
return c == null ? 0 : c.getIntValue(JSONResponse.KEY_COUNT);
@@ -139,7 +139,7 @@ public int deleteChildComment(@NotNull JSONObject rq, @NotNull String toId) thro
139139
request.put("Comment", comment);
140140
//Comment>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
141141

142-
JSONObject rp = new DemoParser(RequestMethod.DELETE).setNoVerify(true).parseResponse(request);
142+
JSONObject rp = new DemoParser(RequestMethod.DELETE).setNeedVerify(false).parseResponse(request);
143143

144144
JSONObject c = rp.getJSONObject("Comment");
145145
return c == null ? 0 : c.getIntValue(JSONResponse.KEY_COUNT);
@@ -165,7 +165,7 @@ private JSONArray getChildCommentIdList(long tid) {
165165
request.putAll(idItem.toArray(0, 0, "Comment-id"));
166166
//Comment-id[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
167167

168-
JSONObject rp = new DemoParser().setNoVerify(true).parseResponse(request);
168+
JSONObject rp = new DemoParser().setNeedVerify(false).parseResponse(request);
169169

170170
JSONArray a = rp.getJSONArray("Comment-id[]");
171171
if (a != null) {

APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/boot/DemoParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public DemoParser() {
2929
public DemoParser(RequestMethod method) {
3030
super(method);
3131
}
32-
public DemoParser(RequestMethod method, boolean noVerify) {
33-
super(method, noVerify);
32+
public DemoParser(RequestMethod method, boolean needVerify) {
33+
super(method, needVerify);
3434
}
3535

3636
// //可重写来设置最大查询数量

APIJSON-Java-Server/APIJSONBootTest/src/main/java/apijson/boot/test/DemoController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ public class DemoController extends APIJSONController {
3636

3737
@Override
3838
public Parser<Long> newParser(HttpSession session, RequestMethod method) {
39-
return super.newParser(session, method).setNoVerify(true);
39+
return super.newParser(session, method).setNeedVerify(false); //TODO 这里关闭校验,方便新手快速测试,实际线上项目建议开启
4040
}
4141

4242
@PostMapping(value = "get")
43+
@Override
4344
public String get(@RequestBody String request, HttpSession session) {
4445
return super.get(request, session);
4546
}

APIJSON-Java-Server/APIJSONBootTest/src/main/java/apijson/boot/test/DemoSQLConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public class DemoSQLConfig extends APIJSONSQLConfig {
2626
static {
2727
DEFAULT_DATABASE = DATABASE_MYSQL; //TODO 默认数据库类型,改成你自己的
2828
DEFAULT_SCHEMA = "sys"; //TODO 默认模式名,改成你自己的,默认情况是 MySQL: sys, PostgreSQL: public, SQL Server: dbo, Oracle:
29+
30+
//表名和数据库不一致的,需要配置映射关系
31+
TABLE_KEY_MAP.put("User", "apijson_user");
32+
TABLE_KEY_MAP.put("Privacy", "apijson_privacy");
2933
}
3034

3135
@Override

APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/APIJSONFunctionParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static JSONObject init(boolean shutdownWhenServerError, ParserCreator<Lon
126126
creator = APIJSONApplication.DEFAULT_APIJSON_CREATOR;
127127
}
128128

129-
JSONObject response = creator.createParser().setMethod(RequestMethod.GET).setNoVerify(true).parseResponse(request);
129+
JSONObject response = creator.createParser().setMethod(RequestMethod.GET).setNeedVerify(true).parseResponse(request);
130130
if (JSONResponse.isSuccess(response) == false) {
131131
onServerError("\n\n\n\n\n !!!! 查询远程函数异常 !!!\n" + response.getString(JSONResponse.KEY_MSG) + "\n\n\n\n\n", shutdownWhenServerError);
132132
}
@@ -160,7 +160,7 @@ public static JSONObject init(boolean shutdownWhenServerError, ParserCreator<Lon
160160
String[] methods = StringUtil.split(item.getString("methods"));
161161
JSONObject r = new APIJSONParser(
162162
methods == null || methods.length <= 0 ? RequestMethod.GET : RequestMethod.valueOf(methods[0])
163-
, true
163+
, false
164164
)
165165
.setTag(item.getString(JSONRequest.KEY_TAG))
166166
.setVersion(item.getIntValue(JSONRequest.KEY_VERSION))

APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/APIJSONParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public APIJSONParser() {
4646
public APIJSONParser(RequestMethod method) {
4747
super(method);
4848
}
49-
public APIJSONParser(RequestMethod method, boolean noVerify) {
50-
super(method, noVerify);
49+
public APIJSONParser(RequestMethod method, boolean needVerify) {
50+
super(method, needVerify);
5151
}
5252

5353
private HttpSession session;

APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/APIJSONVerifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static JSONObject init(boolean shutdownWhenServerError, ParserCreator<Lon
104104
creator = APIJSONApplication.DEFAULT_APIJSON_CREATOR;
105105
}
106106

107-
JSONObject response = creator.createParser().setMethod(RequestMethod.GET).setNoVerify(true).parseResponse(request);
107+
JSONObject response = creator.createParser().setMethod(RequestMethod.GET).setNeedVerify(false).parseResponse(request);
108108
if (JSONResponse.isSuccess(response) == false) {
109109
Log.e(TAG, "\n\n\n\n\n !!!! 查询权限配置异常 !!!\n" + response.getString(JSONResponse.KEY_MSG) + "\n\n\n\n\n");
110110
onServerError("查询权限配置异常 !", shutdownWhenServerError);

APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/StructureUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static JSONObject init(boolean shutdownWhenServerError, ParserCreator<Lon
9191
creator = APIJSONApplication.DEFAULT_APIJSON_CREATOR;
9292
}
9393

94-
JSONObject response = creator.createParser().setMethod(RequestMethod.GET).setNoVerify(true).parseResponse(request);
94+
JSONObject response = creator.createParser().setMethod(RequestMethod.GET).setNeedVerify(false).parseResponse(request);
9595
if (JSONResponse.isSuccess(response) == false) {
9696
Log.e(TAG, "\n\n\n\n\n !!!! 查询权限配置异常 !!!\n" + response.getString(JSONResponse.KEY_MSG) + "\n\n\n\n\n");
9797
onServerError("查询权限配置异常 !", shutdownWhenServerError);

0 commit comments

Comments
 (0)