企业认证

main
rong.liu 11 months ago
parent e9f2d8a968
commit f3f538a0e6
  1. 12
      users/src/main/java/com/huoran/users/config/AliRealNameAuthenticationConfig.java
  2. 117
      users/src/main/java/com/huoran/users/controller/AliRealNameAuthenticationController.java
  3. 64
      users/src/main/java/com/huoran/users/entity/res/BusinessLicenseOCRResp.java
  4. 40
      users/src/main/java/com/huoran/users/entity/res/CreditCodeResp.java

@ -12,8 +12,18 @@ public class AliRealNameAuthenticationConfig {
public static final String ALI_API_HOST = "https://cardnumber.market.alicloudapi.com";
//营业执照
public static final String ALI_API_BUSINESS_LICENSE_HOST = "https://bizlicense.market.alicloudapi.com";
public static final String ALI_API_BUSINESS_LICENSE_PATH = "/rest/160601/ocr/ocr_business_license.json";
public static final String ALI_API_PATH = "/rest/160601/ocr/ocr_idcard.json";
public static final String ALI_API_APPCODE = "4c22c2b34b2d4b5aaa57186a49aa3a4c";
// public static final String ALI_API_APPCODE = "4c22c2b34b2d4b5aaa57186a49aa3a4c";
public static final String ALI_API_APPCODE = "62512c9aa7714735a182bb08a0173f22";
public static final String ALI_IDCHECK_HOST = "https://sxidcheck.market.alicloudapi.com";
public static final String ALI_IDCHECK_PATH = "/idcard/check";

@ -1,19 +1,26 @@
package com.huoran.users.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.huoran.common.response.R;
import com.huoran.common.utils.TokenUtils;
import com.huoran.users.config.AliRealNameAuthenticationConfig;
import com.huoran.users.entity.UserAuthenticationInformation;
import com.huoran.users.entity.req.IdCardOCRReq;
import com.huoran.users.entity.res.BusinessLicenseOCRResp;
import com.huoran.users.entity.res.CreditCodeResp;
import com.huoran.users.entity.res.IdCardOCRResp;
import com.huoran.users.entity.res.RealNameAuthenticationResp;
import com.huoran.users.service.UserAuthenticationInformationService;
import com.huoran.users.utils.ali.FaceRecognitionAidUtil;
import com.huoran.users.utils.ali.HttpUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
@ -21,7 +28,8 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;
import java.util.Optional;
import java.util.HashMap;
import java.util.Map;
@Api(value = "小程序-实名认证", tags = "小程序-实名认证")
@RestController
@ -32,7 +40,7 @@ public class AliRealNameAuthenticationController {
@Autowired
public UserAuthenticationInformationService service;
@ApiOperation(value = "身份证图片验证(对象)")
/* @ApiOperation(value = "身份证图片验证(对象)")
@PostMapping("/faceAuthenticationByObject")
public R faceAuthenticationByObject(HttpServletRequest request, @RequestBody IdCardOCRReq req) throws IOException {
//正面身份证信息返回
@ -41,9 +49,9 @@ public class AliRealNameAuthenticationController {
//反面身份证信息返回
String reverseIDInformationReturned = FaceRecognitionAidUtil.IdCardOCRRecognition(req.getReverseOfIDCard(),"back");
/*if (ObjectUtils.isEmpty(positiveIDReturnsInformation)&&ObjectUtils.isEmpty(reverseIDInformationReturned)){
*//*if (ObjectUtils.isEmpty(positiveIDReturnsInformation)&&ObjectUtils.isEmpty(reverseIDInformationReturned)){
throw new RuntimeException("身份证图片验证失败,请重新再试!");
}*/
}*//*
Optional.ofNullable(positiveIDReturnsInformation)
.orElseThrow(() -> new RuntimeException("身份证图片验证失败,请重新再试!"));
Optional.ofNullable(reverseIDInformationReturned)
@ -54,21 +62,20 @@ public class AliRealNameAuthenticationController {
IdCardOCRResp reverseSide = new Gson().fromJson(reverseIDInformationReturned, IdCardOCRResp.class);
return R.ok().put("front", front).put("reverseSide", reverseSide);
}
}*/
@ApiOperation(value = "身份证图片验证")
@PostMapping("/faceAuthentication")
public R faceAuthentication(@RequestParam(name = "imgFile", required = true) @ApiParam(value = "图片url") String imgFile ,
@RequestParam(name = "side", required = true) @ApiParam(value = "身份证正反面类型:face/back") String side)throws IOException {
public R faceAuthentication(@RequestParam(name = "imgFile", required = true) @ApiParam(value = "图片url") String imgFile, @RequestParam(name = "side", required = true) @ApiParam(value = "身份证正反面类型:face/back") String side) throws IOException {
//身份证信息返回
String idCardInformationReturn = FaceRecognitionAidUtil.IdCardOCRRecognition(imgFile,side);
if (ObjectUtils.isEmpty(idCardInformationReturn)){
String idCardInformationReturn = FaceRecognitionAidUtil.IdCardOCRRecognition(imgFile, side);
if (ObjectUtils.isEmpty(idCardInformationReturn)) {
throw new RuntimeException("身份证图片验证失败,请重新再试!");
}
IdCardOCRResp resp = new Gson().fromJson(idCardInformationReturn, IdCardOCRResp.class);
if (resp.getSuccess()){
if (resp.getSuccess()) {
return R.ok().put("data", resp);
}else {
} else {
throw new RuntimeException("身份证图片验证失败,请重新再试!");
}
@ -81,8 +88,7 @@ public class AliRealNameAuthenticationController {
String accountId = TokenUtils.getIdByJwtToken(request);
userAuthenticationInformation.setAccountId(Integer.valueOf(accountId));
String json = FaceRecognitionAidUtil.postData(AliRealNameAuthenticationConfig.ALI_API_APPCODE,
AliRealNameAuthenticationConfig.GET_APP_CODE_LINK, userAuthenticationInformation.getRealName(), userAuthenticationInformation.getIdCardNo());
String json = FaceRecognitionAidUtil.postData(AliRealNameAuthenticationConfig.ALI_API_APPCODE, AliRealNameAuthenticationConfig.GET_APP_CODE_LINK, userAuthenticationInformation.getRealName(), userAuthenticationInformation.getIdCardNo());
RealNameAuthenticationResp info = new Gson().fromJson(json, RealNameAuthenticationResp.class);
if (!info.getRespCode().equals("0000")) {
@ -106,12 +112,12 @@ public class AliRealNameAuthenticationController {
String accountId = TokenUtils.getIdByJwtToken(request);
QueryWrapper<UserAuthenticationInformation> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("account_id",accountId);
queryWrapper.eq("account_id", accountId);
UserAuthenticationInformation userAuthenticationInformation = service.getOne(queryWrapper);
if (ObjectUtils.isEmpty(userAuthenticationInformation)){
if (ObjectUtils.isEmpty(userAuthenticationInformation)) {
return R.ok().put("data", false);
}
return R.ok().put("data", true).put("authenticationInformation",userAuthenticationInformation);
return R.ok().put("data", true).put("authenticationInformation", userAuthenticationInformation);
}
/*@ApiOperation(value = "输入身份证号码、姓名进行实名认证")
@PostMapping("/realNameAuthentication")
@ -128,4 +134,81 @@ public class AliRealNameAuthenticationController {
}*/
@ApiOperation(value = "营业执照图片验证")
@PostMapping("/businessLicensePictureVerification")
public R businessLicensePictureVerification(@RequestParam(name = "imgFile", required = true) @ApiParam(value = "图片url") String imgFile) throws IOException {
String method = "POST";
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + AliRealNameAuthenticationConfig.ALI_API_APPCODE);
//根据API的要求,定义相对应的Content-Type
headers.put("Content-Type", "application/json; charset=UTF-8");
Map<String, String> querys = new HashMap<String, String>();
String bodys = "{\"image\":\"" + imgFile + "\"}";
try {
HttpResponse response = HttpUtils.doPost(AliRealNameAuthenticationConfig.ALI_API_BUSINESS_LICENSE_HOST, AliRealNameAuthenticationConfig.ALI_API_BUSINESS_LICENSE_PATH, method, headers, querys, bodys);
BusinessLicenseOCRResp info = new Gson().fromJson(EntityUtils.toString(response.getEntity()), BusinessLicenseOCRResp.class);
if (info.getSuccess()) {
return R.ok().put("data", info);
} else {
throw new RuntimeException("营业执照图片验证,请重新再试!");
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("营业执照图片验证,请重新再试!");
}
}
@ApiOperation(value = "统一社会信用代码认证")
@PostMapping("/creditCodeAuthentication")
public R creditCodeAuthentication(@RequestParam(name = "comapnyName", required = true) @ApiParam(value = "公司的名字") String comapnyName,
@RequestParam(name = "legalPerson", required = true) @ApiParam(value = "法人") String legalPerson,
@RequestParam(name = "creditCode", required = true) @ApiParam(value = "统一社会信用代码") String creditCode, HttpServletRequest request) throws IOException {
String host = "https://sys.81api.com";
String path = "/verifyCompany/";
String method = "GET";
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + AliRealNameAuthenticationConfig.ALI_API_APPCODE);
Map<String, String> querys = new HashMap<String, String>();
querys.put("ComapnyName", comapnyName);
querys.put("CreditCode", creditCode);
querys.put("LegalPersonName", legalPerson);
String errorMsg = "";
try {
HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
// System.out.println(response.toString());
//获取response的body
//System.out.println(EntityUtils.toString(response.getEntity()));
CreditCodeResp info = new Gson().fromJson(EntityUtils.toString(response.getEntity()), CreditCodeResp.class);
if (info.getStatus()) {
return R.ok().put("message", "认证通过!");
} else {
errorMsg = info.getReason();
return R.ok().put("message", info.getReason());
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(errorMsg);
}
}
public static <T> T jsonToObject(String json) {
try {
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readValue(json, new TypeReference<T>() {});
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

@ -0,0 +1,64 @@
package com.huoran.users.entity.res;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value = "营业执照OCR文件识别")
public class BusinessLicenseOCRResp {
/*@ApiModelProperty(value = "配置字符串信息")
private String config_str;*/
@ApiModelProperty(value = "#统一社会信用代码或注册号,没有识别出来时返回FailInRecognition")
private String reg_num;
@ApiModelProperty(value = "公司名称,没有识别出来时返回FailInRecognition")
private String name;
@ApiModelProperty(value = "公司类型,没有识别出来时返回FailInRecognition")
private String type;
@ApiModelProperty(value = "公司法人,没有识别出来时返回FailInRecognition")
private String person;
@ApiModelProperty(value = "公司注册日期(例:证件上为2014年04月16日,算法返回20140416")
private String establish_date;
@ApiModelProperty(value = "公司营业期限终止日期(例:证件上为2014年04月16日至2034年04月15日,算法返回20340415)")
private String valid_period;
@ApiModelProperty(value = "公司地址,没有识别出来时返回FailInRecognition")
private String address;
@ApiModelProperty(value = "注册资本,没有识别出来时返回FailInRecognition")
private String capital;
@ApiModelProperty(value = "经营范围,没有识别出来时返回FailInRecognition")
private String business;
/* @ApiModelProperty(value = "国徽位置[top,left,height,width],没有识别出来时返回FailInDetection")
private String emblem;*/
//使用@JsonIgnore注解,忽略此属性,前端不会拿到该属性
@JsonIgnore
@ApiModelProperty(value = "识别结果,true表示成功,false表示失败")
private Boolean success;
}

@ -0,0 +1,40 @@
package com.huoran.users.entity.res;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value = "营业执照OCR文件识别")
public class CreditCodeResp {
//使用@JsonIgnore注解,忽略此属性,前端不会拿到该属性
@JsonIgnore
@ApiModelProperty(value = "识别结果,true表示成功,false表示失败")
private Boolean status;
//使用@JsonIgnore注解,忽略此属性,前端不会拿到该属性
@JsonIgnore
@ApiModelProperty(value = "正确返回返回信息")
private String msg;
//使用@JsonIgnore注解,忽略此属性,前端不会拿到该属性
@JsonIgnore
@ApiModelProperty(value = "查询结果")
private String result;
//使用@JsonIgnore注解,忽略此属性,前端不会拿到该属性
@JsonIgnore
@ApiModelProperty(value = "失败返回信息")
private String reason;
//使用@JsonIgnore注解,忽略此属性,前端不会拿到该属性
@JsonIgnore
@ApiModelProperty(value = "返回码")
private Integer code;
}
Loading…
Cancel
Save