|
|
@@ -16,6 +16,7 @@ import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -24,6 +25,7 @@ import java.time.LocalDate;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -91,30 +93,98 @@ public class IdentityAuthService {
|
|
|
return userRepo.findByIdInAndDelFalse(userIds);
|
|
|
}
|
|
|
|
|
|
+ // public void validate(String name, String phone, String idno) {
|
|
|
+// String body = HttpRequest.post("https://jubrige.market.alicloudapi.com/mobile/3-validate-transfer")
|
|
|
+// .header("Authorization", "APPCODE b48bc8f6759345a79ae20a951f03dabe")
|
|
|
+// .contentType(HttpRequest.CONTENT_TYPE_FORM)
|
|
|
+// .form("idCardNo", idno)
|
|
|
+// .form("mobile", phone)
|
|
|
+// .form("name", name)
|
|
|
+// .body();
|
|
|
+// JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
+// if (jsonObject.getInteger("code") != 200) {
|
|
|
+// String msg = jsonObject.getString("msg");
|
|
|
+// throw new BusinessException(msg);
|
|
|
+// } else {
|
|
|
+// JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+// int result = data.getIntValue("result");
|
|
|
+// String desc = data.getString("desc");
|
|
|
+// if (result != 0) {
|
|
|
+// throw new BusinessException(desc);
|
|
|
+// } else {
|
|
|
+// log.info("{} {} {} 实名认证通过", name, phone, idno);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
public void validate(String name, String phone, String idno) {
|
|
|
- String body = HttpRequest.post("https://jubrige.market.alicloudapi.com/mobile/3-validate-transfer")
|
|
|
+ String body = HttpRequest.post("https://zid.market.alicloudapi.com/idcheck/Post")
|
|
|
.header("Authorization", "APPCODE b48bc8f6759345a79ae20a951f03dabe")
|
|
|
.contentType(HttpRequest.CONTENT_TYPE_FORM)
|
|
|
- .form("idCardNo", idno)
|
|
|
- .form("mobile", phone)
|
|
|
- .form("name", name)
|
|
|
+ .form("cardNo", idno)
|
|
|
+ .form("realName", name)
|
|
|
.body();
|
|
|
JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
- if (jsonObject.getInteger("code") != 200) {
|
|
|
- String msg = jsonObject.getString("msg");
|
|
|
+ if (jsonObject.getInteger("error_code") != 0) {
|
|
|
+ String msg = jsonObject.getString("reason");
|
|
|
throw new BusinessException(msg);
|
|
|
} else {
|
|
|
- JSONObject data = jsonObject.getJSONObject("data");
|
|
|
- int result = data.getIntValue("result");
|
|
|
- String desc = data.getString("desc");
|
|
|
- if (result != 0) {
|
|
|
- throw new BusinessException(desc);
|
|
|
+ JSONObject data = jsonObject.getJSONObject("result");
|
|
|
+ boolean isOK = Optional.ofNullable(data.getBoolean("isok")).orElse(Boolean.FALSE);
|
|
|
+ if (!isOK) {
|
|
|
+ throw new BusinessException("不匹配");
|
|
|
} else {
|
|
|
log.info("{} {} {} 实名认证通过", name, phone, idno);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void removeDuplicated() {
|
|
|
+ boolean hasMore = true;
|
|
|
+ int pageNum = 1;
|
|
|
+ while (hasMore) {
|
|
|
+ Page<Long> page = identityAuthRepo.listUserId(PageRequest.of(pageNum, 100));
|
|
|
+ List<Long> userIds = page.getContent();
|
|
|
+ userIds.parallelStream().forEach(userId -> {
|
|
|
+ userRepo.findById(userId).ifPresent(user -> {
|
|
|
+ List<IdentityAuth> list = identityAuthRepo.findByUserId(userId);
|
|
|
+ if (list.size() > 1) {
|
|
|
+ IdentityAuth auth = list.stream()
|
|
|
+ .filter(i -> i.getStatus() == AuthStatus.SUCCESS)
|
|
|
+ .findAny().orElse(null);
|
|
|
+ if (auth != null) {
|
|
|
+ userRepo.setAuthStatus(user.getId(), auth.getStatus(), auth.getId());
|
|
|
+ identityAuthRepo.deleteDuplicated(user.getId(), auth.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ auth = list.stream()
|
|
|
+ .filter(i -> i.getStatus() == AuthStatus.PENDING)
|
|
|
+ .findAny().orElse(null);
|
|
|
+ if (auth != null) {
|
|
|
+ userRepo.setAuthStatus(user.getId(), auth.getStatus(), auth.getId());
|
|
|
+ identityAuthRepo.deleteDuplicated(user.getId(), auth.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ auth = list.stream()
|
|
|
+ .filter(i -> i.getStatus() == AuthStatus.FAIL)
|
|
|
+ .findAny().orElse(null);
|
|
|
+ if (auth != null) {
|
|
|
+ userRepo.setAuthStatus(user.getId(), auth.getStatus(), auth.getId());
|
|
|
+ identityAuthRepo.deleteDuplicated(user.getId(), auth.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (list.size() == 1) {
|
|
|
+ userRepo.setAuthStatus(user.getId(), list.get(0).getStatus(), list.get(0).getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ hasMore = page.hasNext();
|
|
|
+ pageNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Scheduled(fixedRate = 60000)
|
|
|
@RedisLock(value = "autoValidate", expire = 30, unit = TimeUnit.MINUTES)
|
|
|
public void autoValidate() {
|