parent
b78fee1dd0
commit
cd010d3be7
|
@ -18,12 +18,17 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 企业 BusinessServiceImpl
|
||||
|
@ -132,45 +137,37 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business> i
|
|||
|
||||
|
||||
|
||||
private static void extracted(Business business) {
|
||||
String postUrl="http://175.24.138.82:10006/webhook/%E6%9C%AA%E5%91%BD%E5%90%8D%E9%A1%B9%E7%9B%AE";
|
||||
private void extracted(Business business){
|
||||
String postUrl = "http://192.168.120.128/webhook/%E6%96%B0%E5%BB%BAmysql%E6%9C%8D%E5%8A%A1";
|
||||
HashMap<String, String> hashMap = new HashMap<>();
|
||||
hashMap.put("businessId", business.getId()+ business.getName());
|
||||
hashMap.put("mysqlPort",String.valueOf(3306+ business.getId()));
|
||||
String json = JSON.toJSONString(hashMap);
|
||||
// 3.创建连接与设置连接参数
|
||||
URL urlObj = null;
|
||||
try {
|
||||
urlObj = new URL(postUrl);
|
||||
HttpURLConnection httpConn = (HttpURLConnection) urlObj.openConnection();
|
||||
httpConn.setRequestMethod("POST");
|
||||
httpConn.setRequestProperty("Charset", "UTF-8");
|
||||
// POST请求且JSON数据,必须设置
|
||||
httpConn.setRequestProperty("Content-Type", "application/json");
|
||||
// 打开输出流,默认是false
|
||||
httpConn.setDoOutput(true);
|
||||
// // 打开输入流,默认是true,可省略
|
||||
// httpConn.setDoInput(true);
|
||||
// 4.从HttpURLConnection获取输出流和写数据
|
||||
OutputStream oStream = httpConn.getOutputStream();
|
||||
oStream.write(json.getBytes());
|
||||
oStream.flush();
|
||||
// 5.发起http调用(getInputStream触发http请求)
|
||||
if (httpConn.getResponseCode() != 200) {
|
||||
throw new Exception("调用服务端异常.");
|
||||
}
|
||||
// 6.从HttpURLConnection获取输入流和读数据
|
||||
BufferedReader br = new BufferedReader(
|
||||
new InputStreamReader(httpConn.getInputStream()));
|
||||
String resultData = br.readLine();
|
||||
System.out.println("从服务端返回结果: " + resultData);
|
||||
// 7.关闭HttpURLConnection连接
|
||||
httpConn.disconnect();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
hashMap.put("businessId",business.getId() + business.getName());
|
||||
hashMap.put("mysqlPort",String.valueOf(3306 + business.getId()));
|
||||
String json = JSON.toJSONString(hashMap);
|
||||
|
||||
// 3.创建链接与设置连接参数
|
||||
URL urlObj = null;
|
||||
|
||||
try {
|
||||
urlObj = new URL(postUrl);
|
||||
HttpURLConnection httpConn = (HttpURLConnection) urlObj.openConnection();
|
||||
httpConn.setRequestMethod("POST");
|
||||
httpConn.setRequestProperty("Charset","UTF-8");
|
||||
|
||||
//post请求且json数据,必须设置
|
||||
httpConn.setRequestProperty("Content-Type","application/json");
|
||||
|
||||
//打开输出流,默认false
|
||||
httpConn.setDoOutput(true);
|
||||
|
||||
//4.从httpURLConnection获取输出流和写数据
|
||||
OutputStream oStream = httpConn.getOutputStream();
|
||||
oStream.write(json.getBytes());
|
||||
oStream.flush();
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue