|
|
@@ -1,7 +1,10 @@
|
|
|
package com.uas.platform.b2b.model;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import javax.persistence.Entity;
|
|
|
import javax.persistence.GeneratedValue;
|
|
|
@@ -28,6 +31,8 @@ public class Token implements Serializable{
|
|
|
|
|
|
private Date time;
|
|
|
|
|
|
+ private String code;
|
|
|
+
|
|
|
public Token() {
|
|
|
this.time = new Date();
|
|
|
}
|
|
|
@@ -36,12 +41,16 @@ public class Token implements Serializable{
|
|
|
this();
|
|
|
this.userType = type.toLowerCase();
|
|
|
this.uu = uu;
|
|
|
+ if("mobile".equals(this.userType))
|
|
|
+ this.code = randomCode();
|
|
|
}
|
|
|
|
|
|
public Token(UserType type, Long uu) {
|
|
|
this();
|
|
|
this.userType = type.toString();
|
|
|
this.uu = uu;
|
|
|
+ if("mobile".equals(this.userType))
|
|
|
+ this.code = randomCode();
|
|
|
}
|
|
|
|
|
|
public Long getId() {
|
|
|
@@ -76,6 +85,14 @@ public class Token implements Serializable{
|
|
|
this.time = time;
|
|
|
}
|
|
|
|
|
|
+ public String getCode() {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCode(String code) {
|
|
|
+ this.code = code;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 24小时超时
|
|
|
*
|
|
|
@@ -86,6 +103,23 @@ public class Token implements Serializable{
|
|
|
}
|
|
|
|
|
|
public enum UserType {
|
|
|
- enterprise, user;
|
|
|
+ enterprise, user, mobile;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成6位数字的随机验证码
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String randomCode(){
|
|
|
+ String[] beforeShuffle = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
|
|
+ List<String> list = Arrays.asList(beforeShuffle);
|
|
|
+ Collections.shuffle(list);
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ sb.append(list.get(i));
|
|
|
+ }
|
|
|
+ String afterShuffle = sb.toString();
|
|
|
+ String result = afterShuffle.substring(3, 9);
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|