xiongzhu hace 3 años
padre
commit
6a54f86b50

+ 12 - 8
src/main/java/com/izouma/nineth/service/IdentityAuthService.java

@@ -30,6 +30,7 @@ import java.nio.charset.StandardCharsets;
 import java.time.LocalDate;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
+import java.util.concurrent.ForkJoinPool;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Pattern;
@@ -134,10 +135,10 @@ public class IdentityAuthService {
         HttpRequest request = HttpRequest.get("https://mobilecert.market.alicloudapi.com/mobile3MetaSimple?userName="
                         + URLEncoder.encode(name, StandardCharsets.UTF_8)
                         + "&identifyNum=" + idno + "&mobile=" + phone)
-                .header("Authorization", "APPCODE 1af29c2d37c4f415fac930d82f01fb559");
+                .header("Authorization", "APPCODE af29c2d37c4f415fac930d82f01fb559");
         String body = request.body();
-        if (request.code() == 403) {
-            throw new BusinessException("403", 403);
+        if (request.code() != 200) {
+            throw new BusinessException(request.code() + "", request.code());
         }
         JSONObject jsonObject = JSONObject.parseObject(body);
         log.info("validate {} {} \n{}", name, idno, JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat));
@@ -217,10 +218,13 @@ public class IdentityAuthService {
         }
         try {
             List<IdentityAuth> list = identityAuthRepo.findByStatusAndAutoValidated(AuthStatus.PENDING, false);
-            list.parallelStream().forEach(identityAuth -> {
-                Map<String, Object> map = auth(identityAuth);
-                audit(identityAuth.getId(), (AuthStatus) map.get("status"), (String) map.get("reason"));
-            });
+            new ForkJoinPool(2).submit(() -> {
+                list.parallelStream().forEach(identityAuth -> {
+                    Map<String, Object> map = auth(identityAuth);
+                    audit(identityAuth.getId(), (AuthStatus) map.get("status"), (String) map.get("reason"));
+                });
+            }).get();
+
         } catch (Exception e) {
             log.error("批量自动实名出错", e);
         }
@@ -268,7 +272,7 @@ public class IdentityAuthService {
                     } catch (Exception e) {
                         log.error("自动实名出错", e);
                         if (e instanceof BusinessException && ((BusinessException) e).getCode() == 403) {
-                            result.put("status", AuthStatus.FAIL);
+                            result.put("status", AuthStatus.PENDING);
                         } else {
                             result.put("status", AuthStatus.FAIL);
                             result.put("reason", e.getMessage());

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

@@ -546,6 +546,6 @@ public class CommonTest {
 
     @Test
     public void testAuth() {
-        IdentityAuthService.validate ("蔡文峰", "15077886171", "431202199707283637");
+        IdentityAuthService.validate ("宋震南", "15173871802", "431026200112072510");
     }
 }