|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |