鹏远-个人反欺诈

This commit is contained in:
luojian 2019-05-31 17:59:20 +08:00
parent 7e2fb61629
commit 1f643bdb6d
19 changed files with 1687 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 B

View File

@ -0,0 +1,133 @@
<%@page import="com.itextpdf.text.log.SysoCounter"%>
<%@page import="java.util.Map.Entry"%>
<%@page import="com.alibaba.fastjson.JSONArray"%>
<%@page import="com.alibaba.fastjson.JSON"%>
<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@page import="com.tenwa.httpclient.controller.BigDataController"%>
<%@page import="java.util.Date"%>
<%@page import="com.tenwa.util.SerialNumberUtil"%>
<%@ page contentType="text/html; charset=GBK"%>
<%@include file="/IncludeBegin.jsp"%><%
String flowunid = CurPage.getParameter("ObjectNo");
String projectNo = CurPage.getParameter("ProjectNo");
String ReadyApprove = CurPage.getParameter("ReadyApprove");
String applyId = "";
String getType ="GET";
String type = "";
String count = "";
String reasonDesc = "";
BigDataController bdc = new BigDataController();
boolean flag = true;
if("GET".equals(getType)) {
JBOTransaction tx = JBOFactory.createJBOTransaction();
applyId = SerialNumberUtil.getPengyuanNumber(tx);
tx.commit();
type = "SAVE";
} else {
String result = bdc.getDataApplyId(CurPage, "pengyuan_af", Sqlca);
if("false".equals(result)) {
JBOTransaction tx = JBOFactory.createJBOTransaction();
applyId = SerialNumberUtil.getPengyuanNumber(tx);
tx.commit();
type = "SAVE";
} else {
String[] res = result.split("@");
applyId = res[1];
count = res[2];
type = "GET";
}
}
Map<String,String> params = new HashMap<String,String>(); //初始化参数
String resultals =bdc.getCustomerInfoPerson(flowunid, Sqlca);
if(!"false".equals(resultals)){
String[] sReturn = resultals.split("@");
params.put("queryType","25212");
params.put("name","测试一");
params.put("documentNo","110000199001011112");
params.put("phone","13712345670");
params.put("queryReasonID","101");
params.put("subreportIDs","96040");
params.put("refID","");
}
FileInputStream fr = null;
BufferedReader br = null;
try {
String htmlURL = bdc.getAndSavePengyuanData(params, "pengyuan_af", Sqlca, type, applyId, CurPage);
File file = new File(htmlURL);
fr = new FileInputStream(file);
br = new BufferedReader(new InputStreamReader(fr, "UTF-8"));
String str;
while((str = br.readLine()) != null) {
String html = str;
if(html.indexOf(".png") != -1 || html.indexOf(".jpg") != -1) {
html = html.replaceAll("image/image_\\d+[.]", "Tenwa/Lease/Flow/Comm/BigdataPengyuan/query_report/image/image.");
}
if(html.indexOf("width=\"95%\"") != -1) {
html = html.replaceAll("width=\"95%\"", "");
}
if(html.indexOf("height=\"70\"") != -1) {
html = html.replaceAll("height=\"70\"", "");
}
if(html.indexOf("width=\"103\"") != -1) {
html = html.replaceAll("width=\"103\"", "");
}
if(html.indexOf("<td>个人信息报告</td>") != -1) {
html = html.replaceAll("<td>个人信息报告</td>", "<td><a style=\"position:absolute;left:0;top:8%\" title=\"拉取鹏元数据\" onclick=\"AsButton.run(this, function(){getData();}, event);return false;\" class=\"inline_button \" hidefocus=\"\" href=\"javascript:void(0);\"><span style=\"display:none;\"></span><span class=\"left\">&nbsp;</span><span class=\"center\"><span class=\"btn_icon btn_icon_edit\">&nbsp;</span><span class=\"btn_text\">拉取鹏元数据</span></span><span class=\"right\">&nbsp;</span></a>个人信用报告</td>");
}
if(html.indexOf("<body>") != -1) {
html = html.replaceAll("<body>", "<body style=\"overflow:scroll;height:95%\">");
}
if(html.indexOf("<table class=\"report\" align=\"center\">") != -1) {
html = html.replaceAll("<table class=\"report\" align=\"center\">", "<table class=\"report\" align=\"center\" style=\"width:99%\">");
}
%>
<%=html%>
<%}
System.out.println("------------------鹏元-个人反欺诈解析结束时间----------------------");
System.out.println("");
System.out.println("");
System.out.println("------------------"+StringFunction.getTodayNow()+"----------------------");
System.out.println("");
System.out.println("");
System.out.println("------------------鹏元-个人反欺诈解析结束时间----------------------");
//查询获取数据次数
if("SAVE".equals(type)) {
String result = bdc.getDataApplyId(CurPage, "pengyuan_af", Sqlca);
if("false".equals(result)) {
count = "0";
} else {
count = result.split("@")[2];
}
}
} catch(Exception e) {
e.printStackTrace();
flag = false;
reasonDesc = e.getMessage();
Sqlca.rollback();
%>
<script type="text/javascript" src="<%=sWebRootPath %>/Frame/page/js/as_debug_message.js"></script>
<script type="text/javascript">
AsDebug.alert("提示","获取数据失败");
</script>
<%
} finally {
if(br != null) br.close();
if(fr != null) fr.close();
}
%>
<script type="text/javascript">
function getData() {
if('<%=ReadyApprove%>'=='ReadOnly'){
AsDebug.alert("提示", "查询页面不允许获取大数据");
return;
}
if("<%=count%>" == "done") {
AsDebug.alert("提示", "已达到获取数据次数上限");
} else {
location.href = location.href.indexOf("&GetType=GET") == -1 ? location.href + "&GetType=GET&Count=<%=count%>" : location.href.substring(0, location.href.indexOf("&GetType=GET")) + "&GetType=GET&Count=<%=count%>";
}
}
</script>
<%@include file="/IncludeEnd.jsp"%>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

