|
|
@@ -131,6 +131,29 @@ public class IdentityAuthService {
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
+ public static void validateV2(String name, String phone, String idno) {
|
|
|
+ String body = HttpRequest.post("https://zid.market.alicloudapi.com/idcheck/Post")
|
|
|
+ .header("Authorization", "APPCODE af29c2d37c4f415fac930d82f01fb559")
|
|
|
+ .contentType(HttpRequest.CONTENT_TYPE_FORM)
|
|
|
+ .form("cardNo", idno)
|
|
|
+ .form("realName", name)
|
|
|
+ .body();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
+ log.info("validate {} {} \n{}", name, idno, JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat));
|
|
|
+ if (jsonObject.getInteger("error_code") != 0) {
|
|
|
+ String msg = jsonObject.getString("reason");
|
|
|
+ throw new BusinessException(msg);
|
|
|
+ } else {
|
|
|
+ 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 static void validate(String name, String phone, String idno) {
|
|
|
HttpRequest request = HttpRequest.get("https://mobilecert.market.alicloudapi.com/mobile3MetaSimple?userName="
|
|
|
+ URLEncoder.encode(name, StandardCharsets.UTF_8)
|
|
|
@@ -237,10 +260,9 @@ public class IdentityAuthService {
|
|
|
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())) {
|
|
|
+ } else if (identityAuth.getIdNo() == null ||
|
|
|
+ !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 {
|
|
|
@@ -267,7 +289,7 @@ public class IdentityAuthService {
|
|
|
result.put("reason", "同一身份证注册超过3个");
|
|
|
} else {
|
|
|
try {
|
|
|
- validate(identityAuth.getRealName(), identityAuth.getPhone(), identityAuth.getIdNo());
|
|
|
+ validateV2(identityAuth.getRealName(), identityAuth.getPhone(), identityAuth.getIdNo());
|
|
|
result.put("status", AuthStatus.SUCCESS);
|
|
|
} catch (Exception e) {
|
|
|
log.error("自动实名出错", e);
|