lam commit

This commit is contained in:
lam 2021-03-26 11:07:58 +08:00
parent 0becc9f841
commit ba35f83af0
17 changed files with 641 additions and 2 deletions

View File

@ -0,0 +1,73 @@
package net.shapelight.modules.xian.service;
import com.alibaba.fastjson.JSONObject;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import net.shapelight.common.utils.DateUtils;
import net.shapelight.common.utils.MD5Utils;
import net.shapelight.modules.xian.utils.AESUtils;
import net.shapelight.modules.xian.utils.XaHttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class XaApi {
private static final Logger log = LoggerFactory.getLogger(net.shapelight.modules.xian.service.XaApi.class);
private static final String getXqAddrUrl = "http://117.34.12.66:10011/zhxqgl/interface/get_xq_addr.jsp";
private static final String getFwikUrl = "http://117.34.12.66:10011/ywxzservice/get_fwjk_url.jsp";
public static String getAddress(String xqid, String appId, String appSecret) {
Map<String, String> postParameters = new HashMap<>();
String appsecretMd5 = MD5Utils.getMD5Str(appSecret);
postParameters.put("xqid", xqid);
postParameters.put("appid", appId);
postParameters.put("appsecret", appsecretMd5);
return XaHttpUtils.postHttp("http://117.34.12.66:10011/zhxqgl/interface/get_xq_addr.jsp", postParameters);
}
public static String getFwikUrl(String appId, String appSecret) {
Map<String, String> postParameters = new HashMap<>();
String appsecretMd5 = MD5Utils.getMD5Str(appSecret);
postParameters.put("appid", appId);
postParameters.put("appsecret", appsecretMd5);
String res = XaHttpUtils.postHttp("http://117.34.12.66:10011/ywxzservice/get_fwjk_url.jsp", postParameters);
JSONObject resObject = JSONObject.parseObject(res);
if (resObject != null) {
JSONObject xmlObject = resObject.getJSONObject("xml");
String code = xmlObject.getString("code");
if (code != null && code.equals("0000"))
return xmlObject.getString("data");
log.error("获取接口地址错误,错误码:"+ xmlObject.getString("code") + ",错误信息:"+ xmlObject.getString("data"));
}
return null;
}
public static String postData(String url, String appId, String appSecret, String tranId, String serviceId, String serviceValue, Map<String, Object> dataObject) {
String dataMingWen = JSONObject.toJSONString(dataObject);
String dataMiWen = null;
try {
dataMiWen = AESUtils.encrypt(dataMingWen, appSecret);
} catch (Exception e) {
log.error("加密数据时出错:"+ e.getMessage());
return null;
}
if (dataMiWen != null) {
String tokenStr = appId + appSecret + DateUtils.format(new Date(), "YYYYMMDD") + dataMiWen;
String token = MD5Utils.getMD5Str(tokenStr);
Map<String, String> headerMaps = new HashMap<>();
headerMaps.put("appID", appId);
headerMaps.put("token", token);
headerMaps.put("tranId", tranId);
headerMaps.put("serviceId", serviceId);
headerMaps.put("serviceValue", serviceValue);
Map<String, String> postParameters = new HashMap<>();
postParameters.put("data", dataMiWen);
return "";
}
return null;
}
}

View File

