Parcourir la source

Merge branch 'master' into dev

licailing il y a 3 ans
Parent
commit
66332136f3

+ 1 - 3
src/main/java/com/izouma/nineth/security/WebSecurityConfig.java

@@ -107,9 +107,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/news/all").permitAll()
                 .antMatchers("/news/all").permitAll()
                 .antMatchers("/news/get/**").permitAll()
                 .antMatchers("/news/get/**").permitAll()
                 .antMatchers("/druid/**").permitAll()
                 .antMatchers("/druid/**").permitAll()
-                .antMatchers("/testmq/**").permitAll()
-                .antMatchers("/teststock/**").permitAll()
-                .antMatchers("/debounce/**").permitAll()
+                .antMatchers("/identityAuth/autoAuth").permitAll()
                 // all other requests need to be authenticated
                 // all other requests need to be authenticated
                 .anyRequest().authenticated().and()
                 .anyRequest().authenticated().and()
                 // make sure we use stateless session; session won't be used to
                 // make sure we use stateless session; session won't be used to

+ 40 - 34
src/main/java/com/izouma/nineth/service/IdentityAuthService.java

@@ -23,9 +23,7 @@ import org.springframework.stereotype.Service;
 
 
 import java.time.LocalDate;
 import java.time.LocalDate;
 import java.time.temporal.ChronoUnit;
 import java.time.temporal.ChronoUnit;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Pattern;
 import java.util.regex.Pattern;
@@ -205,48 +203,56 @@ public class IdentityAuthService {
         try {
         try {
             List<IdentityAuth> list = identityAuthRepo.findByStatusAndAutoValidated(AuthStatus.PENDING, false);
             List<IdentityAuth> list = identityAuthRepo.findByStatusAndAutoValidated(AuthStatus.PENDING, false);
             list.parallelStream().forEach(identityAuth -> {
             list.parallelStream().forEach(identityAuth -> {
-                log.info("实名 {}", identityAuth.getRealName());
-                boolean success = false;
-                String reason = null;
-                User user = userRepo.findById(identityAuth.getUserId()).orElseThrow(new BusinessException("用户不存在"));
-                if (user.getAuthStatus() == AuthStatus.SUCCESS) {
-                    audit(identityAuth.getId(), AuthStatus.SUCCESS, null);
-                    return;
-                }
-                if (!Pattern.matches("[1-9]{1}[0-9]{5}(19|20)[0-9]{2}((0[1-9]{1})|(1[0-2]{1}))((0[1-9]{1})|([1-2]{1}[0-9]{1}|(3[0-1]{1})))[0-9]{3}[0-9x]{1}", identityAuth.getIdNo()
-                        .toLowerCase())) {
-                    audit(identityAuth.getId(), AuthStatus.FAIL, "身份证格式错误");
-                    return;
-                } else {
-                    LocalDate birth = DateTimeUtils.toLocalDate(identityAuth.getIdNo().substring(6, 14), "yyyyMMdd");
-                    long age = ChronoUnit.YEARS.between(birth, LocalDate.now());
-                    if (age < 18) {
-                        audit(identityAuth.getId(), AuthStatus.FAIL, "未满18岁");
-                        return;
-                    } else if (age > 60) {
-                        audit(identityAuth.getId(), AuthStatus.FAIL, "超过60岁");
-                        return;
-                    }
-                }
+                Map<String, Object> map = auth(identityAuth);
+                audit(identityAuth.getId(), (AuthStatus) map.get("status"), (String) map.get("reason"));
+            });
+        } catch (Exception e) {
+            log.error("批量自动实名出错", e);
+        }
+    }
 
 
+    public Map<String, Object> auth(IdentityAuth identityAuth) {
+        log.info("实名 {}", identityAuth.getRealName());
+        Map<String, Object> result = new HashMap<>();
+        String reason = null;
+        User user = userRepo.findById(identityAuth.getUserId()).orElseThrow(new BusinessException("用户不存在"));
+        if (user.getAuthStatus() == AuthStatus.SUCCESS) {
+            result.put("status", AuthStatus.SUCCESS);
+        } else if (!Pattern.matches("[1-9]{1}[0-9]{5}(19|20)[0-9]{2}((0[1-9]{1})|(1[0-2]{1}))((0[1-9]{1})|([1-2]{1}[0-9]{1}|(3[0-1]{1})))[0-9]{3}[0-9x]{1}", identityAuth.getIdNo()
+                .toLowerCase())) {
+            result.put("status", AuthStatus.FAIL);
+            result.put("reason", "身份证格式错误");
+        } else {
+            LocalDate birth = DateTimeUtils.toLocalDate(identityAuth.getIdNo().substring(6, 14), "yyyyMMdd");
+            long age = ChronoUnit.YEARS.between(birth, LocalDate.now());
+            if (age < 18) {
+                result.put("status", AuthStatus.FAIL);
+                result.put("reason", "未满18岁");
+            } else if (age > 60) {
+                result.put("status", AuthStatus.FAIL);
+                result.put("reason", "超过60岁");
+            } else {
                 int count = identityAuthRepo.countByIdNoAndStatus(identityAuth.getIdNo(), AuthStatus.SUCCESS);
                 int count = identityAuthRepo.countByIdNoAndStatus(identityAuth.getIdNo(), AuthStatus.SUCCESS);
 
 
                 if (count >= 3) {
                 if (count >= 3) {
-                    success = false;
-                    reason = "同一身份证注册超过3个";
+                    result.put("status", AuthStatus.PENDING);
+                    result.put("reason", "同一身份证注册超过3个");
                 } else {
                 } else {
                     try {
                     try {
                         validate(identityAuth.getRealName(), user.getPhone(), identityAuth.getIdNo());
                         validate(identityAuth.getRealName(), user.getPhone(), identityAuth.getIdNo());
-                        success = true;
+                        result.put("status", AuthStatus.SUCCESS);
                     } catch (Exception e) {
                     } catch (Exception e) {
                         log.error("自动实名出错", e);
                         log.error("自动实名出错", e);
-                        reason = e.getMessage();
+                        if ("不匹配".equals(e.getMessage())) {
+                            result.put("status", AuthStatus.FAIL);
+                        } else {
+                            result.put("status", AuthStatus.PENDING);
+                        }
+                        result.put("reason", e.getMessage());
                     }
                     }
                 }
                 }
-                audit(identityAuth.getId(), success ? AuthStatus.SUCCESS : AuthStatus.PENDING, reason);
-            });
-        } catch (Exception e) {
-            log.error("批量自动实名出错", e);
+            }
         }
         }
+        return result;
     }
     }
 }
 }

