完成接收白鹭分和新市民验证接口
This commit is contained in:
13
code/console/newcitizen/src/main/java/com/cpic/xim/App.java
Normal file
13
code/console/newcitizen/src/main/java/com/cpic/xim/App.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.cpic.xim;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
|
||||
package com.cpic.xim.utils.config;
|
||||
|
||||
public class EncryptionParameters
|
||||
{
|
||||
private static String SECRET_KEY = "9ILpXKFSHckH1g7h";
|
||||
private static String KEY = "2d716d5c7b35d5c0d41199eb0fd789ca";
|
||||
|
||||
public static String getSecretKey()
|
||||
{
|
||||
return EncryptionParameters.SECRET_KEY;
|
||||
}
|
||||
|
||||
public static String getKey()
|
||||
{
|
||||
return EncryptionParameters.KEY;
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2023-05-25 11:14:03
|
||||
* @LastEditors: Kane
|
||||
* @FilePath: /NewCitizenQueryResult/src/main/java/com/cpic/xim/utils/decryption/DecryptionUtils.java
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
package com.cpic.xim.utils.decryption;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import sun.misc.BASE64Decoder;
|
||||
|
||||
public class CdpDecryptUtil
|
||||
{
|
||||
public CdpDecryptUtil()
|
||||
{}
|
||||
|
||||
private static String aesDecryptByBytes( byte[] encryptBytes, String decryptKey )
|
||||
throws Exception
|
||||
{
|
||||
Cipher cipher = Cipher.getInstance( "AES/CBC/NoPadding" );
|
||||
SecretKeySpec keySpec = new SecretKeySpec( decryptKey.getBytes(), "AES" );
|
||||
IvParameterSpec ivSpec = new IvParameterSpec( decryptKey.getBytes() );
|
||||
|
||||
cipher.init( 2, keySpec, ivSpec );
|
||||
|
||||
byte[] decryptBytes = cipher.doFinal( encryptBytes );
|
||||
|
||||
String result = new String( decryptBytes );
|
||||
|
||||
if ( StringUtils.isNotBlank( result ) )
|
||||
{
|
||||
result = result.trim();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String aesDecrypt( String encryptStr, String decryptKey )
|
||||
throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
return StringUtils.isBlank( encryptStr ) ? null
|
||||
: aesDecryptByBytes( base64Decode( encryptStr ), decryptKey );
|
||||
}
|
||||
catch ( Exception var3 )
|
||||
{
|
||||
throw new Exception( "解密失败!" );
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] base64Decode( String base64Code ) throws Exception
|
||||
{
|
||||
return StringUtils.isBlank( base64Code ) ? null
|
||||
: (new BASE64Decoder()).decodeBuffer( base64Code );
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2023-05-25 11:13:17
|
||||
* @LastEditors: Kane
|
||||
* @FilePath: /NewCitizenQueryResult/src/main/java/com/cpic/xim/utils/encryption/EncryptionUtils.java
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
package com.cpic.xim.utils.encryption;
|
||||
|
||||
public class EncryptionUtils
|
||||
{
|
||||
static public String md5Hash( String value )
|
||||
{
|
||||
String result = "";
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
|
||||
package com.cpic.xim.utils.newcitizen;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class IdentifyResult
|
||||
{
|
||||
public IdentifyResult() {}
|
||||
|
||||
public String getCitizenType()
|
||||
{
|
||||
return citizenType;
|
||||
}
|
||||
|
||||
public void setCitizenType( String citizenType )
|
||||
{
|
||||
this.citizenType = citizenType;
|
||||
}
|
||||
|
||||
public String getExpireDate()
|
||||
{
|
||||
return expireDate;
|
||||
}
|
||||
|
||||
public void setExpireDate( String expireDate )
|
||||
{
|
||||
this.expireDate = expireDate;
|
||||
}
|
||||
|
||||
public String getScore()
|
||||
{
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore( String score )
|
||||
{
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
@JsonProperty("citizentype")
|
||||
private String citizenType;
|
||||
|
||||
@JsonProperty("expiredate")
|
||||
private String expireDate;
|
||||
|
||||
@JsonProperty("score")
|
||||
private String score;
|
||||
}
|
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2023-05-25 15:26:09
|
||||
* @LastEditors: Kane
|
||||
* @FilePath: /newcitizen/src/main/java/com/cpic/xim/utils/newcitizen/NewCitizenUitls.java
|
||||
* @Description: 新市民认证相关的工具方法
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
package com.cpic.xim.utils.newcitizen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import com.cdp.product.security.decode.CdpDecryptUtil;
|
||||
import com.cdp.product.security.encode.CdpEncryptUtil;
|
||||
import com.cdp.product.security.sign.CdpSignUtil;
|
||||
import com.cpic.xim.utils.config.EncryptionParameters;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class NewCitizenUitls
|
||||
{
|
||||
// 请求地址
|
||||
private static String identifyURL = "https://api.xmcic.cn:51888/government/economic/352";
|
||||
|
||||
/**
|
||||
* 新市民验证
|
||||
* @param idCardNo 身份证号码
|
||||
* @param name 姓名
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static IdentifyResult identifyNewCitizen( String idCardNo, String name ) throws Exception
|
||||
{
|
||||
String secretKey = EncryptionParameters.getSecretKey();
|
||||
String key = EncryptionParameters.getKey();
|
||||
String pushURL = "http://222.76.244.118:11101/NewCitizen/save_score.do";
|
||||
|
||||
Map<String, String> param = new HashMap<String, String>();
|
||||
|
||||
param.put( "authorized", CdpEncryptUtil.aesEncrypt( "1", secretKey ) );
|
||||
param.put( "idcard", CdpEncryptUtil.aesEncrypt( idCardNo, secretKey ) );
|
||||
param.put( "name", CdpEncryptUtil.aesEncrypt( name, secretKey ) );
|
||||
param.put( "pushurl", CdpEncryptUtil.aesEncrypt( pushURL, secretKey ) );
|
||||
param.put( "timestamp",
|
||||
CdpEncryptUtil.aesEncrypt( System.currentTimeMillis() + "", secretKey ) );
|
||||
|
||||
String sign = CdpSignUtil.sign( param );
|
||||
Map<String, String> params = new HashMap<>();
|
||||
|
||||
params.putAll( param );
|
||||
params.put( "key", key );
|
||||
params.put("sign", sign);
|
||||
|
||||
String resultJSON = sendPost( identifyURL, params);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
ResponseResult response = mapper.readValue( resultJSON, ResponseResult.class );
|
||||
|
||||
// 请求结果解密,应为一个json
|
||||
String identifyJSON = CdpDecryptUtil.aesDecrypt(response.getData(), secretKey);
|
||||
|
||||
IdentifyResult identifyResult = mapper.readValue( identifyJSON, IdentifyResult.class );
|
||||
|
||||
return identifyResult;
|
||||
}
|
||||
|
||||
public static String sendPost( String url, Map<String, String> bodyMap )
|
||||
{
|
||||
HttpPost post = new HttpPost( url );
|
||||
|
||||
try
|
||||
{
|
||||
// 创建参数集合
|
||||
List<BasicNameValuePair> list = new ArrayList<>();
|
||||
// 添加参数
|
||||
if ( bodyMap != null )
|
||||
{
|
||||
for ( String str : bodyMap.keySet() )
|
||||
{
|
||||
list.add( new BasicNameValuePair( str, bodyMap.get( str ) ) );
|
||||
}
|
||||
}
|
||||
// 把参数放入请求对象,post发送的参数list,指定格式
|
||||
post.setEntity( new UrlEncodedFormEntity( list, "UTF-8" ) );
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
// 启动执行请求,并获得返回值
|
||||
CloseableHttpResponse response = client.execute( post );
|
||||
// 得到返回的entity对象
|
||||
HttpEntity entity = response.getEntity();
|
||||
// 把实体对象转换为string
|
||||
return EntityUtils.toString( entity, "UTF-8" );
|
||||
}
|
||||
catch ( Exception e1 )
|
||||
{
|
||||
e1.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ResponseResult
|
||||
{
|
||||
public ResponseResult() {}
|
||||
|
||||
public String getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode( String code )
|
||||
{
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage( String message )
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getData()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData( String data )
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getSeqNo()
|
||||
{
|
||||
return seqNo;
|
||||
}
|
||||
|
||||
public void setSeqNo( String seqNo )
|
||||
{
|
||||
this.seqNo = seqNo;
|
||||
}
|
||||
|
||||
@JsonProperty("code")
|
||||
private String code;
|
||||
|
||||
@JsonProperty("message")
|
||||
private String message;
|
||||
|
||||
@JsonProperty("data")
|
||||
private String data;
|
||||
|
||||
@JsonProperty("seqNo")
|
||||
private String seqNo;
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2023-05-25 15:17:49
|
||||
* @LastEditors: Kane
|
||||
* @FilePath: /NewCitizenQueryResult/src/main/java/com/cpic/xim/web/controllers/NewCitizen/IdentifyNewCitizenRequest.java
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
package com.cpic.xim.web.controllers.NewCitizen;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class IdentifyNewCitizenRequest
|
||||
{
|
||||
public IdentifyNewCitizenRequest() {}
|
||||
|
||||
public String getIdCardNo()
|
||||
{
|
||||
return idCardNo;
|
||||
}
|
||||
|
||||
public void setIdCardNo( String idCardNo )
|
||||
{
|
||||
this.idCardNo = idCardNo;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@JsonProperty("idcard_no")
|
||||
private String idCardNo;
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
|
||||
package com.cpic.xim.web.controllers.NewCitizen;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
// 9ILpXKFSHckH1g7h
|
||||
|
||||
@Controller
|
||||
public class QueryResultController
|
||||
{
|
||||
@RequestMapping("/save_score.do")
|
||||
public void saveQueryResult(HttpServletResponse response, @RequestBody QueryResultRequest result )
|
||||
{
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
}
|
||||
|
||||
@RequestMapping("/identify.do")
|
||||
public void identifyNewCitizen(@RequestBody IdentifyNewCitizenRequest request )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
|
||||
package com.cpic.xim.web.controllers.NewCitizen;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class QueryResultRequest
|
||||
{
|
||||
public QueryResultRequest() {}
|
||||
|
||||
|
||||
public String getIdCardMD5()
|
||||
{
|
||||
return idCardMD5;
|
||||
}
|
||||
|
||||
public void setIdCardMD5( String idCardMD5 )
|
||||
{
|
||||
this.idCardMD5 = idCardMD5;
|
||||
}
|
||||
|
||||
public String getScore()
|
||||
{
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore( String score )
|
||||
{
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@JsonProperty("idcardmd5")
|
||||
private String idCardMD5;
|
||||
|
||||
@JsonProperty("score")
|
||||
private String score;
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2023-05-25 11:02:53
|
||||
* @LastEditors: Kane
|
||||
* @FilePath: /NewCitizenQueryResult/src/main/java/com/cpic/xim/web/filters/CrosFilter.java
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
|
||||
package com.cpic.xim.web.filters;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
public class CrosFilter implements Filter
|
||||
{
|
||||
@Override
|
||||
public void doFilter( ServletRequest req, ServletResponse resp, FilterChain chain )
|
||||
throws ServletException, IOException
|
||||
{
|
||||
HttpServletRequest request = (HttpServletRequest) req;
|
||||
HttpServletResponse response = (HttpServletResponse) resp;
|
||||
String method = request.getMethod();
|
||||
String originHeader = request.getHeader( "Origin" );
|
||||
|
||||
System.out.println( "收到" + method + "请求,来自" + originHeader);
|
||||
|
||||
// 如果是Options请求
|
||||
if ( method.equals(HttpMethod.OPTIONS.toString()) )
|
||||
{
|
||||
originHeader = "*";
|
||||
}
|
||||
|
||||
response.setHeader( "Access-Control-Allow-Origin", originHeader );
|
||||
response.setHeader( "Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT" );
|
||||
response.setHeader( "Access-Control-Max-Age", "0" );
|
||||
response.setHeader( "Access-Control-Allow-Headers",
|
||||
"Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With,userId,token" );
|
||||
response.setHeader( "Access-Control-Allow-Credentials", "true" );
|
||||
response.setHeader( "XDomainRequestAllowed", "1" );
|
||||
response.setHeader( "XDomainRequestAllowed", "1" );
|
||||
|
||||
chain.doFilter( request, response );
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2023-05-25 10:36:14
|
||||
* @LastEditors: Kane
|
||||
* @FilePath: /newcitizen/src/test/java/com/cpic/xim/test/NewCitizenQueryResultTest.java
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
package com.cpic.xim.test;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
|
||||
import org.apache.shiro.crypto.hash.Md5Hash;
|
||||
import com.cpic.xim.utils.newcitizen.NewCitizenUitls;
|
||||
import com.cpic.xim.utils.newcitizen.IdentifyResult;
|
||||
|
||||
public class NewCitizenQueryResultTest
|
||||
{
|
||||
@Test
|
||||
public void testSaveQueryResult()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMd5Hash()
|
||||
{
|
||||
String idCardNo = "350402198106130016";
|
||||
|
||||
Md5Hash idCardNoHash = new Md5Hash( idCardNo );
|
||||
|
||||
System.out.println( "身份证hash值:" + idCardNoHash.toString() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdentify()
|
||||
{
|
||||
try
|
||||
{
|
||||
IdentifyResult result = NewCitizenUitls.identifyNewCitizen( "350402198106130016", "王炜" );
|
||||
}
|
||||
catch ( Exception error )
|
||||
{
|
||||
System.out.println(error.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user