@ -0,0 +1,103 @@
package net.shapelight.modules.xian.utils;
import com.alibaba.fastjson.JSONObject;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import net.shapelight.common.utils.DateUtils;
import net.shapelight.modules.xian.vo.XaSYFW;
public class AESUtils {
public static String encrypt(String sSrc, String sKey) throws Exception {
if (sKey == null)
return null;
if (sKey.length() != 32)
return null;
byte[] raw = parseHexStr2Byte(sKey);
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(1, skeySpec);
byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
return parseByte2HexStr(encrypted);
}
public static String decrypt(String sSrc, String sKey) throws Exception {
try {
if (sKey == null)
return null;
if (sKey.length() != 32)
return null;
byte[] raw = parseHexStr2Byte(sKey);
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(2, skeySpec);
byte[] encrypted1 = parseHexStr2Byte(sSrc);
try {
byte[] original = cipher.doFinal(encrypted1);
String originalString = new String(original, "utf-8");
return originalString;
} catch (Exception e) {
System.out.println(e.toString());
return null;
}
} catch (Exception ex) {
System.out.println(ex.toString());
return null;
}
}
private static String parseByte2HexStr(byte[] buf) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf.length; i++) {
String hex = Integer.toHexString(buf[i] & 0xFF);
if (hex.length() == 1)
hex = '0' + hex;
sb.append(hex.toUpperCase());
}
return sb.toString();
}
private static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1)
return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
result[i] = (byte)(high * 16 + low);
}
return result;
}
public static void main(String[] args) throws Exception {
Date now = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String s = df.format(now);
XaSYFW realRoom = new XaSYFW();
realRoom.setLV_FWBM("123456781234567812345678");
realRoom.setLV_DZBM("123456781234567812345678");
realRoom.setLV_DZMC("陕西省西安市雁塔区科技二路78号太白阁c座10304室");
realRoom.setLV_FWLB("1");
realRoom.setLV_FWXZ("2");
realRoom.setLV_FWYT("4");
realRoom.setLV_SFCZF("");
realRoom.setLV_FZ_GMSFHM("123456781234567812");
realRoom.setLV_FZ_XM("令狐传奇");
realRoom.setLV_FZ_ZJZL("10");
realRoom.setLV_FZ_ZJHM("123456781234567812");
realRoom.setLV_FZ_LXDH("12345678912");
realRoom.setLV_DJSJ(DateUtils.format(new Date(), "yyyyMMddHHmmss"));
realRoom.setLV_FWXZZ("1000");
realRoom.setLV_FWJG("1");
realRoom.setLV_COMPUTERID("123456781234567812345678");
realRoom.setLV_SSXQBM("123456781234567812345678");
realRoom.setLV_PROCMODE("PMINSERT");
String object = JSONObject.toJSONString(realRoom);
int count = object.length();
System.out.println(count);
}
}

View File

@ -0,0 +1,29 @@
package net.shapelight.modules.xian.utils;
public class XaConst {
public static final String REAL_ROOM = "SYFW";
public static final String REAL_PERSON = "SYRK";
public static final String DOOR_CARD = "MJKXX";
public static final String DEVICE = "MJSBXX";
public static final String VISITOR = "FKSQXX";
public static final String PERSON_RECORD = "RYSKZPXX";
public static final String CAR_RECORD = "TCCTCSBXX";
public static final String PERSSON_RECORD_IMAGE = "RYJCZPXX";
public static final String CAR_RECORD_IMAGE = "TCCTCSBZPXX";
public static final String REAL_PERSON_IMAGE = "RYRKPHOTO";
}

View File

@ -0,0 +1,132 @@
package net.shapelight.modules.xian.utils;
import com.alibaba.fastjson.JSONObject;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.Map;
import net.shapelight.common.utils.DateUtils;
import net.shapelight.common.utils.MD5Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
public class XaHttpUtils {
private static final Logger log = LoggerFactory.getLogger(net.shapelight.modules.xian.utils.XaHttpUtils.class);
private static final String appId = "1297164778041095";
private static final String appSecret = "22971647780410956329716477804109";
public static String postHttp(String url, Map<String, String> postParameters) {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(180000);
requestFactory.setReadTimeout(180000);
RestTemplate restTemplate = new RestTemplate((ClientHttpRequestFactory)requestFactory);
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
restTemplate.setErrorHandler((ResponseErrorHandler)new DefaultResponseErrorHandler());
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add("Content-Type", "application/x-www-form-urlencoded");
HttpEntity<Map<String, String>> requestEntity = new HttpEntity(postParameters, (MultiValueMap)requestHeaders);
String result = null;
for (int i = 1; i <= 3; i++) {
try {
result = (String)restTemplate.postForObject(url, requestEntity, String.class, new Object[0]);
return result;
} catch (RestClientException e) {
System.out.println("-----------" + i);
e.printStackTrace();
}
}
return result;
}
public static String postHttp(String url, Map<String, String> postParameters, Map<String, String> headerMaps) {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(180000);
requestFactory.setReadTimeout(180000);
RestTemplate restTemplate = new RestTemplate((ClientHttpRequestFactory)requestFactory);
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
restTemplate.setErrorHandler((ResponseErrorHandler)new DefaultResponseErrorHandler());
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add("Content-Type", "application/x-www-form-urlencoded");
for (String key : headerMaps.keySet()) {
System.out.print(key + "-" + (String)headerMaps.get(key) + "\t");
requestHeaders.add("key", headerMaps.get(key));
}
HttpEntity<Map<String, String>> requestEntity = new HttpEntity(postParameters, (MultiValueMap)requestHeaders);
String result = null;
for (int i = 1; i <= 3; i++) {
try {
result = (String)restTemplate.postForObject(url, requestEntity, String.class, new Object[0]);
return result;
} catch (RestClientException e) {
System.out.println("-----------" + i);
e.printStackTrace();
}
}
return result;
}
public static String postHttp(String url, JSONObject params) {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(180000);
requestFactory.setReadTimeout(180000);
RestTemplate restTemplate = new RestTemplate((ClientHttpRequestFactory)requestFactory);
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
restTemplate.setErrorHandler((ResponseErrorHandler)new DefaultResponseErrorHandler());
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
HttpEntity<JSONObject> requestEntity = new HttpEntity(params, (MultiValueMap)requestHeaders);
String result = null;
for (int i = 1; i <= 3; i++) {
try {
result = (String)restTemplate.postForObject(url, requestEntity, String.class, new Object[0]);
return result;
} catch (RestClientException e) {
System.out.println("-----------" + i);
e.printStackTrace();
}
}
return result;
}
public String getToken(String appId, String appSecret, String requestPackage) {
return MD5Utils.getMD5Str(appId + appSecret +
DateUtils.format(new Date(), "YYYYMMDD") + requestPackage);
}
public String packageEncode(String appSecret, String packageString) {
try {
String res = AESUtils.encrypt(packageString, appSecret);
return res;
} catch (Exception e) {
log.error(e.getMessage());
return null;
}
}
public String packageDecode(String appSecret, String packageString) {
try {
String res = AESUtils.decrypt(packageString, appSecret);
return res;
} catch (Exception e) {
log.error(e.getMessage());
return null;
}
}
}

View File

@ -0,0 +1,36 @@
package net.shapelight.modules.xian.vo;
import lombok.Data;
@Data
public class XaCYRY {
private String LV_CYRYBM;
private String LV_GMSFHM;
private String LV_XM;
private String LV_DWBM;
private String LV_DWMC;
private String LV_ZY;
private String LV_ZYLB;
private String LV_DJDWGAJGJGDM;
private String LV_DJDWGAJGJGMC;
private String LV_DJR;
private String LV_DJSJ;
private String LV_LXFS;
private String LV_COMPUTERID;
private String LV_PROCMODE = "PMINSERT";
}

View File

@ -0,0 +1,28 @@
package net.shapelight.modules.xian.vo;
import lombok.Data;
@Data
public class XaFKSQXX {
private String LV_SSXQBM;
private String LV_GMSFHM;
private String LV_XM;
private String LV_LXDH;
private String LV_DJRXM;
private String LV_YDJRGX;
private String LV_DJSJ;
private String LV_YXQX;
private String LV_PROCMODE = "PMINSERT";
private String LV_SBXT = "10";
}

View File

@ -22,6 +22,5 @@ public class XaHeaderParam {
private String tranId;
private String serviceId;
private String serviceValue;
private String versionCode;
}

View File

