根据数字大小生成验证码的核心代码编写

main
topsun 2 years ago
parent 218ffb3122
commit fb32df755d

@ -13,12 +13,17 @@ public class NumberCodeController {
public String numberCode(@PathVariable("size") int size){ public String numberCode(@PathVariable("size") int size){
System.out.println("size:"+size); System.out.println("size:"+size);
//获取随机数
double mathRandom =( Math.random()*9 + 1) * (Math.pow(10,size -1));
int numberCode = (int) mathRandom;
JSONObject resultObj = new JSONObject(); JSONObject resultObj = new JSONObject();
resultObj.put("code",1); resultObj.put("code",1);
resultObj.put("message","success"); resultObj.put("message","success");
JSONObject jsonObjectData = new JSONObject(); JSONObject jsonObjectData = new JSONObject();
jsonObjectData.put("numberCode",123456); jsonObjectData.put("numberCode",numberCode);
resultObj.put("data",jsonObjectData); resultObj.put("data",jsonObjectData);
return resultObj.toString(); return resultObj.toString();
} }
} }

Loading…
Cancel
Save