提交修改
This commit is contained in:
parent
fe2946d44d
commit
4e928d78a7
@ -2,12 +2,10 @@ package com.heyu.api.data.dto;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class IdCardAddressModel {
|
public class IdCardAddressModel {
|
||||||
|
|
||||||
public IdCardAddressModel(String p, String c, String co, int s){
|
public IdCardAddressModel(String p, String c, String co, int s,String birthday){
|
||||||
province = p;
|
province = p;
|
||||||
city = c;
|
city = c;
|
||||||
county = co;
|
county = co;
|
||||||
@ -17,6 +15,9 @@ public class IdCardAddressModel {
|
|||||||
}else{
|
}else{
|
||||||
sexChar = "女";
|
sexChar = "女";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.birthday = birthday;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -50,4 +51,9 @@ public class IdCardAddressModel {
|
|||||||
* */
|
* */
|
||||||
String sexChar;
|
String sexChar;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 生日
|
||||||
|
*/
|
||||||
|
private String birthday;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4117,8 +4117,17 @@ public class IDCardValidatorUtils {
|
|||||||
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static IdCardAddressModel getAddrInfo(String idCard){
|
public static IdCardAddressModel getAddrInfo(String idCard){
|
||||||
String p = idCard.substring(0, 2);
|
String p = idCard.substring(0, 2);
|
||||||
|
String a = idCard.substring(6, 13);
|
||||||
|
|
||||||
|
String birthday = a ;
|
||||||
|
if(a.length()==8){
|
||||||
|
birthday = a.substring(0,4) + "-" + a.substring(4,6) + "-" + a.substring(6,8);
|
||||||
|
}
|
||||||
|
|
||||||
if (idCardCodeMap.containsKey(p)) {
|
if (idCardCodeMap.containsKey(p)) {
|
||||||
IdCardCodeModel province = idCardCodeMap.get(p);
|
IdCardCodeModel province = idCardCodeMap.get(p);
|
||||||
String c = idCard.substring(2, 4);
|
String c = idCard.substring(2, 4);
|
||||||
@ -4129,9 +4138,9 @@ public class IDCardValidatorUtils {
|
|||||||
if (city.codeMap.containsKey(d)) {
|
if (city.codeMap.containsKey(d)) {
|
||||||
IdCardCodeModel district = city.codeMap.get(d);
|
IdCardCodeModel district = city.codeMap.get(d);
|
||||||
|
|
||||||
return new IdCardAddressModel(province.getName(), city.getName(), district.getName(), sex);
|
return new IdCardAddressModel(province.getName(), city.getName(), district.getName(), sex,birthday);
|
||||||
}else{
|
}else{
|
||||||
return new IdCardAddressModel(province.getName(), city.getName(), "", sex);
|
return new IdCardAddressModel(province.getName(), city.getName(), "", sex,birthday);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4156,7 +4165,11 @@ public class IDCardValidatorUtils {
|
|||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println(getAddrInfo("430529199209255030"));
|
String a = "19920925";
|
||||||
|
String b = a.substring(0,4) + "-" + a.substring(4,6) + "-" + a.substring(6,8);
|
||||||
|
System.out.println(a.length());
|
||||||
|
System.out.println(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package com.heyu.api.data.utils;
|
package com.heyu.api.data.utils;
|
||||||
|
|
||||||
|
|
||||||
import com.heyu.api.data.dto.IdCardAddressModel;
|
|
||||||
import com.heyu.api.data.dto.IdCardCodeModel;
|
import com.heyu.api.data.dto.IdCardCodeModel;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -44,26 +43,7 @@ public class MobileUtils {
|
|||||||
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
public static IdCardAddressModel getAddrInfo(String idCard){
|
|
||||||
String p = idCard.substring(0, 2);
|
|
||||||
if (idCardCodeMap.containsKey(p)) {
|
|
||||||
IdCardCodeModel province = idCardCodeMap.get(p);
|
|
||||||
String c = idCard.substring(2, 4);
|
|
||||||
if (province.codeMap.containsKey(c)) {
|
|
||||||
IdCardCodeModel city = province.codeMap.get(c);
|
|
||||||
String d = idCard.substring(4, 6);
|
|
||||||
int sex = Integer.parseInt(idCard.substring(16, 17)) % 2;
|
|
||||||
if (city.codeMap.containsKey(d)) {
|
|
||||||
IdCardCodeModel district = city.codeMap.get(d);
|
|
||||||
|
|
||||||
return new IdCardAddressModel(province.getName(), city.getName(), district.getName(), sex);
|
|
||||||
}else{
|
|
||||||
return new IdCardAddressModel(province.getName(), city.getName(), "", sex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean validateMobile(String phone) {
|
public static boolean validateMobile(String phone) {
|
||||||
return phone.matches(CHINA_PHONE_NUMBER_REGEX);
|
return phone.matches(CHINA_PHONE_NUMBER_REGEX);
|
||||||
|
|||||||
@ -66,7 +66,9 @@ public class IdCardOCRVerificationController {
|
|||||||
idCardOCRVerificationResp.setArea(idCardAddressModel.getCounty());
|
idCardOCRVerificationResp.setArea(idCardAddressModel.getCounty());
|
||||||
idCardOCRVerificationResp.setDetailAddress(idCardAddressModel.getProvince() + idCardAddressModel.getCity() + idCardAddressModel.getCounty());
|
idCardOCRVerificationResp.setDetailAddress(idCardAddressModel.getProvince() + idCardAddressModel.getCity() + idCardAddressModel.getCounty());
|
||||||
|
|
||||||
|
idCardOCRVerificationResp.setBirthday(idCardAddressModel.getBirthday());
|
||||||
idCardOCRVerificationResp.setSex(idCardAddressModel.getSex());
|
idCardOCRVerificationResp.setSex(idCardAddressModel.getSex());
|
||||||
|
idCardOCRVerificationResp.setSexChar(idCardAddressModel.getSexChar());
|
||||||
|
|
||||||
idCardOCRVerificationResp.setDesc("姓名和身份证号一致");
|
idCardOCRVerificationResp.setDesc("姓名和身份证号一致");
|
||||||
} else if ("-1".equals(idCardOCRVerificationResponse.getResult())) {
|
} else if ("-1".equals(idCardOCRVerificationResponse.getResult())) {
|
||||||
@ -82,7 +84,6 @@ public class IdCardOCRVerificationController {
|
|||||||
idCardOCRVerificationResp.setDesc(idCardOCRVerificationResponse.getDescription()); //其他情况
|
idCardOCRVerificationResp.setDesc(idCardOCRVerificationResponse.getDescription()); //其他情况
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
idCardOCRVerificationResp.setIdCardNumber(apiIdentityCardRequest.getIdCardNumber());
|
idCardOCRVerificationResp.setIdCardNumber(apiIdentityCardRequest.getIdCardNumber());
|
||||||
idCardOCRVerificationResp.setRealName(apiIdentityCardRequest.getRealName());
|
idCardOCRVerificationResp.setRealName(apiIdentityCardRequest.getRealName());
|
||||||
return R.ok().setData(idCardOCRVerificationResp);
|
return R.ok().setData(idCardOCRVerificationResp);
|
||||||
|
|||||||
@ -62,14 +62,23 @@ public class IdCardOCRVerificationResp {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 性别:0男 1女
|
* 性别:0男 1女
|
||||||
*/
|
*/
|
||||||
private Integer sex = 0;
|
private Integer sex = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 生日
|
||||||
|
*/
|
||||||
|
private String birthday;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 性别描述
|
||||||
|
* */
|
||||||
|
private String sexChar;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
147
api-web/api-interface/src/test/java/com/api/test/Demo.java
Normal file
147
api-web/api-interface/src/test/java/com/api/test/Demo.java
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
package com.api.test;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.crypto.Mac;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
import java.security.Key;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
|
class Demo {
|
||||||
|
public static String calcAuthorization(String secretId, String secretKey, String datetime)
|
||||||
|
throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
|
||||||
|
String signStr = "x-date: " + datetime;
|
||||||
|
Mac mac = Mac.getInstance("HmacSHA1");
|
||||||
|
Key sKey = new SecretKeySpec(secretKey.getBytes("UTF-8"), mac.getAlgorithm());
|
||||||
|
mac.init(sKey);
|
||||||
|
byte[] hash = mac.doFinal(signStr.getBytes("UTF-8"));
|
||||||
|
//String sig = new Base64Encoder().encode(hash);
|
||||||
|
|
||||||
|
|
||||||
|
Base64.Encoder encoder = Base64.getMimeEncoder();
|
||||||
|
String sig= encoder.encodeToString(hash);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
String auth = "{\"id\":\"" + secretId + "\", \"x-date\":\"" + datetime + "\", \"signature\":\"" + sig + "\"}";
|
||||||
|
return auth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String urlencode(Map<?, ?> map) throws UnsupportedEncodingException {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
sb.append("&");
|
||||||
|
}
|
||||||
|
sb.append(String.format("%s=%s",
|
||||||
|
URLEncoder.encode(entry.getKey().toString(), "UTF-8"),
|
||||||
|
URLEncoder.encode(entry.getValue().toString(), "UTF-8")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
|
||||||
|
//云市场分配的密钥Id
|
||||||
|
String secretId = "32GyIZXijjQqtaTx";
|
||||||
|
//云市场分配的密钥Key
|
||||||
|
String secretKey = "8drHlKmmphKWNxEidbRDMbV9zA3WX8Cn";
|
||||||
|
|
||||||
|
Calendar cd = Calendar.getInstance();
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
|
||||||
|
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
String datetime = sdf.format(cd.getTime());
|
||||||
|
// 签名
|
||||||
|
String auth = calcAuthorization(secretId, secretKey, datetime);
|
||||||
|
// 请求方法
|
||||||
|
String method = "POST";
|
||||||
|
// 请求头
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
Map<String, String> headers = new HashMap<String, String>();
|
||||||
|
headers.put("request-id", uuid);
|
||||||
|
headers.put("Authorization", auth);
|
||||||
|
|
||||||
|
// 查询参数
|
||||||
|
Map<String, String> queryParams = new HashMap<String, String>();
|
||||||
|
|
||||||
|
// body参数
|
||||||
|
Map<String, String> bodyParams = new HashMap<String, String>();
|
||||||
|
//bodyParams.put("cardNo","430529199209255030");
|
||||||
|
//bodyParams.put("realName","瞿贻晓");
|
||||||
|
|
||||||
|
//bodyParams.put("cardNo","360428198505100418");
|
||||||
|
//bodyParams.put("realName","吴林");
|
||||||
|
|
||||||
|
|
||||||
|
bodyParams.put("cardNo","360311199303080027");
|
||||||
|
bodyParams.put("realName","胡凯敏");
|
||||||
|
String bodyParamStr = urlencode(bodyParams);
|
||||||
|
|
||||||
|
// url参数拼接
|
||||||
|
String url = "https://ap-beijing.cloudmarket-apigw.com/service-18c38npd/idcard/VerifyIdcardv2";
|
||||||
|
if (!queryParams.isEmpty()) {
|
||||||
|
url += "?" + urlencode(queryParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedReader in = null;
|
||||||
|
try {
|
||||||
|
URL realUrl = new URL(url);
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
|
||||||
|
conn.setConnectTimeout(5000);
|
||||||
|
conn.setReadTimeout(5000);
|
||||||
|
conn.setRequestMethod(method);
|
||||||
|
|
||||||
|
// request headers
|
||||||
|
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
||||||
|
conn.setRequestProperty(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// request body
|
||||||
|
Map<String, Boolean> methods = new HashMap<>();
|
||||||
|
methods.put("POST", true);
|
||||||
|
methods.put("PUT", true);
|
||||||
|
methods.put("PATCH", true);
|
||||||
|
Boolean hasBody = methods.get(method);
|
||||||
|
if (hasBody != null) {
|
||||||
|
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
|
||||||
|
out.writeBytes(bodyParamStr);
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 定义 BufferedReader输入流来读取URL的响应
|
||||||
|
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
|
String line;
|
||||||
|
String result = "";
|
||||||
|
while ((line = in.readLine()) != null) {
|
||||||
|
result += line;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (in != null) {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e2) {
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user