瀏覽代碼

新增接口live/getLiveUrlList返回所有直播地址

mengshibin 6 年之前
父節點
當前提交
dd3d82376d

+ 60 - 0
wsm-admin-web/src/main/java/com/wsm/admin/api/LiveController.java

@@ -0,0 +1,60 @@
+package com.wsm.admin.api;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.wsm.common.util.AjaxJson;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by Hb_zzZ on 2019/3/29.
+ */
+@RestController
+public class LiveController {
+
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Value("${live.key}")
+    private String liveKey;
+
+    @Value("${live.number.url}")
+    private String numberUrl;
+
+    @Value("${live.info.url}")
+    private String infoUrl;
+
+    @Autowired
+    private RestTemplate restTemplate;
+
+    @RequestMapping(value = {"/live/getLiveUrlList"})
+    public AjaxJson getLiveUrlList() {
+        JSONObject postData = new JSONObject();
+        postData.put("key", liveKey);
+        JSONObject json = restTemplate.postForObject(numberUrl, postData, JSONObject.class);
+        logger.info("接口数据:" + json.toString());
+
+        List<String> urlList = new ArrayList<>();
+        if(json.containsKey("sessions")){
+            JSONArray numberArray = json.getJSONArray("sessions");
+            for(int i = 0; i < numberArray.size(); i++){
+                JSONObject job = numberArray.getJSONObject(i);  // 遍历 jsonarray 数组,把每一个对象转成 json 对象
+                if(job.containsKey("serial_number")){
+                    postData.put("serial_number", job.get("serial_number"));
+                    JSONObject jsonObj = restTemplate.postForObject(infoUrl, postData, JSONObject.class);
+                    logger.info("直播url数据:" + jsonObj.get("hlsUrl").toString());
+                    urlList.add(jsonObj.get("hlsUrl").toString());
+                }
+            }
+        }
+        return AjaxJson.success(urlList);
+    }
+}

+ 1 - 0
wsm-admin-web/src/main/java/com/wsm/admin/shiro/ShiroConfig.java

@@ -103,6 +103,7 @@ public class ShiroConfig {
         //静态资源不拦截
         filterChainDefinitionMap.put("/", "anon");
         filterChainDefinitionMap.put("/webSocketServer/**", "anon");
+        filterChainDefinitionMap.put("/live/**", "anon");
         filterChainDefinitionMap.put("/static/**", "anon");
         filterChainDefinitionMap.put("/index.html", "anon");
         filterChainDefinitionMap.put("/mobile.html", "anon");

+ 7 - 0
wsm-application/src/main/java/com/wsm/Application.java

@@ -6,9 +6,11 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.web.servlet.ServletComponentScan;
 import org.springframework.boot.web.support.SpringBootServletInitializer;
 import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.web.client.RestTemplate;
 
 @ComponentScan(basePackages = {"com.wsm", "com.wsm.admin"})
 @SpringBootApplication(scanBasePackages = {"com.wsm", "com.wsm.admin"})
@@ -23,6 +25,11 @@ public class Application extends SpringBootServletInitializer {
         return application.sources(Application.class);
     }
 
+    @Bean
+    public RestTemplate restTemplate() {
+        return new RestTemplate();
+    }
+
     public static void main(String[] args) {
         SpringApplication.run(Application.class, args);
     }

+ 14 - 10
wsm-application/src/main/resources/application.properties

@@ -31,25 +31,29 @@ spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/reso
 spring.redis.database=0
 spring.redis.host=127.0.0.1
 spring.redis.port=6379
-# 连接超时时间 单位 ms(毫秒
+# 锟斤拷锟接筹拷时时锟斤拷 锟斤拷位 ms锟斤拷锟斤拷锟诫
 spring.redis.timeout=3000
-# 连接池中的最大空闲连接,默认值也是8。
+# 锟斤拷锟接筹拷锟叫碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟接o拷默锟斤拷值也锟斤拷8锟斤拷
 spring.redis.pool.max-idle=8
-#连接池中的最小空闲连接,默认值也是0。
+#锟斤拷锟接筹拷锟叫碉拷锟斤拷小锟斤拷锟斤拷锟斤拷锟接o拷默锟斤拷值也锟斤拷0锟斤拷
 spring.redis.pool.min-idle=0
-# 如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。
+# �����ֵΪ-1�����ʾ�����ƣ����pool�Ѿ�������maxActive��jedisʵ�������ʱpool��״̬Ϊexhausted(�ľ�)��
 spring.redis.pool.max-active=8
-# 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException
+# �ȴ��������ӵ����ʱ�䣬��λ���룬Ĭ��ֵΪ-1����ʾ������ʱ����������ȴ�ʱ�䣬��ֱ���׳�JedisConnectionException
 spring.redis.pool.max-wait=-1
-#redis哨兵设置
-#Redis服务器master的名字
+#redis锟节憋拷锟斤拷锟斤拷
+#Redis锟斤拷锟斤拷锟斤拷master锟斤拷锟斤拷锟斤拷
 #spring.redis.sentinel.master=master8026
-#redis-sentinel的配置地址和端口
+#redis-sentinel锟斤拷锟斤拷锟矫碉拷址锟酵端匡拷
 #spring.redis.sentinel.nodes=10.189.80.25:26379,10.189.80.26:26379,10.189.80.27:26378
 
 context.listener.classes=com.wsm.admin.init.StartupUdpEvent
-#线程池
+#锟竭程筹拷
 spring.task.pool.corePoolSize=5
 spring.task.pool.maxPoolSize=100
 spring.task.pool.keepAliveSeconds=100
-spring.task.pool.queueCapacity=100
+spring.task.pool.queueCapacity=100
+
+live.key=c1685ef2012c099ec3daa238907577ed
+live.number.url=http://95787.com/api/getSessionID.php
+live.info.url=http://95787.com/api/getSessionIDInfo.php