|
@@ -2,20 +2,34 @@ package com.jpsoft.campus.modules.base.service.impl;
|
|
|
|
|
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.net.MediaType;
|
|
|
+import com.google.gson.Gson;
|
|
|
import com.jpsoft.campus.modules.base.entity.ApplicationPrimary;
|
|
|
import com.jpsoft.campus.modules.base.entity.UserInformationProvincial;
|
|
|
+import com.jpsoft.campus.modules.base.entity.UserInformationProvincialSubDeclares;
|
|
|
import com.jpsoft.campus.modules.base.service.ApplicationPrimaryService;
|
|
|
import com.jpsoft.campus.modules.base.service.UiasService;
|
|
|
import com.jpsoft.campus.modules.common.utils.FileUtil;
|
|
|
import com.jpsoft.campus.modules.common.utils.HttpConnectionUtil;
|
|
|
import com.jpsoft.campus.modules.common.utils.StringUtils;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
+import org.codehaus.jackson.map.ObjectMapper;
|
|
|
+import org.omg.CORBA.Request;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import javax.crypto.Cipher;
|
|
|
+import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
@@ -23,10 +37,15 @@ import java.nio.file.Paths;
|
|
|
import java.security.KeyFactory;
|
|
|
import java.security.PrivateKey;
|
|
|
import java.security.spec.PKCS8EncodedKeySpec;
|
|
|
-import java.util.Base64;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import javax.net.ssl.*;
|
|
|
+import java.io.*;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.security.cert.X509Certificate;
|
|
|
+import java.util.Base64;
|
|
|
|
|
|
@Transactional
|
|
|
@Component(value="uiasServiceImpl")
|
|
@@ -108,55 +127,238 @@ public class UiasServiceImpl implements UiasService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String applyno(String path,String token){
|
|
|
- HashMap<String, Object> map = new HashMap<>();
|
|
|
- map.put("sceneNo","42PC08017123");
|
|
|
- map.put("sceneBusiness",4);
|
|
|
+ public String applyno(String path,String token) {
|
|
|
+ try {
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("sceneNo", "42PCN0010224J1003");
|
|
|
+ map.put("sceneBusiness", 4);
|
|
|
|
|
|
- HashMap<String, String> headersMap = new HashMap<>();
|
|
|
- map.put("Authorization",token);
|
|
|
+ HashMap<String, String> headersMap = new HashMap<>();
|
|
|
+ headersMap.put("Authorization", token);
|
|
|
|
|
|
- String body = HttpRequest.post(path + "/gateway/api/sbk/declare/ownerDeclare/applyno").header("Authorization",token).form(map).execute().body();
|
|
|
- JSONObject jsonBody = JSONObject.parseObject(body);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("sceneNo", "42PC08017123");
|
|
|
+ jsonObject.put("sceneBusiness", 4);
|
|
|
|
|
|
- if (jsonBody!=null) {
|
|
|
- String code = jsonBody.getString("code");
|
|
|
- String data = jsonBody.getString("data");
|
|
|
+ String url = path + "/gateway/api/sbk/declare/ownerDeclare/applyno";
|
|
|
|
|
|
- return data;
|
|
|
- }
|
|
|
- else{
|
|
|
- return "";
|
|
|
+// String jsonInputString = "{\"sceneNo\": \"42PC08017123\", \"sceneBusiness\": 4}";
|
|
|
+
|
|
|
+ String jsonInputString = jsonObject.toString();
|
|
|
+ try {
|
|
|
+ // 信任所有证书
|
|
|
+ TrustManager[] trustAllCerts = new TrustManager[]{
|
|
|
+ new X509TrustManager() {
|
|
|
+ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkClientTrusted(
|
|
|
+ java.security.cert.X509Certificate[] certs, String authType) {
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkServerTrusted(
|
|
|
+ java.security.cert.X509Certificate[] certs, String authType) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ SSLContext sslContext = SSLContext.getInstance("TLS");
|
|
|
+ sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
|
|
|
+
|
|
|
+ HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
|
|
|
+
|
|
|
+ // 忽略主机名验证
|
|
|
+ HostnameVerifier allHostsValid = new HostnameVerifier() {
|
|
|
+ public boolean verify(String hostname, SSLSession session) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
|
|
|
+
|
|
|
+ // 创建连接
|
|
|
+ URL obj = new URL(url);
|
|
|
+ HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
|
|
+
|
|
|
+ // 设置请求方法、输出、输入
|
|
|
+ con.setRequestMethod("POST");
|
|
|
+ con.setRequestProperty("Content-Type", "application/json; utf-8");
|
|
|
+ con.setRequestProperty("Authorization", token);
|
|
|
+ con.setDoOutput(true);
|
|
|
+
|
|
|
+ // 发送POST输出
|
|
|
+ try (OutputStream os = con.getOutputStream()) {
|
|
|
+ byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
|
|
|
+ os.write(input, 0, input.length);
|
|
|
+ }
|
|
|
+
|
|
|
+ int responseCode = con.getResponseCode();
|
|
|
+ System.out.println("POST Response Code :: " + responseCode);
|
|
|
+
|
|
|
+ BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
|
|
+ String inputLine;
|
|
|
+ StringBuilder response = new StringBuilder();
|
|
|
+
|
|
|
+ while ((inputLine = in.readLine()) != null) {
|
|
|
+ response.append(inputLine);
|
|
|
+ }
|
|
|
+ in.close();
|
|
|
+
|
|
|
+ // 打印结果
|
|
|
+ System.out.println(response.toString());
|
|
|
+
|
|
|
+ String returnStr = response.toString();
|
|
|
+ // 解析JSON字符串
|
|
|
+ JSONObject returnJson = JSONObject.parseObject(returnStr);
|
|
|
+
|
|
|
+ // 提取data字段的值
|
|
|
+ String code = returnJson.getString("code");
|
|
|
+ String data = returnJson.getString("data");
|
|
|
+
|
|
|
+ return data;
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
@Autowired
|
|
|
private ApplicationPrimaryService applicationPrimaryService;
|
|
|
@Override
|
|
|
- public String submitAll(String path,String token, UserInformationProvincial provincial){
|
|
|
- HashMap<String, Object> map = new HashMap<>();
|
|
|
- map.put("declare",provincial);
|
|
|
+ public String submitAll(String path, String token, UserInformationProvincial provincial, UserInformationProvincialSubDeclares subDeclares){
|
|
|
+ try {
|
|
|
+// HashMap<String, Object> map = new HashMap<>();
|
|
|
+// map.put("declare", provincial);
|
|
|
+//
|
|
|
+// HashMap<String, String> headersMap = new HashMap<>();
|
|
|
+// headersMap.put("Authorization", token);
|
|
|
+//
|
|
|
+// ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+// String jsonString = objectMapper.writeValueAsString(map);
|
|
|
+// System.out.println(jsonString);
|
|
|
|
|
|
- HashMap<String, String> headersMap = new HashMap<>();
|
|
|
- map.put("Authorization",token);
|
|
|
+// String body = HttpRequest.post(path + "/gateway/api/sbk/declare/subDeclare/submitAll").header("Authorization", token).form(jsonString).execute().body();
|
|
|
+// System.out.println(body);
|
|
|
+// JSONObject jsonBody = JSONObject.parseObject(body);
|
|
|
|
|
|
- String body = HttpRequest.post(path + "/gateway/api/sbk/declare/subDeclare/submitAll").header("Authorization",token).form(map).execute().body();
|
|
|
- JSONObject jsonBody = JSONObject.parseObject(body);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("declare",provincial);
|
|
|
|
|
|
- if (jsonBody!=null) {
|
|
|
- String code = jsonBody.getString("code");
|
|
|
- String data = jsonBody.getString("data");
|
|
|
|
|
|
- ApplicationPrimary applicationPrimary = applicationPrimaryService.get(provincial.getApplicantId());
|
|
|
- applicationPrimary.setCode(code);
|
|
|
- applicationPrimary.setApplyNo(provincial.getApplyNo());
|
|
|
- applicationPrimary.setSubNos(data);
|
|
|
- applicationPrimaryService.update(applicationPrimary);
|
|
|
|
|
|
- return data;
|
|
|
- }
|
|
|
- else{
|
|
|
- return "";
|
|
|
+ // 创建Gson对象
|
|
|
+ Gson gson = new Gson();
|
|
|
+
|
|
|
+ // 将实体类对象转换为JSON字符串
|
|
|
+ String jsonString = gson.toJson(provincial);
|
|
|
+
|
|
|
+ // 创建内部的JSONObject
|
|
|
+ JSONObject declare = JSONObject.parseObject(jsonString);
|
|
|
+
|
|
|
+ // 创建外部的JSONObject并添加内部对象和数组
|
|
|
+ JSONObject root = new JSONObject();
|
|
|
+ root.put("declare", declare);
|
|
|
+
|
|
|
+ List<UserInformationProvincialSubDeclares> subDeclaressss = new ArrayList<>();
|
|
|
+ subDeclaressss.add(subDeclares);
|
|
|
+// jsonObject.put("subDeclares",subDeclaressss);
|
|
|
+
|
|
|
+ root.put("subDeclares", subDeclaressss);
|
|
|
+
|
|
|
+ // 将JSONObject转换为字符串
|
|
|
+ String jsonInputString = root.toString();
|
|
|
+ System.out.println(jsonInputString);
|
|
|
+
|
|
|
+
|
|
|
+ String url = path + "/gateway/api/sbk/declare/subDeclare/submitAll";
|
|
|
+// String jsonInputString = jsonObject.toString();
|
|
|
+ try {
|
|
|
+ // 信任所有证书
|
|
|
+ TrustManager[] trustAllCerts = new TrustManager[]{
|
|
|
+ new X509TrustManager() {
|
|
|
+ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkClientTrusted(
|
|
|
+ java.security.cert.X509Certificate[] certs, String authType) {
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkServerTrusted(
|
|
|
+ java.security.cert.X509Certificate[] certs, String authType) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ SSLContext sslContext = SSLContext.getInstance("TLS");
|
|
|
+ sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
|
|
|
+
|
|
|
+ HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
|
|
|
+
|
|
|
+ // 忽略主机名验证
|
|
|
+ HostnameVerifier allHostsValid = new HostnameVerifier() {
|
|
|
+ public boolean verify(String hostname, SSLSession session) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
|
|
|
+
|
|
|
+ // 创建连接
|
|
|
+ URL obj = new URL(url);
|
|
|
+ HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
|
|
+
|
|
|
+ // 设置请求方法、输出、输入
|
|
|
+ con.setRequestMethod("POST");
|
|
|
+ con.setRequestProperty("Content-Type", "application/json; utf-8");
|
|
|
+ con.setRequestProperty("Authorization", token);
|
|
|
+ con.setDoOutput(true);
|
|
|
+
|
|
|
+ // 发送POST输出
|
|
|
+ try (OutputStream os = con.getOutputStream()) {
|
|
|
+ byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
|
|
|
+ os.write(input, 0, input.length);
|
|
|
+ }
|
|
|
+
|
|
|
+ int responseCode = con.getResponseCode();
|
|
|
+ System.out.println("POST Response Code :: " + responseCode);
|
|
|
+
|
|
|
+ BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
|
|
+ String inputLine;
|
|
|
+ StringBuilder response = new StringBuilder();
|
|
|
+
|
|
|
+ while ((inputLine = in.readLine()) != null) {
|
|
|
+ response.append(inputLine);
|
|
|
+ }
|
|
|
+ in.close();
|
|
|
+
|
|
|
+ // 打印结果
|
|
|
+ System.out.println(response.toString());
|
|
|
+
|
|
|
+ String returnStr = response.toString();
|
|
|
+ // 解析JSON字符串
|
|
|
+ JSONObject returnJson = JSONObject.parseObject(returnStr);
|
|
|
+
|
|
|
+ // 提取data字段的值
|
|
|
+ String code = returnJson.getString("code");
|
|
|
+ String data = returnJson.getString("data");
|
|
|
+
|
|
|
+ return data;
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+ return "";
|
|
|
}
|
|
|
}
|