|
@@ -2,6 +2,9 @@ package com.skyversation.xjcy.oauth;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.skyversation.xjcy.bean.User;
|
|
|
|
|
+import com.skyversation.xjcy.dms.DMSColumn;
|
|
|
|
|
+import com.skyversation.xjcy.dms.DMSService;
|
|
|
import com.skyversation.xjcy.service.WeChatService;
|
|
import com.skyversation.xjcy.service.WeChatService;
|
|
|
import com.skyversation.xjcy.util.HttpUtil;
|
|
import com.skyversation.xjcy.util.HttpUtil;
|
|
|
import com.skyversation.xjcy.util.MessageManage;
|
|
import com.skyversation.xjcy.util.MessageManage;
|
|
@@ -16,6 +19,7 @@ import javax.annotation.PostConstruct;
|
|
|
import java.security.MessageDigest;
|
|
import java.security.MessageDigest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -64,6 +68,11 @@ public class AuthService {
|
|
|
private static final String RESPONSE_FIELD_CONTENT = "content";
|
|
private static final String RESPONSE_FIELD_CONTENT = "content";
|
|
|
/** 响应字段:用户ID */
|
|
/** 响应字段:用户ID */
|
|
|
private static final String RESPONSE_FIELD_ID = "id";
|
|
private static final String RESPONSE_FIELD_ID = "id";
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 响应字段:用户名
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final String RESPONSE_FIELD_USERNAME = "username";
|
|
|
|
|
+ private final DMSService dMSService;
|
|
|
|
|
|
|
|
|
|
|
|
|
// ============================ 内部类定义 ============================
|
|
// ============================ 内部类定义 ============================
|
|
@@ -111,9 +120,10 @@ public class AuthService {
|
|
|
|
|
|
|
|
// ============================ 构造方法 ============================
|
|
// ============================ 构造方法 ============================
|
|
|
|
|
|
|
|
- public AuthService(WeChatService weChatService, PhoneService phoneService) {
|
|
|
|
|
|
|
+ public AuthService(WeChatService weChatService, PhoneService phoneService, DMSService dMSService) {
|
|
|
this.weChatService = weChatService;
|
|
this.weChatService = weChatService;
|
|
|
this.phoneService = phoneService;
|
|
this.phoneService = phoneService;
|
|
|
|
|
+ this.dMSService = dMSService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// ============================ 初始化方法 ============================
|
|
// ============================ 初始化方法 ============================
|
|
@@ -259,8 +269,20 @@ public class AuthService {
|
|
|
/**
|
|
/**
|
|
|
* 初始化用户数据
|
|
* 初始化用户数据
|
|
|
*/
|
|
*/
|
|
|
- private boolean initUser(int userId) {
|
|
|
|
|
- //TODO 初始化用户
|
|
|
|
|
|
|
+ private boolean initUser(JSONObject userId) {
|
|
|
|
|
+ String usercode = userId.getJSONObject(RESPONSE_FIELD_CONTENT).getString(RESPONSE_FIELD_USERNAME);
|
|
|
|
|
+ if (usercode == null || usercode.isEmpty()) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!isUserDmsDataExist(usercode)){
|
|
|
|
|
+ User user = new User();
|
|
|
|
|
+ user.setCUsercode(usercode);
|
|
|
|
|
+ boolean insertSuccess = dMSService.insertToDms(user.toJSON(),getTokenOfServiceAccount(), DMSColumn.USER);
|
|
|
|
|
+ if (!insertSuccess) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -289,6 +311,14 @@ public class AuthService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 检查用户账户DMS数据存在性
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean isUserDmsDataExist(String userCode){
|
|
|
|
|
+ List<JSONObject> js = dMSService.getUserJSONByCode(userCode);
|
|
|
|
|
+ return !js.isEmpty();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 尝试注册并初始化用户
|
|
* 尝试注册并初始化用户
|
|
|
*/
|
|
*/
|
|
@@ -306,7 +336,7 @@ public class AuthService {
|
|
|
|
|
|
|
|
Integer userId = userUnInitResult.getJSONObject(RESPONSE_FIELD_CONTENT).getInteger(RESPONSE_FIELD_ID);
|
|
Integer userId = userUnInitResult.getJSONObject(RESPONSE_FIELD_CONTENT).getInteger(RESPONSE_FIELD_ID);
|
|
|
if (userId != null) {
|
|
if (userId != null) {
|
|
|
- return initUser(userId);
|
|
|
|
|
|
|
+ return initUser(userUnInitResult);
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|