Parcourir la source

补充初始化

ximinghao il y a 3 mois
Parent
commit
6a19370bea

+ 4 - 0
src/main/java/com/skyversation/xjcy/bean/User.java

@@ -8,11 +8,15 @@ public class User implements FromJSON{
     private String cUsercode;
     private String cGlGs;
     private String cUserStatus;
+    private String cType;
+    private String cTel;
     public JSONObject toJSON(){
         JSONObject json = new JSONObject();
         json.put("c_usercode", cUsercode);
         json.put("c_gl_gs", cGlGs);
         json.put("c_user_status", cUserStatus);
+        json.put("c_type", cType);
+        json.put("c_tel", cTel);
         json.put("title", cUsercode);
         json.put("content", cUsercode);
         return json;

+ 7 - 0
src/main/java/com/skyversation/xjcy/controller/OtherController.java

@@ -58,6 +58,13 @@ public class OtherController {
             User user = JSONObject.toJavaObject(userJSON, User.class);
             if (userJSON != null) {
                 user.setCGlGs(enterprise);
+                if ("4".equals(user.getCType())&&enterprise!=null) {
+                    user.setCType("3");
+                }
+
+                if ("3".equals(user.getCType())&&enterprise==null) {
+                    user.setCType("4");
+                }
                 dMSService.updateToDms(Collections.singletonList(userJSON), authService.getTokenOfServiceAccount(), DMSColumn.USER);
             }
         }

+ 19 - 8
src/main/java/com/skyversation/xjcy/service/AuthService.java

@@ -19,8 +19,6 @@ import org.springframework.util.StringUtils;
 import javax.annotation.PostConstruct;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
@@ -147,17 +145,19 @@ public class AuthService {
         private final String username;
         private final String password;
         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()) {
                 throw new IllegalArgumentException("缺失必要参数");
             }
             this.username = username;
             this.password = password;
             this.serviceId = serviceId;
+            this.telephone = telephone;
         }
         public Account(String username, String password) {
-            this(username, password, null);
+            this(username, password, null,null);
         }
 
         @Override
@@ -309,7 +309,7 @@ public class AuthService {
     public String logOrRegPhoneAccount(String phone, String code) {
         PhoneService.Result result = phoneService.login(phone, code);
         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 {
             return MessageManage.getInstance().getResultContent(-1, result.getError(), result.getError());
         }
@@ -325,7 +325,7 @@ public class AuthService {
     public String logOrRegWeChatPhoneAccount(String jsCode) {
         WeChatService.PhoneResult result = weChatService.wxPhoneLogin(jsCode);
         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 {
             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;
         JSONObject userContent = userJSON.getJSONObject(RESPONSE_FIELD_CONTENT);
         String usercode = userContent.getString(RESPONSE_FIELD_USERNAME);
@@ -473,6 +473,8 @@ public class AuthService {
             User user = new User();
             user.setCUsercode(usercode);
             user.setCUserStatus("1");
+            user.setCType("4");
+            user.setCTel(account.getTelephone());
             boolean insertSuccess = dMSService.insertToDms(user.toJSON(), getTokenOfServiceAccount(), DMSColumn.USER);
             if (!insertSuccess) {
                 allSuccess = false;
@@ -544,7 +546,7 @@ public class AuthService {
         if (userId != null) {
             boolean b = false;
             try {
-                b = initUser(userUnInitResult);
+                b = initUser(userUnInitResult,account);
             } catch (Exception e) {
                 deleteUser(userId);
                 throw new RuntimeException(e);
@@ -578,6 +580,15 @@ public class AuthService {
         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加密方法

+ 5 - 0
src/main/java/com/skyversation/xjcy/service/WxServiceMock.java

@@ -12,4 +12,9 @@ public class WxServiceMock extends WeChatService {
     public ResponseEntity<byte[]> createWxacode(String path, String scene) {
         return null;
     }
+
+    @Override
+    public PhoneResult wxPhoneLogin(String jsCode) {
+        return new PhoneResult(true,null,"1234567890");
+    }
 }