|
@@ -19,8 +19,6 @@ import org.springframework.util.StringUtils;
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.security.MessageDigest;
|
|
import java.security.MessageDigest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
-import java.text.DateFormat;
|
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -147,17 +145,19 @@ public class AuthService {
|
|
|
private final String username;
|
|
private final String username;
|
|
|
private final String password;
|
|
private final String password;
|
|
|
private final Integer serviceId;
|
|
private final Integer serviceId;
|
|
|
|
|
+ private final String telephone;
|
|
|
|
|
|
|
|
- public Account(String username, String password, Integer serviceId) {
|
|
|
|
|
|
|
+ public Account(String username, String password, Integer serviceId,String telephone) {
|
|
|
if (username == null || password == null || username.isEmpty() || password.isEmpty()) {
|
|
if (username == null || password == null || username.isEmpty() || password.isEmpty()) {
|
|
|
throw new IllegalArgumentException("缺失必要参数");
|
|
throw new IllegalArgumentException("缺失必要参数");
|
|
|
}
|
|
}
|
|
|
this.username = username;
|
|
this.username = username;
|
|
|
this.password = password;
|
|
this.password = password;
|
|
|
this.serviceId = serviceId;
|
|
this.serviceId = serviceId;
|
|
|
|
|
+ this.telephone = telephone;
|
|
|
}
|
|
}
|
|
|
public Account(String username, String password) {
|
|
public Account(String username, String password) {
|
|
|
- this(username, password, null);
|
|
|
|
|
|
|
+ this(username, password, null,null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -309,7 +309,7 @@ public class AuthService {
|
|
|
public String logOrRegPhoneAccount(String phone, String code) {
|
|
public String logOrRegPhoneAccount(String phone, String code) {
|
|
|
PhoneService.Result result = phoneService.login(phone, code);
|
|
PhoneService.Result result = phoneService.login(phone, code);
|
|
|
if (result.isSuccess()) {
|
|
if (result.isSuccess()) {
|
|
|
- return logOrReg(generateAccount(result.getPhone(), PHONE_NAME_PREFIX, PHONE_PASSWORD_PREFIX, PHONE_SALT));
|
|
|
|
|
|
|
+ return logOrReg(generateAccount(result.getPhone(), PHONE_NAME_PREFIX, PHONE_PASSWORD_PREFIX, PHONE_SALT,result.getPhone()));
|
|
|
} else {
|
|
} else {
|
|
|
return MessageManage.getInstance().getResultContent(-1, result.getError(), result.getError());
|
|
return MessageManage.getInstance().getResultContent(-1, result.getError(), result.getError());
|
|
|
}
|
|
}
|
|
@@ -325,7 +325,7 @@ public class AuthService {
|
|
|
public String logOrRegWeChatPhoneAccount(String jsCode) {
|
|
public String logOrRegWeChatPhoneAccount(String jsCode) {
|
|
|
WeChatService.PhoneResult result = weChatService.wxPhoneLogin(jsCode);
|
|
WeChatService.PhoneResult result = weChatService.wxPhoneLogin(jsCode);
|
|
|
if (result.isSuccess()) {
|
|
if (result.isSuccess()) {
|
|
|
- return logOrReg(generateAccount(result.getPhone(), PHONE_NAME_PREFIX, PHONE_PASSWORD_PREFIX, PHONE_SALT));
|
|
|
|
|
|
|
+ return logOrReg(generateAccount(result.getPhone(), PHONE_NAME_PREFIX, PHONE_PASSWORD_PREFIX, PHONE_SALT,result.getPhone()));
|
|
|
} else {
|
|
} else {
|
|
|
return MessageManage.getInstance().getResultContent(-1, result.getError(), result.getError());
|
|
return MessageManage.getInstance().getResultContent(-1, result.getError(), result.getError());
|
|
|
}
|
|
}
|
|
@@ -461,7 +461,7 @@ public class AuthService {
|
|
|
/**
|
|
/**
|
|
|
* 初始化用户数据
|
|
* 初始化用户数据
|
|
|
*/
|
|
*/
|
|
|
- private boolean initUser(JSONObject userJSON) {
|
|
|
|
|
|
|
+ private boolean initUser(JSONObject userJSON, Account account) {
|
|
|
boolean allSuccess = true;
|
|
boolean allSuccess = true;
|
|
|
JSONObject userContent = userJSON.getJSONObject(RESPONSE_FIELD_CONTENT);
|
|
JSONObject userContent = userJSON.getJSONObject(RESPONSE_FIELD_CONTENT);
|
|
|
String usercode = userContent.getString(RESPONSE_FIELD_USERNAME);
|
|
String usercode = userContent.getString(RESPONSE_FIELD_USERNAME);
|
|
@@ -473,6 +473,8 @@ public class AuthService {
|
|
|
User user = new User();
|
|
User user = new User();
|
|
|
user.setCUsercode(usercode);
|
|
user.setCUsercode(usercode);
|
|
|
user.setCUserStatus("1");
|
|
user.setCUserStatus("1");
|
|
|
|
|
+ user.setCType("4");
|
|
|
|
|
+ user.setCTel(account.getTelephone());
|
|
|
boolean insertSuccess = dMSService.insertToDms(user.toJSON(), getTokenOfServiceAccount(), DMSColumn.USER);
|
|
boolean insertSuccess = dMSService.insertToDms(user.toJSON(), getTokenOfServiceAccount(), DMSColumn.USER);
|
|
|
if (!insertSuccess) {
|
|
if (!insertSuccess) {
|
|
|
allSuccess = false;
|
|
allSuccess = false;
|
|
@@ -544,7 +546,7 @@ public class AuthService {
|
|
|
if (userId != null) {
|
|
if (userId != null) {
|
|
|
boolean b = false;
|
|
boolean b = false;
|
|
|
try {
|
|
try {
|
|
|
- b = initUser(userUnInitResult);
|
|
|
|
|
|
|
+ b = initUser(userUnInitResult,account);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
deleteUser(userId);
|
|
deleteUser(userId);
|
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
@@ -578,6 +580,15 @@ public class AuthService {
|
|
|
return new Account(oauthAccount, oauthPassword);
|
|
return new Account(oauthAccount, oauthPassword);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 生成账户信息
|
|
|
|
|
+ */
|
|
|
|
|
+ private static Account generateAccount(String uniCode, String namePrefix, String passwordPrefix, String salt,String telephone) {
|
|
|
|
|
+ String uniCodeBase64 = ObfuscationUtils.advancedObfuscate(uniCode + salt);
|
|
|
|
|
+ String oauthAccount = namePrefix + uniCodeBase64 + uniCode.substring(uniCode.length() - 4);
|
|
|
|
|
+ String oauthPassword = passwordPrefix + encrypt(uniCode + salt);
|
|
|
|
|
+ return new Account(oauthAccount, oauthPassword,null,telephone);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* SHA-256加密方法
|
|
* SHA-256加密方法
|