|
@@ -1,6 +1,7 @@
|
|
|
package com.caimei365.tools.utils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.InputStreamReader;
|
|
@@ -8,6 +9,8 @@ import java.io.OutputStream;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 短信工具类
|
|
@@ -32,6 +35,9 @@ public class SmsUtil {
|
|
|
/** 请求地址 */
|
|
|
private static final String SMS_URL = "http://smssh1.253.com/msg/send/json";
|
|
|
|
|
|
+ @Value("${caimei.coreDomain}")
|
|
|
+ private static String profile;
|
|
|
+
|
|
|
private SmsUtil(){}
|
|
|
|
|
|
/**
|
|
@@ -66,32 +72,41 @@ public class SmsUtil {
|
|
|
String requestContent = params.toString();
|
|
|
URL url;
|
|
|
try {
|
|
|
- url = new URL(SMS_URL);
|
|
|
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
- connection.setRequestMethod("POST");
|
|
|
- connection.setConnectTimeout(10000);
|
|
|
- connection.setReadTimeout(10000);
|
|
|
- // 发送POST请求必须设置如下两行
|
|
|
- connection.setDoOutput(true);
|
|
|
- connection.setDoInput(true);
|
|
|
- connection.setRequestProperty("Charset", "UTF-8");
|
|
|
- connection.setRequestProperty("Content-Type", "application/json");
|
|
|
- connection.connect();
|
|
|
- OutputStream os=connection.getOutputStream();
|
|
|
- os.write(requestContent.getBytes(StandardCharsets.UTF_8));
|
|
|
- os.flush();
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- int httpRspCode = connection.getResponseCode();
|
|
|
- if (httpRspCode == HttpURLConnection.HTTP_OK) {
|
|
|
- // 开始获取数据
|
|
|
- BufferedReader br = new BufferedReader(
|
|
|
- new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
|
|
|
- String line;
|
|
|
- while ((line = br.readLine()) != null) {
|
|
|
- sb.append(line);
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ list.add("15917362709");
|
|
|
+ list.add("15814011616");
|
|
|
+ list.add("13100721916");
|
|
|
+ list.add("15113936829");
|
|
|
+ list.add("15827317748");
|
|
|
+ list.add("18476937515");
|
|
|
+ if (profile.contains("core.caimei365.com") || list.contains(mobile)) {
|
|
|
+ url = new URL(SMS_URL);
|
|
|
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
+ connection.setRequestMethod("POST");
|
|
|
+ connection.setConnectTimeout(10000);
|
|
|
+ connection.setReadTimeout(10000);
|
|
|
+ // 发送POST请求必须设置如下两行
|
|
|
+ connection.setDoOutput(true);
|
|
|
+ connection.setDoInput(true);
|
|
|
+ connection.setRequestProperty("Charset", "UTF-8");
|
|
|
+ connection.setRequestProperty("Content-Type", "application/json");
|
|
|
+ connection.connect();
|
|
|
+ OutputStream os=connection.getOutputStream();
|
|
|
+ os.write(requestContent.getBytes(StandardCharsets.UTF_8));
|
|
|
+ os.flush();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ int httpRspCode = connection.getResponseCode();
|
|
|
+ if (httpRspCode == HttpURLConnection.HTTP_OK) {
|
|
|
+ // 开始获取数据
|
|
|
+ BufferedReader br = new BufferedReader(
|
|
|
+ new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
|
|
|
+ String line;
|
|
|
+ while ((line = br.readLine()) != null) {
|
|
|
+ sb.append(line);
|
|
|
+ }
|
|
|
+ br.close();
|
|
|
+ return sb.toString();
|
|
|
}
|
|
|
- br.close();
|
|
|
- return sb.toString();
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|