Commit c4b9e2e8 authored by xiachenqi's avatar xiachenqi

第一次提交

parent 1dfac44d
......@@ -7,10 +7,11 @@
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="CTIDHTTPService" />
<module name="LegalPersonChapter" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="CTIDHTTPService" target="1.5" />
<module name="LegalPersonChapter" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
<option name="TOP_LEVEL_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="INNER_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="METHOD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
</value>
</option>
<option name="FIELD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
<option name="myAdditionalJavadocTags" value="date" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JUnitGeneratorProjectSettings">
<option name="selectedTemplateKey" value="JUnit 4" />
</component>
</project>
\ No newline at end of file
......@@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/CTIDHTTPService.iml" filepath="$PROJECT_DIR$/CTIDHTTPService.iml" />
<module fileurl="file://$PROJECT_DIR$/LegalPersonChapter.iml" filepath="$PROJECT_DIR$/LegalPersonChapter.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
......@@ -9,7 +9,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
......
......@@ -9,6 +9,8 @@
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jettyVersion>9.3.18.v20170406</jettyVersion>
<jerseyVersion>2.10</jerseyVersion>
<httpClientVersion>4.5.3</httpClientVersion>
......
Manifest-Version: 1.0
Main-Class: com.fri.http.rest.server.YXHttpRestServer
package com.fri.http.rest.config;
package com.fri.http.framework.config;
/**
......@@ -18,7 +18,7 @@ public class YXDefaultServerConfig {
//Servlet 路径
public static String SERVER_REST_ROOT_PATH = "/rest";
public static String SERVER_REST_ROOT_PATH = "/framework";
public static String SERVER_MONITOR_PATH = "/status";
public static String SERVER_CTID_IDENTITY_PATH = "/ctid";
......
package com.fri.http.rest.connections;
package com.fri.http.framework.connections;
/**
* Created by zhangdahui on 2017/5/1.
......
package com.fri.http.rest.connections;
package com.fri.http.framework.connections;
/**
* Created by zhangdahui on 2017/5/1.
......
package com.fri.http.rest.connections;
package com.fri.http.framework.connections;
/**
* Created by zhangdahui on 2017/5/1.
......
package com.fri.http.rest.connections;
package com.fri.http.framework.connections;
import com.fri.http.rest.response.YXJSONResponse;
import com.fri.http.framework.response.YXJSONResponse;
import org.apache.http.*;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
......
package com.fri.http.rest.connections;
package com.fri.http.framework.connections;
/**
* Created by zhangdahui on 2017/5/1.
......
package com.fri.http.rest.logging;
package com.fri.http.framework.logging;
import com.fri.http.rest.config.YXDefaultServerConfig;
import com.fri.http.rest.utils.TimeUtils;
import com.fri.http.framework.config.YXDefaultServerConfig;
import com.fri.http.framework.utils.TimeUtils;
import java.io.IOException;
import java.util.HashMap;
......
package com.fri.http.framework.resources;
import com.fri.http.framework.config.YXDefaultServerConfig;
import com.fri.http.framework.logging.YXLogging;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.logging.Logger;
/**
* Created by lixiaoyang on 4/27/17.
* 版本
* v1.0/auth_app
* v1.0/authen_req
*/
@Path("v2.0")
public class CTIDHTTPRestResources {
private Logger logger = YXLogging.getLogger(YXDefaultServerConfig.LOGGING_NAME_REQUEST_SERVER);
@POST
@Path("authen_req")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
/**
* 接收带有 JSON Body 的POST请求,非Form模式
*/
public String postRandomBody(String jsonStr) throws Exception {
logger.info(jsonStr);
return "身份认证申请v2.0的响应json字符串";
}
@POST
@Path("auth_app")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
/**
* 接收带有 JSON Body 的POST请求,非Form模式
*/
public String postIdentityBody(String jsonStr) throws Exception {
logger.info(jsonStr);
return "身份认证结果v2.0的响应json字符串";
}
}
\ No newline at end of file
package com.fri.http.framework.resources;
import com.fri.http.framework.config.YXDefaultServerConfig;
import com.fri.http.framework.logging.YXLogging;
import com.fri.http.legalchapter.rzfw.auth.AuthApply;
import com.fri.http.legalchapter.rzfw.auth.AuthRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.logging.Logger;
/**
* Created by lixiaoyang on 4/27/17.
* 版本
* v1.0/auth_app
* v1.0/authen_req
*/
@Path("v2.0")
public class CTIDRestResources {
private Logger logger = YXLogging.getLogger(YXDefaultServerConfig.LOGGING_NAME_REQUEST_SERVER);
@POST
@Path("auth_app")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
/**
* 认证申请
* 接收带有 JSON Body 的POST请求,非Form模式
*/
public String authAppForward(String jsonStr) throws Exception {
logger.info(jsonStr);
//执行认证申请 获取响应结果
String response=new AuthApply().authApplyExecute(jsonStr);
return response;
}
@POST
@Path("authen_req")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
/**
* 认证请求
* 接收带有 JSON Body 的POST请求,非Form模式
*/
public String authReqForward(String jsonStr) throws Exception {
logger.info(jsonStr);
// YXJSONResponse sta = new YXJSONResponse();
// JSONObject randomResponseObj = new CTIDServer().passRandomData(jsonStr);
// logger2.info(randomResponseObj.toString());
// return sta.outPutSuccess(randomResponseObj).toJSONString();
//认证请求结果
String response= new AuthRequest().authRequestExecute(jsonStr);
return response;
}
}
\ No newline at end of file
package com.fri.http.rest.resources;
package com.fri.http.framework.resources;
import com.fri.http.rest.config.YXDefaultServerConfig;
import com.fri.http.rest.connections.HttpClientPool;
import com.fri.http.rest.logging.YXLogging;
import com.fri.http.rest.response.YXJSONResponse;
import com.fri.http.rest.server.YXHttpRestServer;
import com.fri.http.framework.config.YXDefaultServerConfig;
import com.fri.http.framework.connections.HttpClientPool;
import com.fri.http.framework.logging.YXLogging;
import com.fri.http.framework.response.YXJSONResponse;
import com.fri.http.framework.server.YXHttpRestServer;
import net.sf.json.JSONObject;
import org.eclipse.jetty.server.ServerConnector;
import org.omg.CORBA.Any;
......
package com.fri.http.rest.resources;
package com.fri.http.framework.resources;
import com.fri.http.rest.config.YXDefaultServerConfig;
import com.fri.http.rest.logging.YXLogging;
import com.fri.http.rest.server.YXHttpRestServer;
import com.fri.http.rest.response.YXJSONResponse;
import com.fri.http.framework.config.YXDefaultServerConfig;
import com.fri.http.framework.logging.YXLogging;
import com.fri.http.framework.server.YXHttpRestServer;
import com.fri.http.framework.response.YXJSONResponse;
import org.eclipse.jetty.server.ServerConnector;
import org.omg.CORBA.Any;
......
package com.fri.http.rest.response;
package com.fri.http.framework.response;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
......
package com.fri.http.rest.server;
package com.fri.http.framework.server;
import com.fri.http.rest.config.YXDefaultServerConfig;
import com.fri.http.rest.connections.HttpClientPool;
import com.fri.http.rest.logging.YXLogging;
import com.fri.http.rest.resources.YXRestResources;
import com.fri.http.rest.resources.CTIDRestResources;
import com.fri.http.rest.resources.YXServerStatus;
import com.fri.http.rest.utils.TimeUtils;
import com.fri.http.framework.config.YXDefaultServerConfig;
import com.fri.http.framework.connections.HttpClientPool;
import com.fri.http.framework.logging.YXLogging;
import com.fri.http.framework.resources.YXRestResources;
import com.fri.http.framework.resources.CTIDRestResources;
import com.fri.http.framework.resources.YXServerStatus;
import com.fri.http.framework.utils.TimeUtils;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
......@@ -92,7 +92,7 @@ public class YXHttpRestServer {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
//The following code show how to add two or more rest services in http server
//The following code show how to add two or more framework services in http server
ServletHolder restServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, YXDefaultServerConfig.SERVER_REST_ROOT_PATH + "/*");
restServlet.setInitOrder(0);
restServlet.setInitParameter("jersey.config.server.provider.classnames", YXRestResources.class.getCanonicalName());
......
package com.fri.http.rest.utils;
package com.fri.http.framework.utils;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
......
package com.fri.http.rest.utils;
package com.fri.http.framework.utils;
/**
* Created by zhangdahui on 2017/5/1.
......
package com.fri.http.legalchapter.rzfw.auth;
import com.fri.http.framework.config.YXDefaultServerConfig;
import com.fri.http.framework.logging.YXLogging;
import com.fri.http.legalchapter.rzfw.data.AuthApplyResponse;
import com.fri.http.legalchapter.rzfw.data.AuthenticationApplicationData;
import com.fri.http.legalchapter.rzfw.data.SocketPackage;
import com.fri.http.legalchapter.rzfw.net.SocketSender;
import com.fri.http.legalchapter.rzfw.utils.Constans;
import com.fri.http.legalchapter.rzfw.utils.FormatBytesUtil;
import net.sf.json.JSONObject;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.logging.Logger;
/**
* Created by GavinLi 李晓阳 on 2017/12/24.
*/
public class AuthApply {
private Logger logger = YXLogging.getLogger(YXDefaultServerConfig.LOGGING_NAME_REQUEST_SERVER);
public String authApplyExecute(String authapplyJson){
/*
* 组装认证申请数据区 第一个包的数据区
*/
// 客户号 8字节 共用
byte[] customerId = Constans.customerId;
// 终端号 2字节 共用
byte[] terminalId = Constans.terminalId;
// 读卡控件版本 4字节
byte[] readCardControlsVersion = new byte[] { 1, 2, 3, 4 };
// 人像控件版本 4字节
byte[] pictureControlsVersion = new byte[] { 1, 2, 3, 4 };
//证书标识
byte[] certificateNumber=Constans.certificateNumber;
//业务站点
logger.info("证书序列号:" + Arrays.toString(certificateNumber));
// System.out.println("证书序列号:" + Arrays.toString(certificateNumber));
AuthenticationApplicationData auApp = new AuthenticationApplicationData(customerId, terminalId,
readCardControlsVersion, pictureControlsVersion, certificateNumber);
byte[] auAppData = auApp.getAuthenticationApplicationData();
/*
* 组装认证申请Socket数据包 第一次UDP数据包
*/
// 协议版本 2字节 0x0001 共用
byte[] version = { 0, 1 };
// 命令类型 1字节 0x00(请求)0x01(应答) 共用
byte[] commandType = { 0 };
// 命令 1字节 0x00(身份认证申请)0x01(身份认证) 共用但值不同
byte[] command = { 0 };
// 命令内容 1字节 保留 0x00 共用
byte[] commandContent = { 0 };
// 操作 1字节 保留 0x00 共用
byte[] operation = { 0 };
SocketPackage auAppSP = new SocketPackage(version, commandType, command, commandContent, operation, auAppData);
byte[] auAppSPData = auAppSP.getSocketPackage();
byte[] applicationReturn = SocketSender.sendSocketPackage(auAppSPData);
AuthApplyResponse response= new AuthApplyResponse();
/*
* 组装认证数据区 第二个包的数据区
*/
byte[] streamNumber = null;
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date=df.format(new Date());
if (applicationReturn != null) {
streamNumber = Arrays.copyOfRange(applicationReturn, 24, 33);// 获取到业务流水号要组装进第二个数据包中
//业务流水号
response.setBusinessSerialNumber(FormatBytesUtil.bytesToHexString(streamNumber));
System.out.println("流水号:"+FormatBytesUtil.bytesToHexString(streamNumber));
short randomBytesLength = FormatBytesUtil.getShortFromBytes(Arrays.copyOfRange(applicationReturn, 33, 35)); // 获取随机数长度
String randomData = FormatBytesUtil
.bytesToHexString(Arrays.copyOfRange(applicationReturn, 35, 35 + randomBytesLength)); // 获取随机数数据
System.out.println("随机数长度:" + randomBytesLength);
System.out.println("随机数数据:" + randomData);
//随机数
response.setRandomNumber(randomData);
//申请结果
response.setSuccess(true);
}
if (applicationReturn == null) {
//申请结果
response.setSuccess(false);
//错误结果
response.setErrorDesc("业务流水号获取失败,请重新获取");
System.out.println("获取流水号失败,认证失败。");
}
//响应时间
response.setTimeStamp(date);
String responseStr=JSONObject.fromObject(response).toString();
return responseStr;
}
}
package com.fri.http.legalchapter.rzfw.auth;
import com.fri.http.legalchapter.rzfw.data.*;
import com.fri.http.legalchapter.rzfw.net.SocketSender;
import com.fri.http.legalchapter.rzfw.utils.Constans;
import com.fri.http.legalchapter.rzfw.utils.FormatBytesUtil;
import net.sf.json.JSONObject;
import sun.misc.BASE64Decoder;
import java.io.IOException;
import java.util.Arrays;
/**
* Created by GavinLi 李晓阳 on 2017/12/24.
*/
public class AuthRequest {
private byte[] reservationTwo=null;
private byte[] reservationFour=null;
private byte[] picture=null;
private byte[] authCode=null;
private byte[] idcardAuthData=null;
private byte[] auData=null;
private Boolean success=false;
private String errorDesc="UnKnow Error";
public String authRequestExecute(String authRequestJson){
JSONObject authRequest= JSONObject.fromObject(authRequestJson);
AuthRequestBean authRequestBean= (AuthRequestBean) JSONObject.toBean(authRequest, AuthRequestBean.class);
//获取业务流水号 HexString类型
String businessSerialNumber= authRequestBean.getBusinessSerialNumber();
//业务流水号
byte[] streamNumber= FormatBytesUtil.hexStringToBytes(businessSerialNumber);
//客户号
byte[] customerId=Constans.customerId;
//终端号
byte[] terminalId=Constans.terminalId;
//证书标识
byte[] certificateNumber=Constans.certificateNumber;
//认证保留数据
String authApplyRetainData = authRequestBean.getAuthApplyRetainData();
//获取ID验证数据
try {
idcardAuthData= excuteBase64Decode(authRequestBean.getIdcardAuthData());
} catch (IOException e) {
System.out.println("ID验证数据编码解析出错");
success=false;
errorDesc="ID验证数据编码解析出错,检查ID验证数据";
e.printStackTrace();
}
//获取人像
try {
picture = excuteBase64Decode(authRequestBean.getPhotoData());
} catch (IOException e) {
System.out.println("人像编码解析出错");
success=false;
errorDesc="人像编码解析出错,检查人像数据";
e.printStackTrace();
}
//获取认证码
try {
authCode = excuteBase64Decode(authRequestBean.getAuthCode());
} catch (IOException e) {
System.out.println("认证码解析出错");
success=false;
errorDesc="认证码解析出错,检查认证码数据";
e.printStackTrace();
}
//认证模式
String mode=authRequestBean.getAuthMode();
switch (mode){
case "0x42":
/**
* 0x42
*/
//获取两项信息
getReservationTwo(authApplyRetainData);
byte[] identityModel_0X42 = new byte[] { 0x42 };
AuthenticationData au_0X42 = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X42,
null, null, picture, reservationTwo, certificateNumber);
auData = au_0X42.getAuthenticationData();
break;
case "0x40":
/**
* 0x40
*/
//获取两项信息
getReservationTwo(authApplyRetainData);
byte[] identityModel_0X40 = new byte[] { 0x40 };
AuthenticationData au_0X40 = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X40,
null, null, null, reservationTwo, certificateNumber);
auData = au_0X40.getAuthenticationData();
break;
case "0x0f":
/**
* 0X0F
*/
byte[] identityModel_0X0F = new byte[] { 0x0f };
AuthenticationData au_0X0F = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X0F,
idcardAuthData, authCode, picture, null, certificateNumber);
auData = au_0X0F.getAuthenticationData();
break;
case "0x4f":
/**
* 0X4F
*/
//获取两项信息
getReservationTwo(authApplyRetainData);
byte[] identityModel_0X4F = new byte[] { 0x4f };
AuthenticationData au_0X4F = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X4F,
idcardAuthData, authCode, picture, reservationTwo, certificateNumber);
auData = au_0X4F.getAuthenticationData();
break;
case "0x13":
/**
* 0X13
*/
//获取四项信息
getReservationFour(authApplyRetainData);
byte[] identityModel_0X13 = new byte[] { 0x13 };
AuthenticationData au_0X13 = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X13,
idcardAuthData,null, picture, reservationFour, certificateNumber);
auData = au_0X13.getAuthenticationData();
case "0x1F":
/**
* 0X1F
*/
//获取四项信息
getReservationFour(authApplyRetainData);
byte[] identityModel_0X1F = new byte[] { 0x1f };
AuthenticationData au_0X1F = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X1F,
idcardAuthData, authCode, picture, reservationFour, certificateNumber);
auData = au_0X1F.getAuthenticationData();
break;
}
/*
* 组装认证Socket数据包 第二次UDP数据包
*/
// 协议版本 2字节 0x0001 共用
byte[] version = { 0, 1 };
// 命令类型 1字节 0x00(请求)0x01(应答) 共用
byte[] commandType = { 0 };
// 命令内容 1字节 保留 0x00 共用
byte[] commandContent = { 0 };
// 操作 1字节 保留 0x00 共用
byte[] operation = { 0 };
// 命令 1字节 0x00(身份认证申请)0x01(身份认证) 共用但值不同
byte[] command = { 1 };// 命令 1字节 0x00(身份认证申请)0x01(身份认证) 修改值的内容为1
SocketPackage auSP = new SocketPackage(version, commandType, command, commandContent, operation, auData);
byte[] auSPData = auSP.getSocketPackage();
byte[] auReturn = SocketSender.sendSocketPackage(auSPData);
AuthResponse authRes=new AuthResponse();
//设置业务流水号
authRes.setBusinessSerialNumber(businessSerialNumber);
if (auReturn != null) {
System.out.println("响应结果:"+ Arrays.toString(auReturn));
System.out.println("验签结果:" + DataSignature.signCheck(auReturn)); // 验签
String authResult = new String(Arrays.copyOfRange(auReturn, 33, 37));
System.out.print("认证结果:" + authResult);
authRes.setAuthResult(authResult);
success=true;
errorDesc="";
}
authRes.setSuccess(success);
authRes.setErrorDesc(errorDesc);
String authResStr=JSONObject.fromObject(authRes).toString();
return authResStr;
}
public void getReservationTwo(String retainDate){
JSONObject retainData= JSONObject.fromObject(retainDate);
String name=retainData.getString(Constans.name);
String idNumber=retainData.getString(Constans.idNumber);
reservationTwo = new ReservationData(name, idNumber, null, null).getReservasionBytes(); // 生成两项保留数据
}
public void getReservationFour(String retainDate){
JSONObject retainData= JSONObject.fromObject(retainDate);
String name=retainData.getString(Constans.name);
String idNumber=retainData.getString(Constans.idNumber);
String enableDate=retainData.getString(Constans.enableDate);
String expireDate=retainData.getString(Constans.expireDate);
reservationFour = new ReservationData(name, idNumber, enableDate, expireDate)
.getReservasionBytes(); // 生成四项保留数据
}
public byte[] excuteBase64Decode(String encodeData) throws IOException {
byte[] originalData= new BASE64Decoder().decodeBuffer(encodeData);
return originalData;
}
}
package com.fri.http.legalchapter.rzfw.data;
/**
* Created by GavinLi 李晓阳 on 2017/12/24.
*/
public class AuthApplyResponse {
/**
* customerNumber : LegalPersonChapter001
* appName : fripolice001
* timeStamp : 20171224
* businessSerialNumber : 410DEFAAAAAAA
* randomNumber : 410DEFAAAAAAA
* success : true
* errorDesc :
*/
private String customerNumber = "";
private String appName = "";
private String timeStamp;
private String businessSerialNumber;
private String randomNumber;
private boolean success = false;
private String errorDesc = "";
public String getCustomerNumber() {
return customerNumber;
}
public void setCustomerNumber(String customerNumber) {
this.customerNumber = customerNumber;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
public String getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
public String getBusinessSerialNumber() {
return businessSerialNumber;
}
public void setBusinessSerialNumber(String businessSerialNumber) {
this.businessSerialNumber = businessSerialNumber;
}
public String getRandomNumber() {
return randomNumber;
}
public void setRandomNumber(String randomNumber) {
this.randomNumber = randomNumber;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getErrorDesc() {
return errorDesc;
}
public void setErrorDesc(String errorDesc) {
this.errorDesc = errorDesc;
}
}
package com.fri.http.legalchapter.rzfw.data;
/**
* Created by GavinLi 李晓阳 on 2017/12/25.
*/
public class AuthRequestBean {
/**
* customNumber :
* AppName :
* timeStamp :
* businessSerialNumber :
* authMode :
* photoData :
* authCode :
* idcardAuthData :
* authApplyRetainData :
*/
private String customNumber;
private String AppName;
private String timeStamp;
private String businessSerialNumber;
private String authMode;
private String photoData;
private String authCode;
private String idcardAuthData;
private String authApplyRetainData;
public String getCustomNumber() {
return customNumber;
}
public void setCustomNumber(String customNumber) {
this.customNumber = customNumber;
}
public String getAppName() {
return AppName;
}
public void setAppName(String AppName) {
this.AppName = AppName;
}
public String getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
public String getBusinessSerialNumber() {
return businessSerialNumber;
}
public void setBusinessSerialNumber(String businessSerialNumber) {
this.businessSerialNumber = businessSerialNumber;
}
public String getAuthMode() {
return authMode;
}
public void setAuthMode(String authMode) {
this.authMode = authMode;
}
public String getPhotoData() {
return photoData;
}
public void setPhotoData(String photoData) {
this.photoData = photoData;
}
public String getAuthCode() {
return authCode;
}
public void setAuthCode(String authCode) {
this.authCode = authCode;
}
public String getIdcardAuthData() {
return idcardAuthData;
}
public void setIdcardAuthData(String idcardAuthData) {
this.idcardAuthData = idcardAuthData;
}
public String getAuthApplyRetainData() {
return authApplyRetainData;
}
public void setAuthApplyRetainData(String authApplyRetainData) {
this.authApplyRetainData = authApplyRetainData;
}
}
package com.fri.http.legalchapter.rzfw.data;
/**
* Created by GavinLi 李晓阳 on 2017/12/25.
*/
public class AuthResponse {
/**
* customerNumber : LegalPersonChapter001
* appName : fripolice001
* timeStamp : 20171224
* businessSerialNumber : 410DEFAAAAAAA
* authResult : 0000
* authResultRetainData :
* success : true
* errorDesc :
*/
private String customerNumber;
private String appName;
private String timeStamp;
private String businessSerialNumber;
private String authResult;
private String authResultRetainData;
private boolean success;
private String errorDesc;
public String getCustomerNumber() {
return customerNumber;
}
public void setCustomerNumber(String customerNumber) {
this.customerNumber = customerNumber;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
public String getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
public String getBusinessSerialNumber() {
return businessSerialNumber;
}
public void setBusinessSerialNumber(String businessSerialNumber) {
this.businessSerialNumber = businessSerialNumber;
}
public String getAuthResult() {
return authResult;
}
public void setAuthResult(String authResult) {
this.authResult = authResult;
}
public String getAuthResultRetainData() {
return authResultRetainData;
}
public void setAuthResultRetainData(String authResultRetainData) {
this.authResultRetainData = authResultRetainData;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getErrorDesc() {
return errorDesc;
}
public void setErrorDesc(String errorDesc) {
this.errorDesc = errorDesc;
}
}
package com.fri.http.legalchapter.rzfw.data;
import com.fri.http.legalchapter.rzfw.utils.FormatBytesUtil;
import java.util.Arrays;
public class AuthenticationApplicationData {
// 客户号 8字节
private byte[] customerId;
// 终端号 2字节
private byte[] terminalId;
// 时间戳 4字节
private byte[] timestamp;
// 读卡控件版本 4字节
private byte[] readCardControlsVersion;
// 人像控件版本 4字节
private byte[] pictureControlsVersion;
// 证书序列号 32字节
private byte[] certificateNumber;
public AuthenticationApplicationData(byte[] customerId, byte[] terminalId, byte[] readCardControlsVersion,
byte[] pictureControlsVersion, byte[] certificateNumber) {
super();
this.customerId = customerId;
this.terminalId = terminalId;
this.timestamp = FormatBytesUtil.getTimestamp();
this.readCardControlsVersion = readCardControlsVersion;
this.pictureControlsVersion = pictureControlsVersion;
this.certificateNumber = certificateNumber;
}
public byte[] getAuthenticationApplicationData() {
byte[] data = FormatBytesUtil.concatAll(customerId, terminalId, timestamp, readCardControlsVersion,
pictureControlsVersion, certificateNumber);
System.out.println("身份认证申请数据区:" + Arrays.toString(data));
return data;
}
}
package com.fri.http.legalchapter.rzfw.data;
import com.fri.http.legalchapter.rzfw.utils.FormatBytesUtil;
import java.util.Arrays;
public class AuthenticationData {
// 客户号 8字节
private byte[] customerId;
// 终端号 2字节
private byte[] terminalId;
// 时间戳 4字节
private byte[] timestamp;
// 业务流水号 9字节
private byte[] streamNumber;
// 认证模式 1字节
private byte[] identityModel;
// ID验证数据字段及认证吗数据字段总长 2字节
private byte[] lengthOfTwo;
// ID验证数据长度 2字节
private byte[] lengthOfIdCheck;
// ID验证数据 变长 可为空
private byte[] idCheck;
// 认证码数据长度 2字节
private byte[] lengthOfVerification;
// 认证码数据 变长 可为空
private byte[] verification;
// 照片长度 4字节
private byte[] lengthOfPicture;
// 照片数据 变长 可为空
private byte[] picture;
// 认证申请保留数据长度 2字节
private byte[] lengthOfReservasion;
// 认证申请保留数据 变长 可为空
private byte[] reservation;
// 证书序列号 32字节
private byte[] certificateNumber;
public AuthenticationData(byte[] customerId, byte[] terminalId, byte[] streamNumber, byte[] identityModel,
byte[] idCheck, byte[] verification, byte[] picture, byte[] reservation, byte[] certificateNumber) {
super();
this.customerId = customerId;
this.terminalId = terminalId;
this.timestamp = FormatBytesUtil.getTimestamp();
this.streamNumber = streamNumber;
this.identityModel = identityModel;
int idCheckLengthTemp = 0;
int verificationLengthTemp = 0;
this.lengthOfIdCheck = new byte[] { 0, 0 };
if (idCheck != null) {
idCheckLengthTemp = idCheck.length;
this.lengthOfIdCheck = FormatBytesUtil.getByteOfShort((short) idCheck.length);
}
this.idCheck = idCheck;
this.lengthOfVerification = new byte[] { 0, 0 };
if (verification != null) {
verificationLengthTemp = verification.length;
this.lengthOfVerification = FormatBytesUtil.getByteOfShort((short) verification.length);
}
this.verification = verification;
this.lengthOfTwo = FormatBytesUtil.getByteOfShort((short) (idCheckLengthTemp + verificationLengthTemp + 4));
this.lengthOfPicture = new byte[] { 0, 0, 0, 0 };
if (picture != null) {
this.lengthOfPicture = FormatBytesUtil.getBytesOfInt(picture.length);
}
this.picture = picture;
this.lengthOfReservasion = new byte[] { 0, 0 };
if (reservation != null) {
this.lengthOfReservasion = FormatBytesUtil.getByteOfShort((short) reservation.length);
}
this.reservation = reservation;
this.certificateNumber = certificateNumber;
}
public byte[] getAuthenticationData() {
byte[] data = FormatBytesUtil.concatAll(customerId, terminalId, timestamp, streamNumber, identityModel,
lengthOfTwo, lengthOfIdCheck, idCheck, lengthOfVerification, verification, lengthOfPicture, picture,
lengthOfReservasion, reservation, certificateNumber);
System.out.println("身份认证数据区:" + Arrays.toString(data));
return data;
}
}
package com.fri.http.legalchapter.rzfw.data;
import java.util.Arrays;
import cn.com.jit.assp.css.client.util.Base64;
import cn.com.jit.assp.dsign.DSign;
import com.fri.http.legalchapter.rzfw.utils.Constans;
import com.fri.http.legalchapter.rzfw.utils.FormatBytesUtil;
public class DataSignature {
public static byte[] signature(byte[] data) {
DSign dSign = new DSign();
DSign.init("./config/cssconfig.properties");
String signResultString = dSign.p1Sign(Constans.strDN, Constans.strDigestAlg, data);
byte[] signResultByte = Base64.decode(signResultString);
return signResultByte;
}
public static boolean signCheck(byte[] dataPackage) {
byte[] dataLengthByte = Arrays.copyOfRange(dataPackage, 6, 10);
// 数据区长度
int dataLength = FormatBytesUtil.getIntFromBytes(dataLengthByte);
// 被签名数据
byte[] data = Arrays.copyOfRange(dataPackage, 0, 10 + dataLength);
// 签名长度数据
byte[] signatureLengthByte = Arrays.copyOfRange(dataPackage, 10 + dataLength, 11 + dataLength);
// 签名长度
int signatureLength = signatureLengthByte[0];
// 签名数据
byte[] signatureByte = Arrays.copyOfRange(dataPackage, 11 + dataLength, 11 + dataLength + signatureLength);
// 证书
byte[] zhengshu = Arrays.copyOfRange(data, data.length - 32, data.length);
DSign ds = new DSign();
DSign.init("./config/cssconfig.properties");
String certID = new String(zhengshu).trim();
System.out.println("证书序列号:" + certID);
String strDigetsAlg = "sm3";
long a = ds.p1Verify(certID, strDigetsAlg, Base64.encode(signatureByte), data);
if (a == 0) {
return true;
}
System.out.println("错误号为:" + ds.getErrorCode());
System.out.println("错误描述:" + ds.getErrorMessage());
return false;
}
}
package com.fri.http.legalchapter.rzfw.data;
import java.io.UnsupportedEncodingException;
import cn.com.jit.assp.dsign.DSign;
import com.fri.http.legalchapter.rzfw.utils.FormatBytesUtil;
public class ReservationData {
// 姓名
private String name;
// 身份证号
private String idNumber;
// 有效期起
private String validFrom;
// 有效期止
private String validEnd;
/*
* 网站上传信息 JSON字符串 必填 String jsonStr =
* "{'vendorIp':'202.211.100.100','venderName':'rzfw','businessType':'test','dealDate':'20161202'}";
*/
private byte[] updataInfo_JSON = new byte[] { 123, 39, 118, 101, 110, 100, 111, 114, 73, 112, 39, 58, 39, 50, 48,
50, 46, 50, 49, 49, 46, 49, 48, 48, 46, 49, 48, 48, 39, 44, 39, 118, 101, 110, 100, 101, 114, 78, 97, 109,
101, 39, 58, 39, 121, 105, 110, 103, 120, 105, 110, 105, 110, 102, 111, 39, 44, 39, 98, 117, 115, 105, 110,
101, 115, 115, 84, 121, 112, 101, 39, 58, 39, 116, 101, 115, 116, 39, 44, 39, 100, 101, 97, 108, 68, 97,
116, 101, 39, 58, 39, 50, 48, 49, 54, 49, 50, 48, 50, 39, 125 };
String json="";
public ReservationData(String name, String idNumber, String validFrom, String validEnd) {
super();
this.name = name;
this.idNumber = idNumber;
this.validFrom = validFrom;
this.validEnd = validEnd;
}
public byte[] getReservasionBytes() {
// 各项信息长度固定
byte[] nameByte = new byte[45];
byte[] idNumberByte = new byte[18];
byte[] validFromByte = new byte[8];
byte[] validEndByte = new byte[8];
try {
// 姓名以UTF-8格式转换为byte[]
nameByte = FormatBytesUtil.copyByteToAnother(nameByte, name.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
// 身份证号中含有字母"X"的,一律大写
idNumberByte = FormatBytesUtil.getBytesFromString(idNumberByte, idNumber);
if (validFrom != null) {
validFromByte = FormatBytesUtil.getBytesFromString(validFromByte, validFrom);
}
if (validEnd != null) {
validEndByte = FormatBytesUtil.getBytesFromString(validEndByte, validEnd);
}
byte[] bytes = FormatBytesUtil.concatAll(nameByte, idNumberByte, validFromByte, validEndByte, updataInfo_JSON);
byte[] reservasionBytes = getDesign(bytes);
return reservasionBytes;
}
/**
* 通过签名服务器对保留数据单独进行加密
*
* @param bytes
* @return
*/
private byte[] getDesign(byte[] bytes) {
DSign dSign = new DSign();
String signReturn = null;
DSign.init("./config/cssconfig.properties");
// 正式线alias改成{ "rzfw01" }
String[] alias = { "rzfw01" };
signReturn = dSign.encryptEnvelop(alias, bytes);
if (signReturn != null) {
return signReturn.getBytes();
}
return null;
}
}
package com.fri.http.legalchapter.rzfw.data;
import com.fri.http.legalchapter.rzfw.utils.FormatBytesUtil;
import java.util.Arrays;
public class SocketPackage {
// 协议版本 2字节 0x0001
private byte[] version;
// 命令类型 1字节 0x00(请求)0x01(应答)
private byte[] commandType;
// 命令 1字节 0x00(身份认证申请)0x01(身份认证)
private byte[] command;
// 命令内容 1字节 保留 0x00
private byte[] commandContent;
// 操作 1字节 保留 0x00
private byte[] operation;
// 数据区长度 4字节
private byte[] dataLength;
// 数据区 变长
private byte[] data;
// 签名长度 1字节
private byte[] signatureLength;
// 签名 变长
private byte[] signature;
public SocketPackage(byte[] version, byte[] commandType, byte[] command, byte[] commandContent, byte[] operation,
byte[] data) {
super();
this.version = version;
this.commandType = commandType;
this.command = command;
this.commandContent = commandContent;
this.operation = operation;
this.dataLength = FormatBytesUtil.getBytesOfInt(data.length);
this.data = data;
}
public byte[] getSocketPackage() {
byte[] clearText = FormatBytesUtil.concatAll(version, commandType, command, commandContent, operation,
dataLength, data);
System.out.println("身份认证请求Socket数据原文:" + Arrays.toString(clearText));
byte[] cipherText = DataSignature.signature(clearText);
System.out.println("身份认证请求Socket数据签名:" + Arrays.toString(cipherText));
this.signatureLength = new byte[] { (byte) cipherText.length };
this.signature = cipherText;
byte[] socketPackage = FormatBytesUtil.concatAll(clearText, signatureLength, signature);
System.out.println("身份认证请求Socket数据报文:" + Arrays.toString(socketPackage));
return socketPackage;
}
}
package com.fri.http.legalchapter.rzfw.net;
import com.fri.http.legalchapter.rzfw.utils.Constans;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
public class SocketSender {
public static byte[] sendSocketPackage(byte[] socketPackage) {
DatagramPacket sendPacket = new DatagramPacket(socketPackage, socketPackage.length, Constans.ia, Constans.port);
DatagramPacket receivePacket = new DatagramPacket(new byte[300], 300);
try (DatagramSocket udpClient = new DatagramSocket()) {
udpClient.send(sendPacket);
udpClient.setSoTimeout(10000);
udpClient.receive(receivePacket);
return receivePacket.getData();
} catch (SocketException e) {
System.out.println("udpClient创建失败");
e.printStackTrace();
} catch (IOException e) {
System.out.println("send/receive调用失败");
e.printStackTrace();
}
return null;
}
}
package com.fri.http.legalchapter.rzfw.test;
import com.fri.http.legalchapter.rzfw.data.*;
import com.fri.http.legalchapter.rzfw.net.SocketSender;
import com.fri.http.legalchapter.rzfw.utils.Constans;
import com.fri.http.legalchapter.rzfw.utils.FormatBytesUtil;
import java.util.Arrays;
/**
* 身份认证测试Demo
*
* @author 夏晨棋
* @email xia794404765@gmail.com
* @qq 794404765
* @version 创建时间 2017年3月8日 下午3:25:38
*/
public class RunDemo {
public static void main(String[] args) {
/*
* 组装认证申请数据区 第一个包的数据区
*/
// 客户号 8字节 共用
byte[] customerId = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
// 终端号 2字节 共用
byte[] terminalId = new byte[] { 1, 2 };
// 读卡控件版本 4字节
byte[] readCardControlsVersion = new byte[] { 1, 2, 3, 4 };
// 人像控件版本 4字节
byte[] pictureControlsVersion = new byte[] { 1, 2, 3, 4 };
// 证书序列号 32字节 "csywzd1" 共用
// byte[] certificateNumber = new byte[] { 99, 115, 121, 119, 122, 100, 49 };
byte[] certificateNumber = new byte[] {114, 122, 102, 119, 48, 49 };
certificateNumber = FormatBytesUtil.copyByteToAnother(new byte[32], certificateNumber);
System.out.println("证书序列号:" + Arrays.toString(certificateNumber));
AuthenticationApplicationData auApp = new AuthenticationApplicationData(customerId, terminalId,
readCardControlsVersion, pictureControlsVersion, certificateNumber);
byte[] auAppData = auApp.getAuthenticationApplicationData();
/*
* 组装认证申请Socket数据包 第一次UDP数据包
*/
// 协议版本 2字节 0x0001 共用
byte[] version = { 0, 1 };
// 命令类型 1字节 0x00(请求)0x01(应答) 共用
byte[] commandType = { 0 };
// 命令 1字节 0x00(身份认证申请)0x01(身份认证) 共用但值不同
byte[] command = { 0 };
// 命令内容 1字节 保留 0x00 共用
byte[] commandContent = { 0 };
// 操作 1字节 保留 0x00 共用
byte[] operation = { 0 };
SocketPackage auAppSP = new SocketPackage(version, commandType, command, commandContent, operation, auAppData);
byte[] auAppSPData = auAppSP.getSocketPackage();
byte[] applicationReturn = SocketSender.sendSocketPackage(auAppSPData);
/*
* 组装认证数据区 第二个包的数据区
*/
byte[] streamNumber = null;
if (applicationReturn != null) {
streamNumber = Arrays.copyOfRange(applicationReturn, 24, 33);// 获取到业务流水号要组装进第二个数据包中
System.out.println("流水号:" + Arrays.toString(streamNumber));
System.out.println(FormatBytesUtil.bytesToHexString(streamNumber));
short randomBytesLength = FormatBytesUtil.getShortFromBytes(Arrays.copyOfRange(applicationReturn, 33, 35)); // 获取随机数长度
String randomData = FormatBytesUtil
.bytesToHexString(Arrays.copyOfRange(applicationReturn, 35, 35 + randomBytesLength)); // 获取随机数数据
System.out.println("随机数长度:" + randomBytesLength);
System.out.println("随机数数据:" + randomData);
}
if (applicationReturn == null) {
System.out.println("获取流水号失败,认证失败。");
return;
}
byte[] picture = Constans.picture; // 生成人像数据
byte[] reservationFour = new ReservationData("毛家亮", "342224198901241273", "20071114", "20171114")
.getReservasionBytes(); // 生成四项保留数据
byte[] reservationTwo = new ReservationData("李晓阳", "410185199211044510", null, null).getReservasionBytes(); // 生成两项保留数据
/*
* 0X0F
*/
byte[] identityModel_0X0F = new byte[] { 0x0f };
AuthenticationData au_0X0F = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X0F,
Constans.idCheck, Constans.verification, picture, null, certificateNumber);
byte[] auData_0X0F = au_0X0F.getAuthenticationData();
/*
* 0X4F
*/
byte[] identityModel_0X4F = new byte[] { 0x4f };
AuthenticationData au_0X4F = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X4F,
Constans.idCheck, Constans.verification, picture, reservationTwo, certificateNumber);
@SuppressWarnings("unused")
byte[] auData_0X4F = au_0X4F.getAuthenticationData();
/*
* 0X1F
*/
byte[] identityModel_0X1F = new byte[] { 0x1f };
AuthenticationData au_0X1F = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X1F,
Constans.idCheck, Constans.verification, picture, reservationFour, certificateNumber);
byte[] identityModel_0X62 = new byte[] { 0x62 };
AuthenticationData au_0X62 = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X62,
null, null, picture, reservationFour, certificateNumber);
@SuppressWarnings("unused")
byte[] auData_0X62 = au_0X62.getAuthenticationData();
/**
* 0x40
*/
byte[] identityModel_0X40 = new byte[] { 0x40 };
AuthenticationData au_0X40 = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X40,
null, null, null, reservationTwo, certificateNumber);
@SuppressWarnings("unused")
byte[] auData_0X40 = au_0X40.getAuthenticationData();
/**
* 0x42
*/
byte[] identityModel_0X42 = new byte[] { 0x42 };
AuthenticationData au_0X42 = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X42,
null, null, picture, reservationTwo, certificateNumber);
@SuppressWarnings("unused")
byte[] auData_0X42 = au_0X42.getAuthenticationData();
/*
* 0X13
*/
byte[] identityModel_0X13 = new byte[] { 0x13 };
AuthenticationData au_0X13 = new AuthenticationData(customerId, terminalId, streamNumber, identityModel_0X13,
Constans.idCheck, null, picture, reservationFour, certificateNumber);
@SuppressWarnings("unused")
byte[] auData_0X13 = au_0X13.getAuthenticationData();
/*
* 组装认证Socket数据包 第二次UDP数据包
*/
command[0] = 1; // 命令 1字节 0x00(身份认证申请)0x01(身份认证) 修改值的内容为1
SocketPackage auSP = new SocketPackage(version, commandType, command, commandContent, operation, auData_0X40);
byte[] auSPData = auSP.getSocketPackage();
byte[] auReturn = SocketSender.sendSocketPackage(auSPData);
if (auReturn != null) {
System.out.println("响应结果:"+Arrays.toString(auReturn));
System.out.println("验签结果:" + DataSignature.signCheck(auReturn)); // 验签
String string = new String(Arrays.copyOfRange(auReturn, 33, 37));
System.out.print("认证结果:" + string);
return;
}
System.out.println("认证失败。");
}
}
package com.fri.http.legalchapter.rzfw.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class Constans {
// 签名方法参数
public static String strDN = "rzfw01";
public static String strDigestAlg = "sm3";
// 客户号 8字节 共用
public static byte[] customerId = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
// 终端号 2字节 共用
public static byte[] terminalId = new byte[] { 1, 2 };
public static byte[] certificateNumber = FormatBytesUtil.copyByteToAnother(new byte[32], new byte[] {114, 122, 102, 119, 48, 49 });
public static String business ="businessSerialNumber";
//申请保留数据
public static String applyRetain ="authApplyRetainData";
//认证模式
public static String authMode="authMode";
public static String name="Name";
public static String idNumber="IDNumber";
public static String enableDate="EnableDate";
public static String expireDate ="ExpireDate";
// UDP Socket参数
// public static String ip = "111.200.45.122";
public static String ip = "172.16.16.253";
public static int port = 8283;
public static InetAddress ia = null;
static {
try {
ia = InetAddress.getByName(ip);
} catch (UnknownHostException e) {
System.out.println("InetAddress 初始化失败,请检查Constans类中的host地址。");
e.printStackTrace();
}
}
public static byte[] idCheck = new byte[] { 3, 0, -51, -13, -36, 14, 123, 109, 106, 88, 2, 82, -46, -28, -84, -37,
-82, 113, 111, -118, 34, 107, -40, -59, 69, -68, -10, 97, 110, -52, 70, -114, -34, -15, 50, 48, 49, 53, 49,
49, 49, 56, 48, 49, 53, 51, 50, 52, 55, 57, 56, 1, 1, 108, 81, -119, 91, -24, -112, 44, 123, 0, 78, 20, 120,
118, 122, 64, 98, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 50, 0, 48, 0, 49, 0, 53, 0, 49, 0, 49, 0,
49, 0, 56, 0, 50, 0, 48, 0, 49, 0, 55, 0, 49, 0, 49, 0, 49, 0, 52, 0, -89, 46, -122, 112, 37, 110, -52, 34,
26, 21, -1, 49, 44, -47, -64, -21, -25, 45, 32, 33, 110, -73, -93, -5, -8, -9, 105, 92, -18, 109, -87, 7,
-51, -13, -36, 14, 123, 109, 106, 88, 2, 82, -46, -28, -84, -37, -82, 113, 111, -118, 34, 107, -40, -59, 69,
-68, -10, 97, 110, -52, 70, -114, -34, -15, 21, -18, 19, -18, -69, 14, -63, 13, 73, 125, 50, 51, 93, 84, 27,
63, -42, -66, 95, -90, -94, -20, 47, -120, -100, -98, -68, 85, 73, 24, 97, 19, 0, 1, 48, 70, 2, 33, 0, -47,
62, -43, 102, -99, 98, 37, 96, -97, 106, -80, -120, -28, 89, 96, -102, 124, 104, -15, 108, -34, 63, -61, 39,
4, 20, -75, 21, -125, 88, 98, -37, 2, 33, 0, -25, -61, 57, -39, 33, -2, 51, -90, -38, -79, 111, 69, -91,
-124, -27, 58, -93, -3, 37, 67, -9, -50, -12, 106, 1, 71, -103, 75, 67, -73, -29, -58, 77, 73, 73, 66, 49,
81, 89, 75, 75, 111, 69, 99, 122, 49, 85, 71, 65, 81, 81, 67, 65, 54, 67, 67, 65, 99, 85, 119, 103, 103, 72,
66, 65, 103, 69, 65, 77, 89, 72, 79, 77, 73, 72, 76, 65, 103, 69, 65, 77, 68, 119, 119, 77, 68, 69, 76, 77,
65, 107, 71, 65, 49, 85, 69, 13, 10, 66, 104, 77, 67, 81, 48, 52, 120, 68, 84, 65, 76, 66, 103, 78, 86, 66,
65, 111, 84, 66, 69, 100, 66, 87, 86, 77, 120, 69, 106, 65, 81, 66, 103, 78, 86, 66, 65, 77, 84, 67, 85,
100, 66, 87, 86, 78, 84, 86, 85, 74, 68, 81, 81, 73, 73, 86, 110, 121, 67, 47, 50, 83, 122, 13, 10, 83, 57,
89, 119, 67, 119, 89, 74, 75, 111, 69, 99, 122, 49, 85, 66, 103, 105, 48, 68, 66, 72, 115, 119, 101, 81, 73,
103, 72, 118, 115, 109, 113, 75, 73, 122, 90, 104, 57, 55, 111, 70, 52, 110, 75, 65, 51, 78, 47, 87, 79, 77,
65, 97, 80, 56, 66, 51, 57, 68, 103, 97, 112, 105, 13, 10, 122, 57, 66, 78, 103, 80, 89, 67, 73, 81, 67, 90,
89, 51, 89, 122, 122, 50, 84, 70, 113, 81, 49, 72, 72, 86, 106, 98, 106, 54, 57, 80, 99, 103, 79, 90, 79,
57, 69, 101, 67, 105, 69, 71, 119, 107, 72, 101, 98, 117, 107, 52, 85, 103, 81, 103, 111, 66, 111, 48, 86,
72, 49, 67, 13, 10, 97, 75, 109, 88, 107, 111, 72, 90, 79, 102, 112, 87, 79, 98, 102, 102, 69, 78, 106, 70,
116, 105, 116, 74, 116, 104, 54, 43, 101, 51, 106, 103, 102, 113, 48, 69, 69, 66, 82, 71, 121, 55, 56, 97,
82, 72, 57, 122, 69, 66, 112, 77, 55, 68, 116, 82, 89, 122, 107, 119, 103, 101, 111, 71, 13, 10, 67, 105,
113, 66, 72, 77, 57, 86, 66, 103, 69, 69, 65, 103, 69, 119, 67, 81, 89, 72, 75, 111, 69, 99, 122, 49, 85,
66, 97, 73, 67, 66, 48, 79, 50, 72, 51, 89, 79, 87, 114, 109, 72, 98, 108, 72, 119, 87, 98, 102, 112, 107,
56, 48, 74, 90, 57, 82, 50, 69, 104, 67, 115, 86, 13, 10, 68, 83, 104, 66, 116, 55, 118, 72, 78, 48, 102,
109, 68, 49, 69, 75, 68, 73, 79, 116, 88, 104, 109, 48, 65, 71, 47, 99, 122, 111, 105, 100, 77, 87, 81, 101,
101, 84, 106, 90, 84, 69, 55, 113, 85, 105, 65, 52, 105, 98, 55, 81, 76, 72, 78, 77, 99, 75, 97, 68, 53,
108, 115, 65, 13, 10, 104, 97, 70, 89, 111, 50, 100, 43, 87, 86, 65, 116, 111, 83, 67, 66, 65, 83, 66, 75,
86, 98, 88, 66, 83, 78, 107, 90, 101, 49, 52, 118, 90, 68, 83, 107, 43, 74, 109, 113, 43, 102, 72, 98, 122,
52, 89, 65, 118, 74, 72, 90, 54, 117, 57, 68, 111, 82, 116, 111, 115, 67, 51, 104, 13, 10, 118, 76, 65, 113,
98, 72, 109, 56, 65, 68, 55, 74, 70, 79, 112, 48, 102, 121, 120, 118, 98, 114, 99, 88, 74, 53, 118, 65, 118,
53, 55, 102, 82, 57, 104, 57, 72, 86, 86, 77, 113, 109, 71, 109, 50, 113, 120, 113, 52, 51, 111, 78, 76,
104, 80, 113, 49, 108, 73, 52, 77, 77, 57, 57, 13, 10, 98, 67, 114, 99, 111, 105, 113, 56, 106, 47, 122,
108, 85, 116, 68, 90, 99, 65, 122, 88, 112, 105, 80, 47, 103, 113, 69, 57, 57, 77, 75, 103, 77, 97, 49, 81,
69, 73, 116, 89, 77, 98, 111, 53, 68, 55, 73, 80, 101, 104, 48, 114, 84, 79, 103, 61 };
public static byte[] verification = new byte[] { -64, 1, 77, 73, 73, 66, 81, 119, 89, 75, 75, 111, 69, 99, 122, 49,
85, 71, 65, 81, 81, 67, 65, 54, 67, 67, 65, 84, 77, 119, 103, 103, 69, 118, 65, 103, 69, 65, 77, 89, 72, 79,
77, 73, 72, 76, 65, 103, 69, 65, 77, 68, 119, 119, 77, 68, 69, 76, 77, 65, 107, 71, 65, 49, 85, 69, 13, 10,
66, 104, 77, 67, 81, 48, 52, 120, 68, 84, 65, 76, 66, 103, 78, 86, 66, 65, 111, 84, 66, 69, 100, 66, 87, 86,
77, 120, 69, 106, 65, 81, 66, 103, 78, 86, 66, 65, 77, 84, 67, 85, 100, 66, 87, 86, 78, 84, 86, 85, 74, 68,
81, 81, 73, 73, 86, 110, 121, 67, 47, 50, 83, 122, 13, 10, 83, 57, 89, 119, 67, 119, 89, 74, 75, 111, 69,
99, 122, 49, 85, 66, 103, 105, 48, 68, 66, 72, 115, 119, 101, 81, 73, 104, 65, 73, 71, 53, 106, 121, 80, 90,
80, 86, 48, 83, 119, 108, 87, 65, 85, 82, 120, 111, 108, 104, 87, 81, 53, 69, 79, 106, 71, 101, 70, 80, 77,
76, 81, 50, 13, 10, 53, 118, 119, 47, 111, 49, 52, 78, 65, 105, 65, 77, 109, 69, 54, 57, 70, 57, 106, 87,
116, 50, 103, 75, 82, 108, 80, 105, 49, 107, 66, 51, 99, 110, 86, 71, 56, 56, 105, 49, 100, 108, 78, 53, 55,
75, 75, 114, 73, 105, 102, 85, 74, 119, 81, 103, 102, 113, 48, 54, 54, 110, 108, 72, 13, 10, 76, 117, 86,
66, 118, 76, 119, 65, 100, 57, 99, 68, 86, 97, 122, 86, 55, 48, 119, 102, 87, 116, 72, 84, 52, 101, 114,
114, 49, 67, 110, 105, 75, 73, 99, 69, 69, 75, 104, 116, 75, 70, 119, 81, 87, 119, 84, 48, 54, 104, 120, 83,
80, 54, 119, 52, 106, 116, 69, 119, 87, 81, 89, 75, 13, 10, 75, 111, 69, 99, 122, 49, 85, 71, 65, 81, 81,
67, 65, 84, 65, 74, 66, 103, 99, 113, 103, 82, 122, 80, 86, 81, 70, 111, 103, 69, 66, 53, 116, 54, 117, 83,
67, 49, 98, 118, 47, 85, 108, 110, 84, 107, 85, 54, 48, 68, 87, 120, 120, 77, 113, 43, 108, 49, 101, 102,
113, 53, 43, 79, 13, 10, 51, 53, 66, 97, 114, 100, 56, 48, 117, 76, 47, 56, 88, 101, 71, 74, 118, 112, 89,
113, 100, 102, 67, 80, 120, 54, 78, 101, 111, 118, 84, 115, 71, 47, 122, 111, 66, 103, 70, 87, 67, 116, 97,
80, 51, 57, 117, 79, 56, 117, 106, 71, 0, 0 };
public static byte[] picture = null;
static {
File f = new File("./config/123.jpg");
try (InputStream in = new FileInputStream(f)) {
picture = new byte[(int) f.length()];
in.read(picture);
} catch (FileNotFoundException e) {
System.out.println("文件未找到。");
e.printStackTrace();
} catch (IOException e) {
System.out.println("IOException.");
e.printStackTrace();
}
// OCX版人像控件输出结果需进行Base64.decode(image)转换,获得的字节数据进行组包
}
}
package com.fri.http.legalchapter.rzfw.utils;
public class FormatBytesUtil {
/**
* 将byte数组转换为short类型
* @param bytes
* @return short
*/
public static short getShortFromBytes(byte[] bytes) {
return (short) ((0xff & bytes[0]) | (0xff00 & (bytes[1] << 8)));
}
/**
* 将byte数组转换为int类型
* @param bytes
* @return
*/
public static int getIntFromBytes(byte[] bytes) {
return (0xff & bytes[0]) | (0xff00 & (bytes[1] << 8))
| (0xff0000 & (bytes[2] << 16))
| (0xff000000 & (bytes[3] << 24));
}
/**
* 将short类型的数据转为byte数组 short类型为两个字节将这个字节转为byte数组长度为二 eg:id和认证码长度的转换
*
* @param data
* @return
*/
public static byte[] getByteOfShort(short data) {
byte[] bytes = new byte[2]; // 创建一个byte数组,长度设置为2
bytes[0] = (byte) (data & 0xff);// 参数与0xff做与运算
bytes[1] = (byte) ((data & 0xff00) >> 8);// 做过‘与’运算之后右移8位
return bytes;
}
/**
* int类型转换为4字节长度的byte数组 eg:时间戳的生成 数据区长度的转换
*
* @param data
* @return
*/
public static byte[] getBytesOfInt(int data) {
byte[] bytes = new byte[4];
bytes[0] = (byte) (data & 0xff);
bytes[1] = (byte) ((data & 0xff00) >> 8);
bytes[2] = (byte) ((data & 0xff0000) >> 16);
bytes[3] = (byte) ((data & 0xff000000) >> 24);
return bytes;
}
/**
* 时间戳
*
* @return 4字节时间戳
*/
public static byte[] getTimestamp() {
int i = (int) (System.currentTimeMillis() / 1000);
byte[] time = getBytesOfInt(i);
return time;
}
/**
* 把from中的内容拷贝到to中 eg:姓名拷贝到保留数据明文
*
* @param to
* @param from
* @return
*/
public static byte[] copyByteToAnother(byte[] to, byte[] from) {
for (int i = 0; i < from.length; i++) {
to[i] = from[i];
}
return to;
}
/**
* String类型转为byte数组,单字节转换方式
*
* @param bytes
* @param string
* @return
*/
public static byte[] getBytesFromString(byte[] bytes, String string) {
for (int i = 0; i < string.length(); i++) {
bytes[i] = (byte) string.charAt(i);
}
return bytes;
}
/**
* 将两个byte数组合并为一个
*
* @param byte_1
* @param byte_2
* @return byte_3
*/
public static byte[] byteMerger(byte[] byte1, byte[] byte2) {
byte[] byte3 = new byte[byte1.length + byte2.length];
System.arraycopy(byte1, 0, byte3, 0, byte1.length);
System.arraycopy(byte2, 0, byte3, byte1.length, byte2.length);
return byte3;
}
/**
* 用可变参数将所有的byte数组合并为一个
*
* @param first
* @param rest
* @return
*/
public static byte[] concatAll(byte[] first, byte[]... rest) {
int totalLength = first.length;
for (int i = 0; i < rest.length; i++) {
if (rest[i] != null) {
totalLength += rest[i].length;
}
}
byte[] result = new byte[totalLength];
System.arraycopy(first, 0, result, 0, first.length);
int offset = first.length;
for (int i = 0; i < rest.length; i++) {
if (rest[i] != null) {
System.arraycopy(rest[i], 0, result, offset, rest[i].length);
offset += rest[i].length;
}
}
return result;
}
/**
* 将byte数组转换成十六进制字符串 eg:流水号转换
*
* @author xia79
* @param ba
* @return
*/
public static String bytesToHexString(byte[] ba) {
String s = "";
for (int i = 0; i < ba.length; i++) {
s += String.format("%02X", ba[i]);
}
return s;
}
/**
* 将十六进制字符串转换成byte数组 eg:流水号转换
*
* @param hexString
* @return
*/
public static byte[] hexStringToBytes(String hexString) {
if (hexString == null || hexString.equals("")) {
return null;
}
hexString = hexString.toUpperCase();
int length = hexString.length() / 2;
char[] hexChars = hexString.toCharArray();
byte[] d = new byte[length];
for (int i = 0; i < length; i++) {
int pos = i * 2;
d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
}
return d;
}
private static byte charToByte(char c) {
return (byte) "0123456789ABCDEF".indexOf(c);
}
}
package com.fri.http.rest.resources;
import com.fri.http.rest.config.YXDefaultServerConfig;
import com.fri.http.rest.connections.HttpClientPool;
import com.fri.http.rest.logging.YXLogging;
import com.fri.http.rest.server.YXHttpRestServer;
import com.fri.http.rest.response.YXJSONResponse;
import org.eclipse.jetty.server.ServerConnector;
import org.omg.CORBA.Any;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Random;
import java.util.logging.Logger;
/**
* Created by lixiaoyang on 4/27/17.
* 版本
* v1/postRandom
* v1/postIdentity
*/
@Path("v1")
public class CTIDRestResources {
private String version = "ver1";
private Logger logger = YXLogging.getLogger(YXDefaultServerConfig.LOGGING_NAME_REQUEST_SERVER);
private Logger logger2 = YXLogging.getLogger(YXDefaultServerConfig.LOGGING_NAME_RESPONSE_SERVER);
@GET
@Path("status")
@Produces(MediaType.APPLICATION_JSON)
/**
* 接收带有查询参数的GET的请求
*/
public String hello(@Context HttpServletRequest req, @Context HttpServletResponse resp, @QueryParam("agent") String agent) throws Exception {
resp.setCharacterEncoding("UTF-8");
YXJSONResponse yxResp = new YXJSONResponse();
HashMap dataMap = new HashMap<String, Any>();
dataMap.put("ApiVersion", version);
dataMap.put("ThreadInProcess", YXHttpRestServer.jettyServer.getThreadPool().getThreads());
dataMap.put("CurrentQueueSize", ((ServerConnector)YXHttpRestServer.jettyServer.getConnectors()[0]).getAcceptQueueSize());
dataMap.put("AgentCode", agent);
dataMap.put("BusinessSerialNo", "SAXD1351231512312");
dataMap.put("RandomNo", String.valueOf(new Random().nextInt(999999999)+5));
String jsonStr = yxResp.outPutSuccess(dataMap).toJSONString();
logger.info(req.getRemoteHost() + " => " + jsonStr);
return jsonStr;
}
@POST
@Path("postRandom")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
/**
* 接收带有 JSON Body 的POST请求,非Form模式
*/
public String postRandomBody(String jsonStr) throws Exception {
logger.info(jsonStr);
// YXJSONResponse sta = new YXJSONResponse();
// JSONObject randomResponseObj = new CTIDServer().passRandomData(jsonStr);
// logger2.info(randomResponseObj.toString());
// return sta.outPutSuccess(randomResponseObj).toJSONString();
//接收客户端发送的json 转换并处理返回响应结果
return "身份认证申请的响应json字符串";
}
@POST
@Path("postIdentity")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
//接收带有 JSON Body 的POST请求,非Form模式
public String postIdentityBody(String jsonStr) throws Exception {
logger.info(jsonStr);
// YXJSONResponse sta = new YXJSONResponse();
// String responseStr = new CTIDServer().passIdentityData(jsonStr);
// JSONObject json = JSONObject.fromObject(responseStr);
// logger2.info(json.toString());
// return sta.outPutSuccess(json).toJSONString();
return "身份认证结果的响应json字符串";
}
@GET
@Path("getTest")
@Produces(MediaType.APPLICATION_JSON)
//GET请求,同时向其他服务器发送请求
public String getTest(@Context HttpServletRequest req, @Context HttpServletResponse resp) throws Exception {
YXJSONResponse sta = HttpClientPool.getRequest("http://www.baidu.com");
return sta.toJSONString();
}
@GET
@Path("postTest")
@Produces(MediaType.APPLICATION_JSON)
//GET请求,同时向远程发送POST请求
public String postTest(@Context HttpServletRequest req, @Context HttpServletResponse resp) throws Exception {
String body = "[{\n" +
" \"name\": \"archive_file_search_1\",\n" +
" \"timestamp\": 1359786400000,\n" +
" \"value\": 321,\n" +
" \"tags\": {\"host\": \"server3\"}\n" +
"}]";
YXJSONResponse sta = HttpClientPool.postRequest(YXDefaultServerConfig.KAIROSDB_REST_ADDRESS, body);
return sta.toJSONString();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment