2 changed files with 117 additions and 0 deletions
@ -0,0 +1,61 @@ |
|||
package com.zdxt.enforcementcode.controller.app.utils; |
|||
|
|||
import org.apache.http.client.config.RequestConfig; |
|||
import org.apache.http.client.methods.CloseableHttpResponse; |
|||
import org.apache.http.client.methods.HttpGet; |
|||
import org.apache.http.config.Registry; |
|||
import org.apache.http.config.RegistryBuilder; |
|||
import org.apache.http.conn.socket.ConnectionSocketFactory; |
|||
import org.apache.http.conn.socket.PlainConnectionSocketFactory; |
|||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
|||
import org.apache.http.impl.client.CloseableHttpClient; |
|||
import org.apache.http.impl.client.HttpClients; |
|||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; |
|||
import org.apache.http.util.EntityUtils; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
|
|||
import javax.net.ssl.SSLContext; |
|||
import javax.net.ssl.TrustManager; |
|||
import javax.net.ssl.X509TrustManager; |
|||
import java.security.cert.X509Certificate; |
|||
|
|||
public class HttpUtil { |
|||
private static final Logger log = LoggerFactory.getLogger(HttpUtil.class); |
|||
|
|||
public static String HttpSendGet(String url,String accessToken) throws Exception{ |
|||
HttpGet httpGet = new HttpGet(url); |
|||
CloseableHttpResponse response=null; |
|||
SSLContext sc = SSLContext.getInstance("SSL"); |
|||
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom()); |
|||
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() |
|||
.register("http", PlainConnectionSocketFactory.INSTANCE) |
|||
.register("https",new SSLConnectionSocketFactory(sc)) |
|||
.build(); |
|||
PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(registry); |
|||
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(manager).build(); |
|||
RequestConfig config = RequestConfig.custom(). |
|||
setConnectTimeout(300000). |
|||
setSocketTimeout(300000). |
|||
build(); |
|||
httpGet.setConfig(config); |
|||
httpGet.setHeader("accessToken",accessToken); |
|||
httpGet.setHeader("Content-Type","application/json"); |
|||
response = httpClient.execute(httpGet); |
|||
return EntityUtils.toString(response.getEntity(),"utf-8"); |
|||
} |
|||
|
|||
public static class TrustAnyTrustManager implements X509TrustManager { |
|||
@Override |
|||
public void checkClientTrusted(X509Certificate[] chain, String authType) {} |
|||
|
|||
@Override |
|||
public void checkServerTrusted(X509Certificate[] chain, String authType) {} |
|||
|
|||
@Override |
|||
public X509Certificate[] getAcceptedIssuers() { |
|||
return new X509Certificate[] {}; |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
/** |
|||
* 执法/入企时间可选范围:当天起向前推 N 天(与 non-law/sign.vue 一致) |
|||
*/ |
|||
export function getBeforeDate(num, time) { |
|||
let d = time ? new Date(time) : new Date(); |
|||
d.setDate(d.getDate() - num); |
|||
const year = d.getFullYear(); |
|||
const mon = d.getMonth() + 1; |
|||
const day = d.getDate(); |
|||
return `${year}-${mon < 10 ? '0' + mon : mon}-${day < 10 ? '0' + day : day}`; |
|||
} |
|||
|
|||
/** @param {number} daysBack 向前可选天数,默认 10 */ |
|||
export function getEnforcementTimeDateRange(daysBack = 10) { |
|||
const now = new Date(); |
|||
const minStr = getBeforeDate(daysBack, now); |
|||
const [y, m, d] = minStr.split('-').map(Number); |
|||
return { |
|||
minDate: new Date(y, m - 1, d), |
|||
maxDate: new Date(now.getFullYear(), now.getMonth(), now.getDate()), |
|||
currentDate: [ |
|||
String(now.getFullYear()), |
|||
String(now.getMonth() + 1).padStart(2, '0'), |
|||
String(now.getDate()).padStart(2, '0'), |
|||
], |
|||
}; |
|||
} |
|||
|
|||
export function parseEnforcementTimeToPicker(value) { |
|||
if (!value) return null; |
|||
const datePart = String(value).split(' ')[0]; |
|||
const parts = datePart.split('-'); |
|||
if (parts.length < 3) return null; |
|||
return [parts[0], parts[1], parts[2]]; |
|||
} |
|||
|
|||
/** 日期选择确认后:选中日期 + 当前时分秒,如 2026-06-03 14:25:30 */ |
|||
export function buildEnforcementTimeFromPicker(selectedValues) { |
|||
if (!selectedValues || selectedValues.length < 3) return ''; |
|||
const now = new Date(); |
|||
const d = new Date( |
|||
Number(selectedValues[0]), |
|||
Number(selectedValues[1]) - 1, |
|||
Number(selectedValues[2]), |
|||
now.getHours(), |
|||
now.getMinutes(), |
|||
now.getSeconds() |
|||
); |
|||
const year = d.getFullYear(); |
|||
const month = String(d.getMonth() + 1).padStart(2, '0'); |
|||
const day = String(d.getDate()).padStart(2, '0'); |
|||
const hour = String(d.getHours()).padStart(2, '0'); |
|||
const minute = String(d.getMinutes()).padStart(2, '0'); |
|||
const second = String(d.getSeconds()).padStart(2, '0'); |
|||
return `${year}-${month}-${day} ${hour}:${minute}:${second}`; |
|||
} |
|||
Loading…
Reference in new issue