Skip to content

Commit a56ad31

Browse files
committed
同步eclipse版至idea版
1 parent 18d51dd commit a56ad31

4 files changed

Lines changed: 91 additions & 13 deletions

File tree

‎APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/server/Controller.java‎

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414

1515
package zuo.biao.apijson.server;
1616

17+
import java.util.Random;
18+
1719
import org.springframework.web.bind.annotation.PathVariable;
1820
import org.springframework.web.bind.annotation.RequestBody;
1921
import org.springframework.web.bind.annotation.RequestMapping;
2022
import org.springframework.web.bind.annotation.RequestMethod;
2123
import org.springframework.web.bind.annotation.RestController;
2224

25+
import com.alibaba.fastjson.JSONObject;
26+
27+
import zuo.biao.apijson.JSON;
28+
import zuo.biao.apijson.StringUtil;
29+
2330
/**request receiver and controller
2431
* @author Lemon
2532
*/
@@ -31,7 +38,7 @@ public class Controller {
3138
public String get(@PathVariable String request) {
3239
return new RequestParser(zuo.biao.apijson.RequestMethod.GET).parse(request);
3340
}
34-
41+
3542
/**用POST方法GET数据,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
3643
* @param request
3744
* @return
@@ -40,23 +47,78 @@ public String get(@PathVariable String request) {
4047
public String post_get(@RequestBody String request) {
4148
return new RequestParser(zuo.biao.apijson.RequestMethod.POST_GET).parse(request);
4249
}
43-
50+
4451
@RequestMapping(value="post", method = RequestMethod.POST)
4552
public String post(@RequestBody String request) {
4653
return new RequestParser(zuo.biao.apijson.RequestMethod.POST).parse(request);
4754
}
48-
55+
4956
/**以下接口继续用POST接口是为了客户端方便,只需要做get,post请求。也可以改用实际对应的方法。
5057
* post,put方法名可以改为add,update等更客户端容易懂的名称
51-
*/
58+
*/
5259
@RequestMapping(value="put", method = RequestMethod.POST)
5360
public String put(@RequestBody String request) {
5461
return new RequestParser(zuo.biao.apijson.RequestMethod.PUT).parse(request);
5562
}
56-
63+
5764
@RequestMapping(value="delete", method = RequestMethod.POST)
5865
public String delete(@RequestBody String request) {
5966
return new RequestParser(zuo.biao.apijson.RequestMethod.DELETE).parse(request);
6067
}
6168

69+
70+
@RequestMapping("post/authCode/{phone}")
71+
public String postAuthCode(@PathVariable String phone) {
72+
new RequestParser(zuo.biao.apijson.RequestMethod.DELETE).parse(newVerifyRequest(newVerify(phone, 0)));
73+
74+
JSONObject response = new RequestParser(zuo.biao.apijson.RequestMethod.POST).parseResponse(
75+
newVerifyRequest(newVerify(phone, new Random().nextInt(9999) + 1000)));
76+
77+
JSONObject verify = null;
78+
try {
79+
verify = response.getJSONObject("Verify");
80+
} catch (Exception e) {
81+
// TODO: handle exception
82+
}
83+
if (verify == null || verify.getIntValue("status") != 200) {
84+
return JSON.toJSONString(response);
85+
}
86+
87+
return getAuthCode(phone);
88+
}
89+
90+
@RequestMapping(value="post_get/authCode/{phone}", method = RequestMethod.POST)
91+
public String getAuthCode(@PathVariable String phone) {
92+
return new RequestParser(zuo.biao.apijson.RequestMethod.POST_GET).parse(newVerifyRequest(newVerify(phone, 0)));
93+
}
94+
95+
@RequestMapping("check/authCode/{phone}/{code}")
96+
public String checkAuthCode(@PathVariable String phone, @PathVariable String code) {
97+
if (StringUtil.isNumer(code) == false) {
98+
code = "-1";
99+
}
100+
return new RequestParser(zuo.biao.apijson.RequestMethod.POST_GET).parse(
101+
newVerifyRequest(newVerify(phone, Integer.parseInt(0 + StringUtil.getNumber(code)))));
102+
}
103+
104+
private JSONObject newVerify(String phone, int code) {
105+
JSONObject verify = new JSONObject(true);
106+
verify.put("id", phone);
107+
if (code > 0) {
108+
verify.put("code", code);
109+
}
110+
return verify;
111+
}
112+
private JSONObject newVerifyRequest(JSONObject verify) {
113+
return newRequest(verify, "Verify", true);
114+
}
115+
private JSONObject newRequest(JSONObject object, String name, boolean needTag) {
116+
JSONObject request = new JSONObject(true);
117+
request.put(name, object);
118+
if (needTag) {
119+
request.put("tag", name);
120+
}
121+
return request;
122+
}
123+
62124
}

