新增验证码,完成注册
This commit is contained in:
parent
1db30b941a
commit
18d51dd1cb
@ -14,12 +14,19 @@ limitations under the License.*/
|
|||||||
|
|
||||||
package zuo.biao.apijson.server;
|
package zuo.biao.apijson.server;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
import zuo.biao.apijson.JSON;
|
||||||
|
import zuo.biao.apijson.StringUtil;
|
||||||
|
|
||||||
/**request receiver and controller
|
/**request receiver and controller
|
||||||
* @author Lemon
|
* @author Lemon
|
||||||
*/
|
*/
|
||||||
@ -31,7 +38,7 @@ public class Controller {
|
|||||||
public String get(@PathVariable String request) {
|
public String get(@PathVariable String request) {
|
||||||
return new RequestParser(zuo.biao.apijson.RequestMethod.GET).parse(request);
|
return new RequestParser(zuo.biao.apijson.RequestMethod.GET).parse(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**用POST方法GET数据,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
|
/**用POST方法GET数据,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
|
||||||
* @param request
|
* @param request
|
||||||
* @return
|
* @return
|
||||||
@ -40,23 +47,78 @@ public class Controller {
|
|||||||
public String post_get(@RequestBody String request) {
|
public String post_get(@RequestBody String request) {
|
||||||
return new RequestParser(zuo.biao.apijson.RequestMethod.POST_GET).parse(request);
|
return new RequestParser(zuo.biao.apijson.RequestMethod.POST_GET).parse(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value="post", method = RequestMethod.POST)
|
@RequestMapping(value="post", method = RequestMethod.POST)
|
||||||
public String post(@RequestBody String request) {
|
public String post(@RequestBody String request) {
|
||||||
return new RequestParser(zuo.biao.apijson.RequestMethod.POST).parse(request);
|
return new RequestParser(zuo.biao.apijson.RequestMethod.POST).parse(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**以下接口继续用POST接口是为了客户端方便,只需要做get,post请求。也可以改用实际对应的方法。
|
/**以下接口继续用POST接口是为了客户端方便,只需要做get,post请求。也可以改用实际对应的方法。
|
||||||
* post,put方法名可以改为add,update等更客户端容易懂的名称
|
* post,put方法名可以改为add,update等更客户端容易懂的名称
|
||||||
*/
|
*/
|
||||||
@RequestMapping(value="put", method = RequestMethod.POST)
|
@RequestMapping(value="put", method = RequestMethod.POST)
|
||||||
public String put(@RequestBody String request) {
|
public String put(@RequestBody String request) {
|
||||||
return new RequestParser(zuo.biao.apijson.RequestMethod.PUT).parse(request);
|
return new RequestParser(zuo.biao.apijson.RequestMethod.PUT).parse(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value="delete", method = RequestMethod.POST)
|
@RequestMapping(value="delete", method = RequestMethod.POST)
|
||||||
public String delete(@RequestBody String request) {
|
public String delete(@RequestBody String request) {
|
||||||
return new RequestParser(zuo.biao.apijson.RequestMethod.DELETE).parse(request);
|
return new RequestParser(zuo.biao.apijson.RequestMethod.DELETE).parse(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping("post/authCode/{phone}")
|
||||||
|
public String postAuthCode(@PathVariable String phone) {
|
||||||
|
new RequestParser(zuo.biao.apijson.RequestMethod.DELETE).parse(newVerifyRequest(newVerify(phone, 0)));
|
||||||
|
|
||||||
|
JSONObject response = new RequestParser(zuo.biao.apijson.RequestMethod.POST).parseResponse(
|
||||||
|
newVerifyRequest(newVerify(phone, new Random().nextInt(9999) + 1000)));
|
||||||
|
|
||||||
|
JSONObject verify = null;
|
||||||
|
try {
|
||||||
|
verify = response.getJSONObject("Verify");
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO: handle exception
|
||||||
|
}
|
||||||
|
if (verify == null || verify.getIntValue("status") != 200) {
|
||||||
|
return JSON.toJSONString(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
return getAuthCode(phone);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value="post_get/authCode/{phone}", method = RequestMethod.POST)
|
||||||
|
public String getAuthCode(@PathVariable String phone) {
|
||||||
|
return new RequestParser(zuo.biao.apijson.RequestMethod.POST_GET).parse(newVerifyRequest(newVerify(phone, 0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("check/authCode/{phone}/{code}")
|
||||||
|
public String checkAuthCode(@PathVariable String phone, @PathVariable String code) {
|
||||||
|
if (StringUtil.isNumer(code) == false) {
|
||||||
|
code = "-1";
|
||||||
|
}
|
||||||
|
return new RequestParser(zuo.biao.apijson.RequestMethod.POST_GET).parse(
|
||||||
|
newVerifyRequest(newVerify(phone, Integer.parseInt(0 + StringUtil.getNumber(code)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
private JSONObject newVerify(String phone, int code) {
|
||||||
|
JSONObject verify = new JSONObject(true);
|
||||||
|
verify.put("id", phone);
|
||||||
|
if (code > 0) {
|
||||||
|
verify.put("code", code);
|
||||||
|
}
|
||||||
|
return verify;
|
||||||
|
}
|
||||||
|
private JSONObject newVerifyRequest(JSONObject verify) {
|
||||||
|
return newRequest(verify, "Verify", true);
|
||||||
|
}
|
||||||
|
private JSONObject newRequest(JSONObject object, String name, boolean needTag) {
|
||||||
|
JSONObject request = new JSONObject(true);
|
||||||
|
request.put(name, object);
|
||||||
|
if (needTag) {
|
||||||
|
request.put("tag", name);
|
||||||
|
}
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -230,17 +230,16 @@ public class QueryConfig {
|
|||||||
* @return in ('key0', 'key1', ... )
|
* @return in ('key0', 'key1', ... )
|
||||||
*/
|
*/
|
||||||
public static String getInString(Object[] in) {
|
public static String getInString(Object[] in) {
|
||||||
if (in == null || in.length <= 0) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String inString = "";
|
String inString = "";
|
||||||
for (int i = 0; i < in.length; i++) {
|
if (in != null) {//返回 "" 会导致 id:[] 空值时效果和没有筛选id一样!
|
||||||
inString += ((i > 0 ? "," : "") + "'" + in[i] + "'");
|
for (int i = 0; i < in.length; i++) {
|
||||||
|
inString += ((i > 0 ? "," : "") + "'" + in[i] + "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return " in (" + inString + ") ";
|
return " in (" + inString + ") ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**获取筛选方法
|
/**获取筛选方法
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -55,6 +55,7 @@ public class RequestParser {
|
|||||||
private boolean parseRelation;
|
private boolean parseRelation;
|
||||||
private Map<String, String> relationMap;
|
private Map<String, String> relationMap;
|
||||||
|
|
||||||
|
|
||||||
/**解析请求json并获取对应结果
|
/**解析请求json并获取对应结果
|
||||||
* @param request
|
* @param request
|
||||||
* @return
|
* @return
|
||||||
@ -67,6 +68,20 @@ public class RequestParser {
|
|||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
/**解析请求json并获取对应结果
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String parse(JSONObject request) {
|
||||||
|
return JSON.toJSONString(parseResponse(request));
|
||||||
|
}
|
||||||
|
/**解析请求json并获取对应结果
|
||||||
|
* @param request
|
||||||
|
* @return requestObject
|
||||||
|
*/
|
||||||
|
public JSONObject parseResponse(JSONObject request) {
|
||||||
|
return parseResponse(JSON.toJSONString(request));
|
||||||
|
}
|
||||||
/**解析请求json并获取对应结果
|
/**解析请求json并获取对应结果
|
||||||
* @param request
|
* @param request
|
||||||
* @return requestObject
|
* @return requestObject
|
||||||
@ -395,7 +410,7 @@ public class RequestParser {
|
|||||||
}
|
}
|
||||||
} else {//JSONArray或其它Object,直接填充
|
} else {//JSONArray或其它Object,直接填充
|
||||||
transferredRequest.put(key, value);
|
transferredRequest.put(key, value);
|
||||||
|
|
||||||
//替换path
|
//替换path
|
||||||
if (value instanceof String && StringUtil.isPath((String) value)) {
|
if (value instanceof String && StringUtil.isPath((String) value)) {
|
||||||
System.out.println("getObject StringUtil.isPath(value) >> parseRelation = " + parseRelation);
|
System.out.println("getObject StringUtil.isPath(value) >> parseRelation = " + parseRelation);
|
||||||
|
@ -47,6 +47,7 @@ public class AccessVerifier {
|
|||||||
accessMap.put("Password", new RequestMethod[]{POST_GET, POST, PUT, DELETE});
|
accessMap.put("Password", new RequestMethod[]{POST_GET, POST, PUT, DELETE});
|
||||||
accessMap.put("Login", new RequestMethod[]{POST_GET, POST, DELETE});
|
accessMap.put("Login", new RequestMethod[]{POST_GET, POST, DELETE});
|
||||||
accessMap.put("Request", new RequestMethod[]{GET, POST_GET});
|
accessMap.put("Request", new RequestMethod[]{GET, POST_GET});
|
||||||
|
accessMap.put("Verify", new RequestMethod[]{POST_GET, POST, DELETE});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**验证权限是否通过
|
/**验证权限是否通过
|
||||||
@ -236,4 +237,5 @@ public class AccessVerifier {
|
|||||||
throw new AccessException(table + "不支持" + method + "方法!");
|
throw new AccessException(table + "不支持" + method + "方法!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user