21
config/bigdata.properties Normal file
View File

@ -0,0 +1,21 @@
#bigdata config
count = 3
keyword1 = ProjectId
keyword2 = CustId
keyword3 =
keyword4 =
keyword5 =
#pengyuan
pengyuanUrl = https://test.pycredit.com:6443/services/WebServiceSingleQuery?wsdl
userId = apwsqueryn01
password = {MD5}i3rx5Ta+2VL5Dj5T866giQ==
methodType = queryReport

View File

@ -54,6 +54,10 @@ public class SerialNumberUtil {
public static synchronized String getVoucherPCNumber(JBOTransaction tx) throws Exception{
return SerialNumberUtil.getSerialNumber("AP{year}{month}{day}-{maxOrderNumber}",3,null, "ƾ֤½Ó¿ÚÅú´Î", null, tx);
}
//ÅôÔªapply_id
public static synchronized String getPengyuanNumber(JBOTransaction tx) throws Exception{
return SerialNumberUtil.getSerialNumber("{year}{month}{day}{maxOrderNumber}",9,null, "", null, tx);
}
/**
* ͨÁª´ú¿ÛÁ÷Ë®ºÅ
* @param tx

View File

@ -1,6 +1,12 @@
package com.tenwa.httpclient;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -9,7 +15,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.ConnectTimeoutException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
@ -26,8 +35,12 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import com.amarsoft.are.ARE;
import com.tenwa.comm.exception.BusinessException;
import com.tenwa.httpclient.resources.GPSConfigure;
public class HttpClientUtil {
@ -196,4 +209,147 @@ public class HttpClientUtil {
}
return resultString;
}
public static String queryReport(String data, String type, String uploadPath) throws Exception {
return queryReport(data, type, uploadPath, null);
}
public static String queryReport(String data, String type, String uploadPath, String applyId) throws Exception {
Document doc = DocumentHelper.parseText(data);
Element root = doc.getRootElement();
Element returnValue = root.element("returnValue");
byte[] byteData = new Base64().decode(returnValue.getText());
String filePath = "";//获取html页面的存储路径并展示给用户
if("html".equals(type)) {
//输出文件
filePath = writeByteData(byteData, uploadPath, applyId);
//解压文件
String htmlFileName = unzipFile(filePath);
//找到html页面
filePath = new File(new File(new File(htmlFileName).getParent()).getParent()).getName() + "@" + htmlFileName;
} else if("pdf".equals(type)) {
filePath = writeByteData(byteData, uploadPath);
} else {
filePath = writeByteData(byteData, uploadPath);
}
return filePath;
}
//递归解压缩文件
public static String unzipFile(String filePath) throws Exception {
if(filePath == null || !filePath.endsWith(".zip")) {
throw new BusinessException("not a zipfile");
}
ZipInputStream zip = null;
FileOutputStream fos = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
String htmlFilePath = "";
String zipPath = filePath;
try {
zip = new ZipInputStream(new FileInputStream(filePath));
filePath = filePath.substring(0, filePath.indexOf("html") + 4);
bis = new BufferedInputStream(zip);
ZipEntry zipEntry = null;
while((zipEntry = zip.getNextEntry()) != null) {
String fileName = zipEntry.getName();
fileName = filePath + File.separator + fileName;
if(fileName.endsWith(".zip")) {//是压缩文件就继续解压
unzipFile(fileName);
} else {
File file = new File(fileName);
if(!file.exists()) {
new File(file.getParent()).mkdirs();//文件不存在则先创建目录群
}
if(fileName.endsWith(".html")) {
htmlFilePath = fileName;
}
bos = new BufferedOutputStream(new FileOutputStream(file));
int n = -1;
while((n = bis.read()) != -1) {
bos.write(n);
}
bos.flush();
}
}
} catch(Exception e) {
e.printStackTrace();
throw new BusinessException("文件解压失败");
} finally {
if(zip != null) zip.close();
if(fos != null) fos.close();
if(bis != null) bis.close();
if(bos != null) bos.close();
new File(zipPath).delete();
}
return htmlFilePath;
}
public static String writeByteData(byte[] byteData, String uploadPath) throws Exception {
return writeByteData(byteData, uploadPath, null);
}
public static String writeByteData(byte[] byteData, String uploadPath, String applyId) throws Exception {
String filePath = "";
ByteArrayInputStream bis = null;
FileOutputStream fos = null;
ZipInputStream zip = null;
File file = null;
try {
bis = new ByteArrayInputStream(byteData);
//首输出压缩文件
zip = new ZipInputStream(bis);//读取zip流
ZipEntry zipEntry = zip.getNextEntry();
//filePath = uploadPath + zipEntry.getName();
//为了避免并发导致读取文件冲突,为文件名加上时间戳
String code = System.currentTimeMillis() + "";
//增加applyId为存储名确保并发情况下低概率出现时间戳一致的情况
if(applyId != null && !"".equals(applyId)) {
code = applyId;
}
filePath = uploadPath + zipEntry.getName().replaceAll(".zip", code + ".zip");
file = new File(filePath);
if(!file.exists()) {
new File(file.getParent()).mkdirs();
}
fos = new FileOutputStream(file);
if(zipEntry != null) {
byte[] buf = new byte[1024];
int n = -1;
while((n = zip.read(buf, 0, buf.length)) != -1) {
fos.write(buf, 0, n);
}
fos.flush();
}
} catch(Exception e) {
e.printStackTrace();
throw new BusinessException("读写文件失败");
} finally {
if(bis != null) bis.close();
if(fos != null) fos.close();
}
return filePath;
}
public static String getQueryCondition(Map<String,String> params) {
try {
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement("conditions");
Element condition = root.addElement("condition");
condition.addAttribute("queryType",params.get("queryType"));
for(Entry<String, String> param : params.entrySet()) {
if("queryType".equals(param.getKey())) {
continue;
}
Element item = condition.addElement("item");
item.addElement("name").setText(param.getKey());
item.addElement("value").setText(param.getValue());
}
return doc.asXML();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -0,0 +1,38 @@
package com.tenwa.httpclient;
public class PyConfig {
// API域名
public final static String WEBSERVICE_HOST = ""; // 测试环境-http具体以技术支持提供为准
// public final static String WEBSERVICE_HOST = "https://test.pycredit.com:9443"; // 测试环境-https具体以技术支持提供为准
// public final static String WEBSERVICE_HOST = "http://www.pycredit.com:8001"; // 生产环境-http具体以技术支持提供为准
// public final static String WEBSERVICE_HOST = "https://www.pycredit.com:8443"; // 生产环境-https具体以技术支持提供为准
// 返回报文压缩的URL
public final static String WSDL_PATH_ZIP = "/services/WebServiceSingleQuery?wsdl";
// 返回报文不压缩的URL
public final static String WSDL_PATH_UNZIP = "/services/WebServiceSingleQueryOfUnzip?wsdl";
// 认证信息
public final static String USERID = "";
public final static String PASSWORD = "";
// 返回格式
public final static String FORMAT = "html";
// public final static String FORMAT = "html";
// public final static String FORMAT = "singlepdf";
// 是否测试模式
public final static boolean IS_TEST = true;
// 请求内容样本文件实际中可使用具体对象组装
public final static String QUERY_XML_FILE = "d:/sample.xml";
public final static String KEYSTORE_FILE = "C:/Users/luojian/Desktop/安鹏/接口/01接口文档资料/鹏元测试证书/pytest.jks";
public final static String KEYSTORE_PASSWORD = "123456";
public final static String TRUSTSTORE_FILE = "C:/Users/luojian/Desktop/安鹏/接口/01接口文档资料/鹏元测试证书/pytest2.jks";
public final static String TRUSTSTORE_PASSWORD = "123456";
public final static String AES_KEY = "";
}

View File

@ -0,0 +1,89 @@
package com.tenwa.httpclient;
import com.tenwa.httpclient.PyConfig;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
/**
* 鹏元征信 SSLContext 帮助类
*/
public class PySSLContextUtil {
/**
* 使用该SSLContext证书如下
* keystore javax.net.ssl.keyStore 指定的证书
* truststore javax.net.ssl.trustStore 指定的证书
*
* @return
* @throws NoSuchAlgorithmException
*/
public static SSLContext createDefaultSSLContext() throws NoSuchAlgorithmException {
return SSLContext.getDefault();
}
/**
* 使用该SSLContext, 证书可自定义
*
* @return
* @throws NoSuchAlgorithmException
*/
public static SSLContext createCustomerSSLContext() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException, CertificateException, UnrecoverableKeyException {
SSLContext context = SSLContext.getInstance("TLSv1.2");
KeyStore keyStore = getKeyStore("JKS", new FileInputStream(PyConfig.KEYSTORE_FILE), PyConfig.KEYSTORE_PASSWORD);
KeyManager[] kms = createKeyManager(keyStore, PyConfig.KEYSTORE_PASSWORD);
KeyStore trustStore = getKeyStore("JKS", new FileInputStream(PyConfig.TRUSTSTORE_FILE), PyConfig.TRUSTSTORE_PASSWORD);
//带公钥证书
// TrustManager[] tms = createTrustManager(trustStore);
// context.init(kms, tms, null);
//不带公钥证书
context.init(kms,new TrustManager[]{new X509TrustManager(){
public void checkClientTrusted(java.security.cert.X509Certificate[] arg0,String arg1) throws CertificateException{
}
public void checkServerTrusted(java.security.cert.X509Certificate[] arg0,String arg1) throws CertificateException{
}
public java.security.cert.X509Certificate[] getAcceptedIssuers(){
return null;
}
}},null);
SSLContext.setDefault(context);
return context;
}
private static KeyManager[] createKeyManager(KeyStore keyStore, String password) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException {
KeyManagerFactory factory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
factory.init(keyStore, password.toCharArray());
return factory.getKeyManagers();
}
private static TrustManager[] createTrustManager(KeyStore trustStore) throws NoSuchAlgorithmException, KeyStoreException {
TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
factory.init(trustStore);
return factory.getTrustManagers();
}
public static KeyStore getKeyStore(String keyStoreType, InputStream stream, String password) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(stream, password.toCharArray());
return keyStore;
}
}

