From 6ae372817543fc46f6afa00de44daa557036978b Mon Sep 17 00:00:00 2001 From: xin <1099200748@qq.com> Date: Wed, 04 Jun 2025 21:41:48 +0800 Subject: [PATCH] 发送短信 --- oying-common/src/main/java/com/oying/utils/HttpRequest.java | 28 ++++++++++++++++++++++------ 1 files changed, 22 insertions(+), 6 deletions(-) diff --git a/oying-common/src/main/java/com/oying/utils/HttpRequest.java b/oying-common/src/main/java/com/oying/utils/HttpRequest.java index 486223c..215eb3e 100644 --- a/oying-common/src/main/java/com/oying/utils/HttpRequest.java +++ b/oying-common/src/main/java/com/oying/utils/HttpRequest.java @@ -14,6 +14,7 @@ import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; import javax.net.ssl.SSLContext; @@ -22,6 +23,8 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; import java.util.Map; /** @@ -79,20 +82,33 @@ return headers; } - private static HttpHeaders get() { + private static HttpHeaders getMsg() { HttpHeaders headers = new HttpHeaders(); - headers.set("accept", "*/*"); - headers.set("connection", "Keep-Alive"); - headers.set("user-agent", - "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); + List<MediaType> mediaTypes = new ArrayList<>(); + mediaTypes.add(MediaType.ALL); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); // 表单格式 + headers.setAccept(mediaTypes); + headers.setConnection("Keep-Alive"); + headers.set("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); return headers; + } + + /** + * 短信 + * http返回String xml + */ + public static String exchangeMsg(HttpMethod httpMethod, String url, MultiValueMap<String, String> map) { + HttpHeaders headers = getMsg(); + HttpEntity<Object> httpEntity = new HttpEntity<>(map, headers); + RestTemplate restTemplate = new RestTemplate(getFactory()); + return restTemplate.exchange(url, httpMethod, httpEntity, String.class).getBody(); } /** * http返回String */ public static String exchangeString(HttpMethod httpMethod, String url, Map<String, Object> map) { - HttpHeaders headers = get(); + HttpHeaders headers = getHeaders(); HttpEntity<Object> httpEntity = new HttpEntity<>(map, headers); RestTemplate restTemplate = new RestTemplate(); return restTemplate.exchange(url, httpMethod, httpEntity, String.class).getBody(); -- Gitblit v1.9.3