hzb 2 vuotta sitten
vanhempi
commit
0b1560fd9b

+ 94 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpsUtil.java

@@ -0,0 +1,94 @@
+package com.ruoyi.common.utils.http;
+
+
+import javax.net.ssl.*;
+import java.io.*;
+import java.net.URL;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+public class HttpsUtil {
+
+    private static final class DefaultTrustManager implements X509TrustManager {
+           @Override
+           public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+           }
+
+           @Override
+           public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+           }
+
+           @Override
+           public X509Certificate[] getAcceptedIssuers() {
+               return null;
+           }
+       }
+
+       private static HttpsURLConnection getHttpsURLConnection(String uri, String method) throws IOException {
+           SSLContext ctx = null;
+           try {
+               ctx = SSLContext.getInstance("TLS");
+               ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom());
+           } catch (KeyManagementException e) {
+               e.printStackTrace();
+           } catch (NoSuchAlgorithmException e) {
+               e.printStackTrace();
+           }
+           SSLSocketFactory ssf = ctx.getSocketFactory();
+
+           URL url = new URL(uri);
+           HttpsURLConnection httpsConn = (HttpsURLConnection) url.openConnection();
+           httpsConn.setSSLSocketFactory(ssf);
+           httpsConn.setHostnameVerifier(new HostnameVerifier() {
+               @Override
+               public boolean verify(String arg0, SSLSession arg1) {
+                   return true;
+               }
+           });
+           httpsConn.setRequestMethod(method);
+           httpsConn.setDoInput(true);
+           httpsConn.setDoOutput(true);
+           return httpsConn;
+       }
+
+       private static byte[] getBytesFromStream(InputStream is) throws IOException {
+           ByteArrayOutputStream baos = new ByteArrayOutputStream();
+           byte[] kb = new byte[1024];
+           int len;
+           while ((len = is.read(kb)) != -1) {
+               baos.write(kb, 0, len);
+           }
+           byte[] bytes = baos.toByteArray();
+           baos.close();
+           is.close();
+           return bytes;
+       }
+
+       private static void setBytesToStream(OutputStream os, byte[] bytes) throws IOException {
+           ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+           byte[] kb = new byte[1024];
+           int len;
+           while ((len = bais.read(kb)) != -1) {
+               os.write(kb, 0, len);
+           }
+           os.flush();
+           os.close();
+           bais.close();
+       }
+
+       public static byte[] doGet(String uri) throws IOException {
+           HttpsURLConnection httpsConn = getHttpsURLConnection(uri, "GET");
+           return getBytesFromStream(httpsConn.getInputStream());
+       }
+
+       public static String doPost(String uri, String data) throws IOException {
+           HttpsURLConnection httpsConn = getHttpsURLConnection(uri, "POST");
+           setBytesToStream(httpsConn.getOutputStream(), data.getBytes());
+           byte[] ret = getBytesFromStream(httpsConn.getInputStream());
+           return new String(ret);
+       }
+
+}

+ 17 - 9
ruoyi-system/src/main/java/com/ruoyi/opt/service/impl/ProcessInfoServiceImpl.java

@@ -12,6 +12,7 @@ import com.ruoyi.common.request.CheckInformBo;
 import com.ruoyi.common.request.PayInfomBo;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.http.HttpUtils;
+import com.ruoyi.common.utils.http.HttpsUtil;
 import com.ruoyi.opt.domain.CompanyInfo;
 import com.ruoyi.opt.mapper.CompanyInfoMapper;
 import lombok.extern.slf4j.Slf4j;
@@ -114,15 +115,22 @@ public class ProcessInfoServiceImpl implements IProcessInfoService
                     return AjaxResult.error(resultMap.get("message").toString());
                 }
             } else if ("05".equals(processInfo.getProcessStsCd())){
-                String payResult = getPayInform(processInfo);
-                //解析json结果
-                Map<String, Object> resultMap = JSON.parseObject(payResult, Map.class);
-                if ("0000".equals(resultMap.get("code").toString())){
-                    //成功
-                    int i = processInfoMapper.updateProcessInfo(processInfo);
-                    return AjaxResult.success();
-                } else {
-                    return AjaxResult.error(resultMap.get("message").toString());
+                try {
+                    byte[] doGet = HttpsUtil.doGet("https://www2.laikuaidian.cn/fdd/extsign.do?processId=" + processInfo.getProcessId() + "&bankId=ZLTX");
+                    String url = doGet.toString();
+
+                    String payResult = getPayInform(processInfo);
+                    //解析json结果
+                    Map<String, Object> resultMap = JSON.parseObject(payResult, Map.class);
+                    if ("0000".equals(resultMap.get("code").toString())){
+                        //成功
+                        int i = processInfoMapper.updateProcessInfo(processInfo);
+                        return AjaxResult.success();
+                    } else {
+                        return AjaxResult.error(resultMap.get("message").toString());
+                    }
+                }catch (Exception e){
+                    return AjaxResult.error(e.getMessage());
                 }
             } else {
                 int i = processInfoMapper.updateProcessInfo(processInfo);