修改MongoDB地址

This commit is contained in:
2025-04-16 18:32:20 +08:00
parent 3c6d78b6d0
commit fe8564d120
8 changed files with 33 additions and 266 deletions
@@ -1,190 +0,0 @@
//package com.fangjia.open.controllers;
//
//import com.google.gson.Gson;
//import com.google.gson.JsonArray;
//import com.google.gson.JsonObject;
//import org.apache.http.HttpEntity;
//import org.apache.http.client.methods.CloseableHttpResponse;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.entity.ContentType;
//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 sun.misc.BASE64Encoder;
//
//import java.io.IOException;
//import java.net.Authenticator;
//import java.net.InetSocketAddress;
//import java.net.PasswordAuthentication;
//import java.net.Proxy;
//import java.nio.charset.Charset;
//import java.nio.charset.StandardCharsets;
//import java.util.Base64;
//import java.util.HashMap;
//import java.util.Map;
//
////public class Test {
//// public static void main(String[] args) throws IOException {
//// // 目标URL
//// String targetURL = "http://146.56.217.44:9010/uams/farmer/all/v3/sign";
////
//// // 设置代理
//// String proxyHost = "tunnel2.qg.net";
//// int proxyPort = 14186;
////
//// // 设置代理用户名和密码
//// final String proxyUsername = "113BBC06";
//// final String proxyPassword = "3B2FBD05B0AF";
////
//// // 设置请求的JSON数据
//// String address = "江苏省扬州市宝应县安宜镇宝应大道88号";
//// String type = "1";
//// String jsonData = "{\"address\":\"" + address + "\",\"type\":\"" + type + "\"}";
////
//// // 设置HTTP基本认证
//// String authKey = proxyUsername;
//// String password = proxyPassword;
//// String auth = authKey + ":" + password;
//// String authHeader = "Basic " + new BASE64Encoder().encode(auth.getBytes(Charset.forName("UTF-8")));
////
//// // 创建HTTP客户端
//// CloseableHttpClient httpClient = HttpClients.createDefault();
//// HttpPost httpPost = new HttpPost(targetURL);
////
//// // 设置代理
//// Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
////
//// // 设置代理认证
//// Authenticator.setDefault(new Authenticator() {
//// protected PasswordAuthentication getPasswordAuthentication() {
//// return new PasswordAuthentication(proxyUsername, proxyPassword.toCharArray());
//// }
//// });
////
//// // 设置请求头
//// httpPost.setHeader("Content-Type", "application/json");
//// httpPost.setHeader("Accept", "*/*");
//// httpPost.setHeader("Host", "146.56.217.44:9010");
//// httpPost.setHeader("Proxy-Authorization", authHeader);
////
//// // 设置请求体
//// StringEntity stringEntity = new StringEntity(jsonData, ContentType.APPLICATION_JSON);
//// httpPost.setEntity(stringEntity);
////
//// // 发送POST请求
//// CloseableHttpResponse httpResponse = httpClient.execute(httpPost);
////
//// // 获取响应
//// HttpEntity responseEntity = httpResponse.getEntity();
//// String responseString = EntityUtils.toString(responseEntity);
//// System.out.println(responseString);
////
//// // 关闭连接
//// httpResponse.close();
//// httpClient.close();
//// }
////}
//
//public class Test {
// public static void main(String[] args) throws IOException {
// Map<String, String> map = senRequest("江苏省泰州市靖江市通江路37号", "1");
// System.out.println(map);
//
// }
//
// private static Map<String, String> senRequest(String address, String type) throws IOException {
// String targetURL = "http://146.56.217.44:9010/uams/farmer/all/v3/sign";
// String proxyHost = "tunnel2.qg.net";
// int proxyPort = 14186;
// final String proxyUsername = "113BBC06";
// final String proxyPassword = "3B2FBD05B0AF";
// String jsonData = "{\"address\":\"" + address + "\",\"type\":\"" + type + "\"}";
// String authKey = proxyUsername;
// String password = proxyPassword;
// String auth = authKey + ":" + password;
// String authHeader = "Basic " + new BASE64Encoder().encode(auth.getBytes(Charset.forName("UTF-8")));
//
// CloseableHttpClient httpClient = HttpClients.createDefault();
// HttpPost httpPost = new HttpPost(targetURL);
// Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
// Authenticator.setDefault(new Authenticator() {
// protected PasswordAuthentication getPasswordAuthentication() {
// return new PasswordAuthentication(proxyUsername, proxyPassword.toCharArray());
// }
// });
// httpPost.setHeader("Content-Type", "application/json");
// httpPost.setHeader("Accept", "*/*");
// httpPost.setHeader("Host", "146.56.217.44:9010");
// httpPost.setHeader("Proxy-Authorization", authHeader);
// StringEntity stringEntity = new StringEntity(jsonData, ContentType.APPLICATION_JSON);
// httpPost.setEntity(stringEntity);
//
// CloseableHttpResponse httpResponse = null;
// int retryCount = 2; // 设置重试次数
// int retryDelay = 10; // 设置重试延迟时间(毫秒)
// boolean success = false;
// for (int i = 0; i < retryCount; i++) {
// try {
// httpResponse = httpClient.execute(httpPost);
// success = true;
// break;
// } catch (IOException e) {
// System.err.println("代理请求失败,进行重试...");
// try {
// Thread.sleep(retryDelay);
// } catch (InterruptedException ex) {
// Thread.currentThread().interrupt();
// }
// }
// }
//
// if (success) {
// HttpEntity responseEntity = httpResponse.getEntity();
// String responseString = EntityUtils.toString(responseEntity);
//
// // 使用 Gson 解析 JSON 字符串
// Gson gson = new Gson();
// JsonObject jsonObject = gson.fromJson(responseString, JsonObject.class);
//
//
// // 创建 Map 存储各个值
// Map<String, String> dataMap = new HashMap<String, String>();
//
// // 获取各个值并放入 Map
// dataMap.put("code", jsonObject.get("code").getAsString());
// dataMap.put("msg", jsonObject.get("msg").getAsString());
// JsonObject data = jsonObject.getAsJsonObject("data");
// dataMap.put("version", data.get("version").getAsString());
// dataMap.put("province", data.get("province").getAsString());
// dataMap.put("city", data.get("city").getAsString());
// dataMap.put("district", data.get("district").getAsString());
// dataMap.put("town", data.get("town").getAsString());
// dataMap.put("village", data.get("village").getAsString());
// dataMap.put("provinceCode", data.get("provinceCode").getAsString());
// dataMap.put("cityCode", data.get("cityCode").getAsString());
// dataMap.put("districtCode", data.get("districtCode").getAsString());
// dataMap.put("townCode", data.get("townCode").getAsString());
// dataMap.put("villageCode", data.get("villageCode").getAsString());
// dataMap.put("areaCode", data.get("areaCode").getAsString());
// dataMap.put("farmer", data.get("farmer").getAsString());
// dataMap.put("isGovt", data.get("isGovt").getAsString());
// dataMap.put("govtAddr", data.get("govtAddr").isJsonNull() ? null : data.get("govtAddr").getAsString()); // 对于可能为 null 的值,需要判断是否为空
// JsonArray indusParkList = data.get("indusParkList").isJsonNull() ? null : data.get("indusParkList").getAsJsonArray();
// if (indusParkList != null) {
// JsonObject jsonObject1 = gson.fromJson(indusParkList.get(0), JsonObject.class);
// dataMap.put("devName",jsonObject1.get("indusParkName").getAsString());
// dataMap.put("devLevel",jsonObject1.get("indusParkLevel").getAsString());
// }
//
// httpResponse.close();
// return dataMap;
// } else {
// System.err.println("重试次数已用完,请求失败。");
// }
//
// httpClient.close();
// return null;
// }
//}
//