‎APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/server/QueryConfig.java‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,16 @@ public static String getWhereString(RequestMethod method, Map<String, Object> wh
230230
* @return in ('key0', 'key1', ... )
231231
*/
232232
public static String getInString(Object[] in) {
233-
if (in == null || in.length <= 0) {
234-
return "";
235-
}
236233
String inString = "";
237-
for (int i = 0; i < in.length; i++) {
238-
inString += ((i > 0 ? "," : "") + "'" + in[i] + "'");
234+
if (in != null) {//返回 "" 会导致 id:[] 空值时效果和没有筛选id一样!
235+
for (int i = 0; i < in.length; i++) {
236+
inString += ((i > 0 ? "," : "") + "'" + in[i] + "'");
237+
}
239238
}
240239
return " in (" + inString + ") ";
241240
}
242-
243-
241+
242+
244243
/**获取筛选方法
245244
* @return
246245
*/

‎APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/server/RequestParser.java‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public RequestParser(RequestMethod requestMethod) {
5555
private boolean parseRelation;
5656
private Map<String, String> relationMap;
5757

58+
5859
/**解析请求json并获取对应结果
5960
* @param request
6061
* @return
@@ -67,6 +68,20 @@ public String parse(String request) {
6768

6869
return response;
6970
}
71+
/**解析请求json并获取对应结果
72+
* @param request
73+
* @return
74+
*/
75+
public String parse(JSONObject request) {
76+
return JSON.toJSONString(parseResponse(request));
77+
}
78+
/**解析请求json并获取对应结果
79+
* @param request
80+
* @return requestObject
81+
*/
82+
public JSONObject parseResponse(JSONObject request) {
83+
return parseResponse(JSON.toJSONString(request));
84+
}
7085
/**解析请求json并获取对应结果
7186
* @param request
7287
* @return requestObject
@@ -395,7 +410,7 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
395410
}
396411
} else {//JSONArray或其它Object,直接填充
397412
transferredRequest.put(key, value);
398-
413+
399414
//替换path
400415
if (value instanceof String && StringUtil.isPath((String) value)) {
401416
System.out.println("getObject StringUtil.isPath(value) >> parseRelation = " + parseRelation);

‎APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/server/sql/AccessVerifier.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static void init() {
4747
accessMap.put("Password", new RequestMethod[]{POST_GET, POST, PUT, DELETE});
4848
accessMap.put("Login", new RequestMethod[]{POST_GET, POST, DELETE});
4949
accessMap.put("Request", new RequestMethod[]{GET, POST_GET});
50+
accessMap.put("Verify", new RequestMethod[]{POST_GET, POST, DELETE});
5051
}
5152

5253
/**验证权限是否通过
@@ -236,4 +237,5 @@ public static boolean verifyMethod(String table, RequestMethod method) throws Ac
236237
throw new AccessException(table + "不支持" + method + "方法!");
237238
}
238239

240+
239241
}

0 commit comments

Comments
 (0)