|
@ -13,6 +13,7 @@ import java.io.IOException; |
|
|
import java.net.ConnectException; |
|
|
import java.net.ConnectException; |
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
@Component |
|
|
@Component |
|
|
public class ZLMRESTfulUtils { |
|
|
public class ZLMRESTfulUtils { |
|
@ -40,7 +41,7 @@ public class ZLMRESTfulUtils { |
|
|
|
|
|
|
|
|
FormBody.Builder builder = new FormBody.Builder(); |
|
|
FormBody.Builder builder = new FormBody.Builder(); |
|
|
builder.add("secret",mediaSecret); |
|
|
builder.add("secret",mediaSecret); |
|
|
if (param != null) { |
|
|
if (param != null && param.keySet().size() > 0) { |
|
|
for (String key : param.keySet()){ |
|
|
for (String key : param.keySet()){ |
|
|
builder.add(key, param.get(key).toString()); |
|
|
builder.add(key, param.get(key).toString()); |
|
|
} |
|
|
} |
|
@ -65,7 +66,7 @@ public class ZLMRESTfulUtils { |
|
|
logger.error(String.format("连接ZLM失败: %s, %s", e.getCause().getMessage(), e.getMessage())); |
|
|
logger.error(String.format("连接ZLM失败: %s, %s", e.getCause().getMessage(), e.getMessage())); |
|
|
logger.info("请检查media配置并确认ZLM已启动..."); |
|
|
logger.info("请检查media配置并确认ZLM已启动..."); |
|
|
}catch (IOException e) { |
|
|
}catch (IOException e) { |
|
|
e.printStackTrace(); |
|
|
logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage())); |
|
|
} |
|
|
} |
|
|
}else { |
|
|
}else { |
|
|
client.newCall(request).enqueue(new Callback(){ |
|
|
client.newCall(request).enqueue(new Callback(){ |
|
@ -74,14 +75,10 @@ public class ZLMRESTfulUtils { |
|
|
public void onResponse(@NotNull Call call, @NotNull Response response){ |
|
|
public void onResponse(@NotNull Call call, @NotNull Response response){ |
|
|
if (response.isSuccessful()) { |
|
|
if (response.isSuccessful()) { |
|
|
try { |
|
|
try { |
|
|
String responseStr = response.body().string(); |
|
|
String responseStr = Objects.requireNonNull(response.body()).string(); |
|
|
if (responseStr != null) { |
|
|
|
|
|
callback.run(JSON.parseObject(responseStr)); |
|
|
callback.run(JSON.parseObject(responseStr)); |
|
|
}else { |
|
|
|
|
|
callback.run(null); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
e.printStackTrace(); |
|
|
logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage())); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|