View File

@ -0,0 +1,123 @@
package com.tenwa.httpclient;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.io.IOUtils;
import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.transport.http.CommonsHttpMessageSender;
import org.w3c.dom.Document;
import javax.net.ssl.HttpsURLConnection;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.StringReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* 鹏元工具类
*/
public class PyUtils {
/**
* 发起webservice请求
*
* @param urlStr
* @return
* @throws Exception
*/
public static String requestApi(String urlStr, String method, Object[] params) throws Exception {
String result = "";
try {
//调用webservice
URL url = new URL(urlStr);
Client client = null;
URLConnection conn = null;
if (urlStr.startsWith("https")) {
/**
* https 调用示例
*/
conn = (HttpsURLConnection) url.openConnection();
((HttpsURLConnection) conn).setSSLSocketFactory(PySSLContextUtil.createCustomerSSLContext().getSocketFactory());
} else {
/**
* http 调用示例
*/
conn = url.openConnection();
}
// 设置连接超时
conn.setConnectTimeout(5000);
// 设置读取超时
conn.setReadTimeout(5000);
client = new Client(conn.getInputStream(), null);
// 设置
HttpClientParams httpClientParams = new HttpClientParams();
// 单位毫秒 这个超时时间是 等待数据返回的时间
httpClientParams.setSoTimeout(20000);
// 设置从 HTTP connection manager 获取一个HTTP connection 的超时时间
httpClientParams.setConnectionManagerTimeout(10000L);
// xfire client支持 避免 'Expect: 100-continue' handshake
httpClientParams.setBooleanParameter(HttpClientParams.USE_EXPECT_CONTINUE, Boolean.FALSE);
client.setProperty(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS, httpClientParams);
//xfire client支持 取消长连接
client.setProperty(CommonsHttpMessageSender.DISABLE_KEEP_ALIVE, "true");
//得到子报告结果
Object[] results = client.invoke(method, params);
if (results[0] instanceof Document) {
Document doc = (Document) results[0];
result = doc.getFirstChild().getFirstChild().getNodeValue();
} else {
result = (String) results[0];
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* 解析报文仅供参考
*
* @param bodyStr
* @return
* @throws Exception
*/
public static WebServiceResult parseBody(String bodyStr) throws Exception {
JAXBContext context = JAXBContext.newInstance(WebServiceResult.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
WebServiceResult result = (WebServiceResult) unmarshaller.unmarshal(new StringReader(bodyStr));
return result;
}
/**
* 解压缩
*
* @param data
* @return
* @throws Exception
*/
public static void decompress(byte[] data) throws Exception {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
ZipInputStream zis = new ZipInputStream(bais);
ZipEntry ze = null;
while ((ze = zis.getNextEntry()) != null) {
System.out.println("文件名:" + ze.getName());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(zis, baos);
zis.closeEntry();
System.out.println("文件内容:" + new String(baos.toByteArray(), "GBK"));
}
}
}

View File

@ -0,0 +1,53 @@
package com.tenwa.httpclient;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
*/
@XmlRootElement(name = "result")
@XmlAccessorType(value = XmlAccessType.FIELD)
public class WebServiceResult {
private String status;
private String returnValue;
private String errorCode;
private String errorMessage;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getReturnValue() {
return returnValue;
}
public void setReturnValue(String returnValue) {
this.returnValue = returnValue;
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
package com.tenwa.httpclient.resources;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import com.amarsoft.are.ARE;
public class BigDataPropertiesUtil {
private static Map<String, String> attributes;
public static void load() {
attributes = new ConcurrentHashMap<String, String>();
Properties prop = new Properties();
try {
prop.load(BigDataPropertiesUtil.class.getResourceAsStream("/bigdata.properties"));
for(Entry<Object, Object> entry : prop.entrySet()) {
if(entry.getKey() == null || entry.getValue() == null) {
continue;
}
attributes.put(entry.getKey().toString(), entry.getValue().toString());
}
} catch (IOException e) {
e.printStackTrace();
ARE.getLog().error("init BigDataPropertiesUtil info failed");
}
ARE.getLog().info("init BigDataPropertiesUtil info success");
}
public static void destroy() {
if(attributes != null) attributes.clear();
}
public static String get(String propName) {
if(attributes == null) load();
return attributes.get(propName);
}
}