Merge branch 'uat_保证金天擎调用' into 'uat_code'
增加天擎接口https请求 ssl证书 See merge request eshop/biz_service_ebtp_extend!118
This commit is contained in:
@ -28,6 +28,7 @@ import com.chinaunicom.mall.ebtp.extend.crypconfigure.dao.CrypConfigureMapper;
|
||||
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypBean;
|
||||
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypConfigure;
|
||||
import com.chinaunicom.mall.ebtp.extend.crypconfigure.service.ICrypConfigureService;
|
||||
import com.chinaunicom.mall.ebtp.extend.crypconfigure.util.SslUtil;
|
||||
import com.chinaunicom.mall.ebtp.extend.uniBss.UniBssUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@ -114,7 +115,7 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
|
||||
|
||||
map.put("SIGN", sign);
|
||||
|
||||
json = getUniBss(bean.getReqName(), map);
|
||||
json = getCiticUniBss(bean.getReqName(), map);
|
||||
|
||||
blockChainLog.setParam(json);//请求参数
|
||||
log.info("------请求天擎接口---json参数:---"+json);
|
||||
@ -388,7 +389,6 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
|
||||
|
||||
return JSON.toJSONString(uniBss);
|
||||
}
|
||||
|
||||
/**
|
||||
* 中信天擎接口 数据格式 获取加密签名
|
||||
* REQ:{
|
||||
@ -483,6 +483,10 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
|
||||
|
||||
try {
|
||||
URL url = new URL(path);
|
||||
if("https".equals(url.getProtocol())){
|
||||
SslUtil.ignoreSsl();
|
||||
}
|
||||
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
PrintWriter out = null;
|
||||
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||
@ -500,6 +504,7 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
|
||||
out = new PrintWriter(conn.getOutputStream());
|
||||
out.print(data);
|
||||
out.flush();
|
||||
|
||||
InputStream is = conn.getInputStream();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
@ -516,7 +521,6 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, UnsupportedEncodingException {
|
||||
//String json = "{\"RESULT_ID\":\"1\",\"TP_ID\":\"2\",\"SECTION_ID\":\"3\",\"REPORT_ID\":\"4\",\"RESULTDETAIL\":[{\"RESULT_DETAIL_ID\":\"51\",\"RESULT_ID\":\"52\",\"TENDERER_ID\":\"53\",\"WINNER_CANDIDATE\":\"54\",\"PRICE\":\"55\",\"PRICE_REVIEW\":\"56\",\"BUSINESS_SCORE\":\"57\",\"TECHNICAL_SCORE\":\"58\",\"SERVICE_SCORE\":\"59\",\"PRICE_SCORE\":\"60\",\"TOTAL_SCORE\":\"61\",\"CONTRACTED_MONEY\":\"62\",\"TAX_RATE_PRICE\":\"63\",\"SCOREDETAIL\":[{\"RESULT_DETAIL_ID\":\"71\",\"TENDERER_ID\":\"72\",\"USER_ID\":\"73\",\"BUSINESS_SCORE\":\"74\",\"TECHNICAL_SCORE\":\"75\",\"SERVICE_SCORE\":\"76\",\"PRICE_SCORE\":\"77\"}]}]}";
|
||||
|
||||
@ -559,6 +563,5 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
|
||||
// boolean isOk = crypService.verifyObject(bean);
|
||||
// System.out.println("verify result of Map: "+ isOk);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.crypconfigure.util;
|
||||
import javax.net.ssl.*;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
public class SslUtil {
|
||||
|
||||
private static void trustAllHttpsCertificates() throws Exception {
|
||||
TrustManager[] trustAllCerts = new TrustManager[1];
|
||||
TrustManager tm = new miTM();
|
||||
trustAllCerts[0] = tm;
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, trustAllCerts, null);
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
}
|
||||
|
||||
static class miTM implements TrustManager, X509TrustManager {
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isServerTrusted(X509Certificate[] certs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isClientTrusted(X509Certificate[] certs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] certs, String authType)
|
||||
throws CertificateException {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 忽略HTTPS请求的SSL证书,必须在openConnection之前调用
|
||||
*/
|
||||
public static void ignoreSsl() throws Exception{
|
||||
HostnameVerifier hv = (urlHostName, session) -> true;
|
||||
trustAllHttpsCertificates();
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(hv);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user