Skip to content

Commit

Permalink
Server: 新增支持热更新 远程函数、请求校验、权限校验 的配置;reload/aceess 接口改为 reload 接口,支持重载 …
Browse files Browse the repository at this point in the history
…Access, Function, Request;优化相关代码
  • Loading branch information
TommyLemon committed Jul 21, 2019
1 parent fa96a85 commit d5e130d
Show file tree
Hide file tree
Showing 6 changed files with 370 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public static void main(String[] args) throws Exception {

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

System.out.println("\n\n\n\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON >>>>>>>>>>>>>>>>>>>>>>>>\n");
System.out.println("\n\n\n\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON 开始启动 >>>>>>>>>>>>>>>>>>>>>>>>\n");

System.out.println("开始测试:远程函数 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
try {
DemoFunction.test();
Expand All @@ -57,15 +58,34 @@ public static void main(String[] args) throws Exception {
e.printStackTrace();
}
System.out.println("\n完成测试:请求校验 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");



System.out.println("\n\n\n开始初始化:远程函数配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
try {
DemoVerifier.init();
DemoFunction.init(true);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("\n完成初始化:远程函数配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

System.out.println("\n\n\n开始初始化:请求校验配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
try {
StructureUtil.init(true);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("\n完成初始化:请求校验配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

System.out.println("\n\n\n开始初始化:权限校验配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
try {
DemoVerifier.init(true);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("\n完成初始化:权限校验配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");


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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
import zuo.biao.apijson.server.exception.ConflictException;
import zuo.biao.apijson.server.exception.NotExistException;
import zuo.biao.apijson.server.exception.OutOfRangeException;
import zuo.biao.apijson.server.model.Access;
import zuo.biao.apijson.server.model.Function;
import zuo.biao.apijson.server.model.Request;


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



/**生成验证码,修改为post请求
* @param request
* @return
*/
@PostMapping("reload/access")
public JSONObject reloadAccess(@RequestBody String request) {
JSONObject requestObject = null;
String phone;
String verify;
try {
requestObject = DemoParser.parseRequest(request);
phone = requestObject.getString(PHONE);
verify = requestObject.getString(VERIFY);
} catch (Exception e) {
return DemoParser.extendErrorResult(requestObject, e);
}

JSONResponse response = new JSONResponse(headVerify(Verify.TYPE_RELOAD_ACCESS, phone, verify));
response = response.getJSONResponse(VERIFY_);
if (JSONResponse.isExist(response) == false) {
return DemoParser.extendErrorResult(requestObject, new ConditionErrorException("手机号或验证码错误"));
}

try {
DemoVerifier.init();
} catch (ServerException e) {
e.printStackTrace();
return DemoParser.extendErrorResult(requestObject, e);
}

return DemoParser.newSuccessResult();
}








public static final String FUNCTION_;
public static final String REQUEST_;
public static final String ACCESS_;

public static final String USER_;
public static final String PRIVACY_;
public static final String VERIFY_; //加下划线后缀是为了避免 Verify 和 verify 都叫VERIFY,分不清
static {
FUNCTION_ = Function.class.getSimpleName();
REQUEST_ = Request.class.getSimpleName();
ACCESS_ = Access.class.getSimpleName();

USER_ = User.class.getSimpleName();
PRIVACY_ = Privacy.class.getSimpleName();
VERIFY_ = Verify.class.getSimpleName();
Expand All @@ -258,11 +233,84 @@ public JSONObject reloadAccess(@RequestBody String request) {

public static final String TYPE = "type";



/**重新加载配置
* @param request
* @return
* @see
* <pre>
{
"type": "ALL", //重载对象,ALL, FUNCTION, REQUEST, ACCESS,非必须
"phone": "13000082001",
"verify": "1234567" //验证码,对应类型为 Verify.TYPE_RELOAD
}
* </pre>
*/
@PostMapping("reload")
public JSONObject reload(@RequestBody String request) {
JSONObject requestObject = null;
String type;
String phone;
String verify;
try {
requestObject = DemoParser.parseRequest(request);
type = requestObject.getString(TYPE);
phone = requestObject.getString(PHONE);
verify = requestObject.getString(VERIFY);
} catch (Exception e) {
return DemoParser.extendErrorResult(requestObject, e);
}

JSONResponse response = new JSONResponse(headVerify(Verify.TYPE_RELOAD, phone, verify));
response = response.getJSONResponse(VERIFY_);
if (JSONResponse.isExist(response) == false) {
return DemoParser.extendErrorResult(requestObject, new ConditionErrorException("手机号或验证码错误"));
}

JSONObject result = DemoParser.newSuccessResult();

boolean reloadAll = StringUtil.isEmpty(type, true) || "ALL".equals(type);

if (reloadAll || "FUNCTION".equals(type)) {
try {
result.put(FUNCTION_, DemoFunction.init());
} catch (ServerException e) {
e.printStackTrace();
result.put(FUNCTION_, DemoParser.newErrorResult(e));
}
}

if (reloadAll || "REQUEST".equals(type)) {
try {
result.put(REQUEST_, StructureUtil.init());
} catch (ServerException e) {
e.printStackTrace();
result.put(REQUEST_, DemoParser.newErrorResult(e));
}
}

if (reloadAll || "ACCESS".equals(type)) {
try {
result.put(ACCESS_, DemoVerifier.init());
} catch (ServerException e) {
e.printStackTrace();
result.put(ACCESS_, DemoParser.newErrorResult(e));
}
}

return result;
}

/**生成验证码,修改为post请求
* @param request
* @return
* @see
* <pre>
{
"type": 0, //类型,0,1,2,3,4,非必须
"phone": "13000082001"
}
* </pre>
*/
@PostMapping("post/verify")
public JSONObject postVerify(@RequestBody String request) {
Expand Down Expand Up @@ -302,7 +350,13 @@ public JSONObject postVerify(@RequestBody String request) {

/**获取验证码
* @param request
* @return
* @see
* <pre>
{
"type": 0, //类型,0,1,2,3,4,非必须
"phone": "13000082001"
}
* </pre>
*/
@PostMapping("gets/verify")
public JSONObject getVerify(@RequestBody String request) {
Expand All @@ -321,7 +375,14 @@ public JSONObject getVerify(@RequestBody String request) {

/**校验验证码
* @param request
* @return
* @see
* <pre>
{
"type": 0, //类型,0,1,2,3,4,非必须
"phone": "13000082001",
"verify": "123456"
}
* </pre>
*/
@PostMapping("heads/verify")
public JSONObject headVerify(@RequestBody String request) {
Expand Down
Loading

0 comments on commit d5e130d

Please sign in to comment.