新增验证码,完成注册
This commit is contained in:
parent
1db30b941a
commit
18d51dd1cb
@ -14,12 +14,19 @@ limitations under the License.*/
|
||||
|
||||
package zuo.biao.apijson.server;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
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
|
||||
* @author Lemon
|
||||
*/
|
||||
@ -48,7 +55,7 @@ public class Controller {
|
||||
|
||||
/**以下接口继续用POST接口是为了客户端方便,只需要做get,post请求。也可以改用实际对应的方法。
|
||||
* post,put方法名可以改为add,update等更客户端容易懂的名称
|
||||
*/
|
||||
*/
|
||||
@RequestMapping(value="put", method = RequestMethod.POST)
|
||||
public String put(@RequestBody String request) {
|
||||
return new RequestParser(zuo.biao.apijson.RequestMethod.PUT).parse(request);
|
||||
@ -59,4 +66,59 @@ public class Controller {
|
||||
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,12 +230,11 @@ public class QueryConfig {
|
||||
* @return in ('key0', 'key1', ... )
|
||||
*/
|
||||
public static String getInString(Object[] in) {
|
||||
if (in == null || in.length <= 0) {
|
||||
return "";
|
||||
}
|
||||
String inString = "";
|
||||
for (int i = 0; i < in.length; i++) {
|
||||
inString += ((i > 0 ? "," : "") + "'" + in[i] + "'");
|
||||
if (in != null) {//返回 "" 会导致 id:[] 空值时效果和没有筛选id一样!
|
||||
for (int i = 0; i < in.length; i++) {
|
||||
inString += ((i > 0 ? "," : "") + "'" + in[i] + "'");
|
||||
}
|
||||
}
|
||||
return " in (" + inString + ") ";
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ public class RequestParser {
|
||||
private boolean parseRelation;
|
||||
private Map<String, String> relationMap;
|
||||
|
||||
|
||||
/**解析请求json并获取对应结果
|
||||
* @param request
|
||||
* @return
|
||||
@ -67,6 +68,20 @@ public class RequestParser {
|
||||
|
||||
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并获取对应结果
|
||||
* @param request
|
||||
* @return requestObject
|
||||
|
@ -47,6 +47,7 @@ public class AccessVerifier {
|
||||
accessMap.put("Password", new RequestMethod[]{POST_GET, POST, PUT, DELETE});
|
||||
accessMap.put("Login", new RequestMethod[]{POST_GET, POST, DELETE});
|
||||
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 + "方法!");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user