|
|
@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.SocketTimeoutException; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
@ -30,6 +31,8 @@ import static com.ruoyi.common.constant.Constants.HTTP; |
|
|
|
@RequestMapping("/broadcast") |
|
|
|
public class BroadcastController extends BaseController { |
|
|
|
|
|
|
|
|
|
|
|
private static int numberOfReconnections = 1; |
|
|
|
@Resource |
|
|
|
private RedisCache redisCache; |
|
|
|
private static final String ID = "admin"; |
|
|
@ -52,6 +55,7 @@ public class BroadcastController extends BaseController { |
|
|
|
public AjaxResult logIn(@PathVariable String event, HashMap<String, Object> returnParameters) { |
|
|
|
Object accessToken = returnParameters.get("accessToken"); |
|
|
|
System.out.println(accessToken); |
|
|
|
System.out.println("广播回调事件函数"); |
|
|
|
|
|
|
|
//todo
|
|
|
|
|
|
|
@ -65,20 +69,33 @@ public class BroadcastController extends BaseController { |
|
|
|
@PostMapping(value = "/broadcastFunctionCall") |
|
|
|
public JSONObject nearCamListDistance(@RequestBody JSONObject params) throws HttpException, IOException { |
|
|
|
JSONObject jsonResult = null; |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
OkHttp okHttp = new OkHttp(1); |
|
|
|
RequestParams requestParams = new RequestParams(params); |
|
|
|
String tokenRoadTestBroadcastPlatform = redisCache.getCacheObject(TOKENKEY); |
|
|
|
if (tokenRoadTestBroadcastPlatform == null) { |
|
|
|
tokenRoadTestBroadcastPlatform = getToken(); |
|
|
|
} |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(new HashMap<>()) |
|
|
|
.url(URL + params.getString("functionType") + ".do?accessToken=" + tokenRoadTestBroadcastPlatform) // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.post(); // 请求方法
|
|
|
|
if (response.body() != null) { |
|
|
|
jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
|
try { |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(new HashMap<>()) |
|
|
|
.url(URL + params.getString("functionType") + ".do?accessToken=" + tokenRoadTestBroadcastPlatform) // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.post(); // 请求方法
|
|
|
|
if (response.body() != null) { |
|
|
|
jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
|
} |
|
|
|
} catch (SocketTimeoutException e) { |
|
|
|
if (numberOfReconnections >3){ |
|
|
|
numberOfReconnections += 1; |
|
|
|
getToken(); |
|
|
|
return nearCamListDistance(params); |
|
|
|
}else { |
|
|
|
jsonResult = new JSONObject(); |
|
|
|
jsonResult.put("code","400"); |
|
|
|
jsonResult.put("msg","语音广播连接错误"); |
|
|
|
return jsonResult; |
|
|
|
} |
|
|
|
} |
|
|
|
return jsonResult; |
|
|
|
} |
|
|
@ -97,10 +114,8 @@ public class BroadcastController extends BaseController { |
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.post(); // 请求方法
|
|
|
|
if (response.body() != null) { |
|
|
|
//accessToken
|
|
|
|
String accessToken = JSONObject.parseObject(response.body().string()).getString("accessToken"); |
|
|
|
//RedisCache redisCache = new RedisCache();
|
|
|
|
redisCache.setCacheObject(TOKENKEY, accessToken, 100, TimeUnit.MINUTES); |
|
|
|
redisCache.setCacheObject(TOKENKEY, accessToken, 5, TimeUnit.MINUTES); |
|
|
|
return accessToken; |
|
|
|
} |
|
|
|
return null; |
|
|
|