@ -0,0 +1,21 @@
package net.shapelight.modules.xian.vo;
import lombok.Data;
@Data
public class XaMJKXX {
private String LV_MJKLX;
private String LV_DJSJ;
private String LV_SSXQBM;
private String LV_SBXT;
private String LV_CKR;
private String LV_BH;
private String LV_PROCMODE = "PMINSERT";
}

View File

@ -0,0 +1,23 @@
package net.shapelight.modules.xian.vo;
import lombok.Data;
@Data
public class XaMJSBXX {
private String LV_MJMC;
private String LV_WZMS;
private String LV_SFYSXT;
private String LV_SSXQBM;
private String LV_SBXT;
private String LV_MJXTWYBM;
private String LV_PROCMODE = "PMINSERT";
}

View File

@ -11,6 +11,6 @@ public class XaPages {
*/
private Integer psize;
private Integer tcount;
private Integer pno;
private String pno = "1";
private Integer tsize;
}

View File

@ -0,0 +1,20 @@
package net.shapelight.modules.xian.vo;
import lombok.Data;
@Data
public class XaRYJCZPXX {
private String LV_SSXQBM;
private String LV_MJXTWYBM;
private String LV_ZPZP;
private String LV_ZPSJ;
}

View File

@ -0,0 +1,20 @@
package net.shapelight.modules.xian.vo;
import lombok.Data;
@Data
public class XaRYRKPHOTO {
private String LV_CASE_ID;
private String LV_SSXQBM;
private String LV_ZP;
private String LV_DJSJ;
private String LV_GMSFHM;
}

View File

@ -0,0 +1,28 @@
package net.shapelight.modules.xian.vo;
import lombok.Data;
@Data
public class XaRYSKZPXX {
private String LV_SSXQBM;
private String LV_MJBH;
private String LV_CRLB;
private String LV_ZPSJ;
private String LV_SBXT = "10";
private String LV_MJXTWYBM;
private String LV_RY_ID;
private String LV_FFMS;
private String LV_PROCMODE = "PMINSERT";
}

View File

@ -0,0 +1,38 @@
package net.shapelight.modules.xian.vo;
import lombok.Data;
@Data
public class XaSYDW {
private String LV_DWBM;
private String LV_DWMC;
private String LV_DWDZBM;
private String LV_DZLB;
private String LV_HZDWLX;
private String LV_DWXZ;
private String LV_DJDWGAJGJGMC;
private String LV_DJDWGAJGJGDM;
private String LV_DJSJ;
private String LV_DJR;
private String LV_COMPUTERID;
private String LV_SSXQBM;
private String LV_PROCMODE = "PMINSERT";
}

View File

@ -0,0 +1,46 @@
package net.shapelight.modules.xian.vo;
import lombok.Data;
@Data
public class XaSYFW {
private String LV_FWBM;
private String LV_DZBM;
private String LV_DZMC;
private String LV_FWLB = "1";
private String LV_FWXZ = "2";
private String LV_FWYT = "4";
private String LV_SFCZF = "";
private String LV_FZ_GMSFHM;
private String LV_FZ_XM;
private String LV_FZ_ZJZL = "10";
private String LV_FZ_ZJHM;
private String LV_FZ_LXDH;
private String LV_DJSJ;
private String LV_FWXZZ = "1000";
private String LV_FWJG = "1";
private String LV_COMPUTERID;
private String LV_SSXQBM;
private String LV_PROCMODE = "PMINSERT";
}

View File

@ -0,0 +1,26 @@
package net.shapelight.modules.xian.vo;
import lombok.Data;
@Data
public class XaTCCTCSBXX {
private String LV_TCCBH;
private String LV_CPHM;
private String LV_CPLX;
private String LV_GCSJ;
private String LV_GCLX;
private String LV_SBXT = "10";
private String LV_KKSBBH;
private String LV_PROCMODE = "PMINSERT";
}

View File

@ -0,0 +1,17 @@
package net.shapelight.modules.xian.vo;
import lombok.Data;
@Data
public class XaTCCTCSBZPXX {
private String LV_TCCBH;
private String LV_ZPZP;
private String LV_ZPSJ;
}