+ 9 - 0
src/main/java/com/izouma/nineth/web/IdentityAuthController.java

@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.IOException;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 @RestController
 @RestController
 @RequestMapping("/identityAuth")
 @RequestMapping("/identityAuth")
@@ -80,5 +81,13 @@ public class IdentityAuthController extends BaseController {
     public void removeDuplicated() {
     public void removeDuplicated() {
         identityAuthService.removeDuplicated();
         identityAuthService.removeDuplicated();
     }
     }
+
+    @PostMapping("/autoAuth")
+    public Object authAuth(@RequestParam Long id) {
+        IdentityAuth identityAuth = identityAuthRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+        Map<String, Object> map = identityAuthService.auth(identityAuth);
+        identityAuthService.audit(identityAuth.getId(), (AuthStatus) map.get("status"), (String) map.get("reason"));
+        return map;
+    }
 }
 }
 
 

+ 2 - 2
src/test/java/com/izouma/nineth/CommonTest.java

@@ -458,8 +458,8 @@ public class CommonTest {
         String body = HttpRequest.post("https://zid.market.alicloudapi.com/idcheck/Post")
         String body = HttpRequest.post("https://zid.market.alicloudapi.com/idcheck/Post")
                 .header("Authorization", "APPCODE b48bc8f6759345a79ae20a951f03dabe")
                 .header("Authorization", "APPCODE b48bc8f6759345a79ae20a951f03dabe")
                 .contentType(HttpRequest.CONTENT_TYPE_FORM)
                 .contentType(HttpRequest.CONTENT_TYPE_FORM)
-                .form("cardNo", "1")
-                .form("realName", "2")
+                .form("cardNo", "352228198905220012")
+                .form("realName", "吴承培")
                 .body();
                 .body();
         System.out.println(JSON.toJSONString(JSON.parseObject(body), SerializerFeature.PrettyFormat));
         System.out.println(JSON.toJSONString(JSON.parseObject(body), SerializerFeature.PrettyFormat));
     }
     }