Commit 3c38cfca86c1b0e90aa5df21d2c3436f3aeebda5
Merge branch 'master' of http://bj.gitlab.cnlive.com/liujicheng/cnlive_live_web into v532
# Conflicts: # .settings/org.eclipse.wst.common.component # src/main/java/com/cnlive/mz/live/action/LiveAction.java
Showing
3 changed files
with
466 additions
and
382 deletions
.settings/org.eclipse.wst.common.component
| 1 | +<<<<<<< HEAD | ||
| 1 | <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> | 2 | <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> |
| 2 | <wb-module deploy-name="cnlive_live_web"> | 3 | <wb-module deploy-name="cnlive_live_web"> |
| 3 | <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> | 4 | <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> |
| @@ -33,3 +34,35 @@ | @@ -33,3 +34,35 @@ | ||
| 33 | <property name="context-root" value="cnlive_live_web"/> | 34 | <property name="context-root" value="cnlive_live_web"/> |
| 34 | </wb-module> | 35 | </wb-module> |
| 35 | </project-modules> | 36 | </project-modules> |
| 37 | +======= | ||
| 38 | +<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> | ||
| 39 | + <wb-module deploy-name="cnlive_live_web"> | ||
| 40 | + <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> | ||
| 41 | + <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> | ||
| 42 | + <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> | ||
| 43 | + <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/> | ||
| 44 | + <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> | ||
| 45 | + <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources/i18n"/> | ||
| 46 | + <dependent-module archiveName="cnlive_live_model-0.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/cnlive_live_model/cnlive_live_model"> | ||
| 47 | + <dependency-type>uses</dependency-type> | ||
| 48 | + </dependent-module> | ||
| 49 | + <dependent-module archiveName="smart-framework-4.0.1.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/smart-framework/smart-framework"> | ||
| 50 | + <dependency-type>uses</dependency-type> | ||
| 51 | + </dependent-module> | ||
| 52 | + <dependent-module archiveName="smart-plugin-dbcp-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/smart-plugin-dbcp/smart-plugin-dbcp"> | ||
| 53 | + <dependency-type>uses</dependency-type> | ||
| 54 | + </dependent-module> | ||
| 55 | + <dependent-module archiveName="smart-plugin-rest-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/smart-plugin-rest/smart-plugin-rest"> | ||
| 56 | + <dependency-type>uses</dependency-type> | ||
| 57 | + </dependent-module> | ||
| 58 | + <dependent-module archiveName="smart-plugin-i18n-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/smart-plugin-i18n/smart-plugin-i18n"> | ||
| 59 | + <dependency-type>uses</dependency-type> | ||
| 60 | + </dependent-module> | ||
| 61 | + <dependent-module archiveName="cnlive_mam_commons-0.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/cnlive_mam_commons/cnlive_mam_commons"> | ||
| 62 | + <dependency-type>uses</dependency-type> | ||
| 63 | + </dependent-module> | ||
| 64 | + <property name="java-output-path" value="/cnlive_live_web/target/classes"/> | ||
| 65 | + <property name="context-root" value="cnlive_live_web"/> | ||
| 66 | + </wb-module> | ||
| 67 | +</project-modules> | ||
| 68 | +>>>>>>> cb8011658d9ad15970225014e8ad4a30104d88d9 |
src/main/java/com/cnlive/mz/live/action/LiveAction.java
| @@ -45,6 +45,7 @@ import com.cnlive.mz.live.service.TCheckService; | @@ -45,6 +45,7 @@ import com.cnlive.mz.live.service.TCheckService; | ||
| 45 | import com.cnlive.mz.live.service.TLiveService; | 45 | import com.cnlive.mz.live.service.TLiveService; |
| 46 | import com.cnlive.mz.live.service.TRoomService; | 46 | import com.cnlive.mz.live.service.TRoomService; |
| 47 | 47 | ||
| 48 | + | ||
| 48 | /** | 49 | /** |
| 49 | * TODO: 机构主播和个人主播发起直播活动 <br/> | 50 | * TODO: 机构主播和个人主播发起直播活动 <br/> |
| 50 | * Date: 2016年4月25日 下午1:12:48 <br/> | 51 | * Date: 2016年4月25日 下午1:12:48 <br/> |
| @@ -203,13 +204,14 @@ public class LiveAction { | @@ -203,13 +204,14 @@ public class LiveAction { | ||
| 203 | boolean flag = tLiveService.addAcitvity(params); | 204 | boolean flag = tLiveService.addAcitvity(params); |
| 204 | if (flag) { | 205 | if (flag) { |
| 205 | Map<String, Object> map = new HashMap<String, Object>(); | 206 | Map<String, Object> map = new HashMap<String, Object>(); |
| 206 | - map.put("location", com.cnlive.mz.live.common.Constants.KS_HOST_UP_RTMP+channelID+"?vdoid=" + activityId); | 207 | + map.put("location", |
| 208 | + com.cnlive.mz.live.common.Constants.KS_HOST_UP_RTMP + channelID + "?vdoid=" + activityId); | ||
| 207 | rb.setData(map); | 209 | rb.setData(map); |
| 208 | rb.setErrorCode("0"); | 210 | rb.setErrorCode("0"); |
| 209 | rb.setErrorMessage("创建活动成功"); | 211 | rb.setErrorMessage("创建活动成功"); |
| 210 | log.info("创建活动成功"); | 212 | log.info("创建活动成功"); |
| 211 | - //通知cms直播 | ||
| 212 | - boolean success = tLiveService.startLive(tLive); | 213 | + // 通知cms直播 |
| 214 | + // boolean success = tLiveService.startLive(tLive); | ||
| 213 | return rb; | 215 | return rb; |
| 214 | } else { | 216 | } else { |
| 215 | Map<String, Object> map = new HashMap<String, Object>(); | 217 | Map<String, Object> map = new HashMap<String, Object>(); |
| @@ -242,23 +244,25 @@ public class LiveAction { | @@ -242,23 +244,25 @@ public class LiveAction { | ||
| 242 | @Request.Get("/live/epg/startActivity") | 244 | @Request.Get("/live/epg/startActivity") |
| 243 | public ResultBean startActivity(Params params) { | 245 | public ResultBean startActivity(Params params) { |
| 244 | ResultBean rb = new ResultBean(); | 246 | ResultBean rb = new ResultBean(); |
| 247 | + log.info(params); | ||
| 245 | String appId = params.getString("appId"); | 248 | String appId = params.getString("appId"); |
| 246 | String activityid = params.getString("activityId"); | 249 | String activityid = params.getString("activityId"); |
| 247 | if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(activityid)) { | 250 | if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(activityid)) { |
| 248 | - Map<String, Object> map = new HashMap<String, Object>(); | ||
| 249 | - map.put("location", ""); | ||
| 250 | - rb.setData(map); | ||
| 251 | rb.setErrorCode("500"); | 251 | rb.setErrorCode("500"); |
| 252 | - rb.setErrorMessage("启动活动失败"); | 252 | + rb.setErrorMessage("启动活动失败,参数不正确"); |
| 253 | return rb; | 253 | return rb; |
| 254 | } else { | 254 | } else { |
| 255 | TLive tLive = tLiveService.selectByParams(appId, activityid); | 255 | TLive tLive = tLiveService.selectByParams(appId, activityid); |
| 256 | - Map<String, Object> map = new HashMap<String, Object>(); | ||
| 257 | - map.put("location", tLive.getLive_url()); | ||
| 258 | - rb.setData(map); | ||
| 259 | - rb.setErrorCode("0"); | ||
| 260 | - rb.setErrorMessage("启动活动成功"); | ||
| 261 | - return rb; | 256 | + if (tLive == null) { |
| 257 | + log.info("tLive为空......"); | ||
| 258 | + rb.setErrorCode("500"); | ||
| 259 | + rb.setErrorMessage("启动活动失败,活动对象为空"); | ||
| 260 | + return rb; | ||
| 261 | + } else { | ||
| 262 | + rb.setErrorCode("0"); | ||
| 263 | + rb.setErrorMessage("启动活动成功"); | ||
| 264 | + return rb; | ||
| 265 | + } | ||
| 262 | } | 266 | } |
| 263 | } | 267 | } |
| 264 | 268 | ||
| @@ -270,38 +274,42 @@ public class LiveAction { | @@ -270,38 +274,42 @@ public class LiveAction { | ||
| 270 | */ | 274 | */ |
| 271 | @Request.Get("/live/epg/stopActivity") | 275 | @Request.Get("/live/epg/stopActivity") |
| 272 | public ResultBean stopActivity(Params params) { | 276 | public ResultBean stopActivity(Params params) { |
| 277 | + log.info(params); | ||
| 273 | ResultBean rb = new ResultBean(); | 278 | ResultBean rb = new ResultBean(); |
| 274 | String appId = params.getString("appId"); | 279 | String appId = params.getString("appId"); |
| 275 | String activityid = params.getString("activityId"); | 280 | String activityid = params.getString("activityId"); |
| 276 | TLive tLive = tLiveService.selectByParams(appId, activityid); | 281 | TLive tLive = tLiveService.selectByParams(appId, activityid); |
| 282 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
| 277 | if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(activityid)) { | 283 | if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(activityid)) { |
| 278 | - Map<String, Object> map = new HashMap<String, Object>(); | ||
| 279 | map.put("location", ""); | 284 | map.put("location", ""); |
| 280 | rb.setData(map); | 285 | rb.setData(map); |
| 281 | rb.setErrorCode("500"); | 286 | rb.setErrorCode("500"); |
| 282 | rb.setErrorMessage("停止直播失败,参数不正确"); | 287 | rb.setErrorMessage("停止直播失败,参数不正确"); |
| 283 | return rb; | 288 | return rb; |
| 284 | } else { | 289 | } else { |
| 285 | - | ||
| 286 | - String live_url = tLive.getLive_url(); | ||
| 287 | - int index = live_url.lastIndexOf("/"); | ||
| 288 | - String streamName = live_url.substring(index + 1); | ||
| 289 | - System.out.println("streamName===" + streamName); | 290 | + if (tLive == null) { |
| 291 | + map.put("location", ""); | ||
| 292 | + rb.setData(map); | ||
| 293 | + rb.setErrorCode("500"); | ||
| 294 | + rb.setErrorMessage("停止直播失败,活动对象为空"); | ||
| 295 | + return rb; | ||
| 296 | + } else { | ||
| 297 | + String live_url = tLive.getLive_url(); | ||
| 298 | + int index = live_url.lastIndexOf("/"); | ||
| 299 | + String streamName = live_url.substring(index + 1); | ||
| 300 | + System.out.println("streamName===" + streamName); | ||
| 290 | // 直播断流。 | 301 | // 直播断流。 |
| 291 | - tCheckService.close(streamName, tLive.getId(), tLive.getUuid()); | ||
| 292 | - //通知cms停止直播 | ||
| 293 | - tLiveService.releaseChatRoom(tLive); | 302 | + tCheckService.close(streamName, tLive.getId(), tLive.getUuid()); |
| 294 | } | 303 | } |
| 295 | // 直播通知 | 304 | // 直播通知 |
| 296 | // tLiveService.notify(video_uuid, -1); | 305 | // tLiveService.notify(video_uuid, -1); |
| 297 | - Map<String, Object> map = new HashMap<String, Object>(); | ||
| 298 | map.put("location", tLive.getLive_url()); | 306 | map.put("location", tLive.getLive_url()); |
| 299 | rb.setData(map); | 307 | rb.setData(map); |
| 300 | rb.setErrorCode("0"); | 308 | rb.setErrorCode("0"); |
| 301 | rb.setErrorMessage("停止直播成功"); | 309 | rb.setErrorMessage("停止直播成功"); |
| 302 | return rb; | 310 | return rb; |
| 303 | } | 311 | } |
| 304 | - | 312 | + } |
| 305 | 313 | ||
| 306 | /** | 314 | /** |
| 307 | * 1.6 获取直播活动列表接口.md | 315 | * 1.6 获取直播活动列表接口.md |
| @@ -320,14 +328,21 @@ public class LiveAction { | @@ -320,14 +328,21 @@ public class LiveAction { | ||
| 320 | map.put("location", ""); | 328 | map.put("location", ""); |
| 321 | rb.setData(map); | 329 | rb.setData(map); |
| 322 | rb.setErrorCode("500"); | 330 | rb.setErrorCode("500"); |
| 323 | - rb.setErrorMessage("获取活动列表失败,字段不正确"); | 331 | + rb.setErrorMessage("获取活动列表失败,参数不正确"); |
| 324 | return rb; | 332 | return rb; |
| 325 | } else { | 333 | } else { |
| 326 | Pager<TLive> tLive = tLiveService.getActivityPager(pageNo, pageSize, appId); | 334 | Pager<TLive> tLive = tLiveService.getActivityPager(pageNo, pageSize, appId); |
| 327 | - rb.setData(tLive); | ||
| 328 | - rb.setErrorCode("0"); | ||
| 329 | - rb.setErrorMessage("获取活动列表成功"); | ||
| 330 | - return rb; | 335 | + if (tLive == null) { |
| 336 | + rb.setData(""); | ||
| 337 | + rb.setErrorCode("500"); | ||
| 338 | + rb.setErrorMessage("获取活动列表失败,活动对象为空"); | ||
| 339 | + return rb; | ||
| 340 | + } else { | ||
| 341 | + rb.setData(tLive); | ||
| 342 | + rb.setErrorCode("0"); | ||
| 343 | + rb.setErrorMessage("获取活动列表成功"); | ||
| 344 | + return rb; | ||
| 345 | + } | ||
| 331 | 346 | ||
| 332 | } | 347 | } |
| 333 | } | 348 | } |
| @@ -342,21 +357,28 @@ public class LiveAction { | @@ -342,21 +357,28 @@ public class LiveAction { | ||
| 342 | ResultBean rb = new ResultBean(); | 357 | ResultBean rb = new ResultBean(); |
| 343 | String appId = params.getString("appId"); | 358 | String appId = params.getString("appId"); |
| 344 | String activityid = params.getString("activityId"); | 359 | String activityid = params.getString("activityId"); |
| 360 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
| 345 | if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(activityid)) { | 361 | if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(activityid)) { |
| 346 | - Map<String, Object> map = new HashMap<String, Object>(); | ||
| 347 | map.put("location", ""); | 362 | map.put("location", ""); |
| 348 | rb.setData(map); | 363 | rb.setData(map); |
| 349 | rb.setErrorCode("500"); | 364 | rb.setErrorCode("500"); |
| 350 | - rb.setErrorMessage("获取直播回放失败"); | 365 | + rb.setErrorMessage("获取直播回放失败,参数不正确"); |
| 351 | return rb; | 366 | return rb; |
| 352 | } else { | 367 | } else { |
| 353 | TLive tLive = tLiveService.selectByParams(appId, activityid); | 368 | TLive tLive = tLiveService.selectByParams(appId, activityid); |
| 354 | - Map<String, Object> map = new HashMap<String, Object>(); | ||
| 355 | - map.put("location", tLive.getPlayback_url()); | ||
| 356 | - rb.setData(map); | ||
| 357 | - rb.setErrorCode("0"); | ||
| 358 | - rb.setErrorMessage("获取直播回放成功"); | ||
| 359 | - return rb; | 369 | + if (tLive == null) { |
| 370 | + map.put("location", ""); | ||
| 371 | + rb.setData(map); | ||
| 372 | + rb.setErrorCode("500"); | ||
| 373 | + rb.setErrorMessage("获取直播回放失败,活动对象为空"); | ||
| 374 | + return rb; | ||
| 375 | + } else { | ||
| 376 | + map.put("location", tLive.getPlayback_url()); | ||
| 377 | + rb.setData(map); | ||
| 378 | + rb.setErrorCode("0"); | ||
| 379 | + rb.setErrorMessage("获取直播回放成功"); | ||
| 380 | + return rb; | ||
| 381 | + } | ||
| 360 | } | 382 | } |
| 361 | } | 383 | } |
| 362 | 384 | ||
| @@ -367,27 +389,35 @@ public class LiveAction { | @@ -367,27 +389,35 @@ public class LiveAction { | ||
| 367 | */ | 389 | */ |
| 368 | @Request.Get("/live/epg/liveplayByAPP") | 390 | @Request.Get("/live/epg/liveplayByAPP") |
| 369 | public ResultBean liveplayByAPP(Params params) { | 391 | public ResultBean liveplayByAPP(Params params) { |
| 392 | + log.info(params); | ||
| 370 | ResultBean rb = new ResultBean(); | 393 | ResultBean rb = new ResultBean(); |
| 371 | String appId = params.getString("appId"); | 394 | String appId = params.getString("appId"); |
| 372 | String activityid = params.getString("activityId"); | 395 | String activityid = params.getString("activityId"); |
| 396 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
| 373 | if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(activityid)) { | 397 | if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(activityid)) { |
| 374 | - Map<String, Object> map = new HashMap<String, Object>(); | ||
| 375 | map.put("location", ""); | 398 | map.put("location", ""); |
| 376 | rb.setData(map); | 399 | rb.setData(map); |
| 377 | rb.setErrorCode("500"); | 400 | rb.setErrorCode("500"); |
| 378 | - rb.setErrorMessage("获取直播回放失败"); | 401 | + rb.setErrorMessage("获取直播回放失败,参数不正确"); |
| 379 | return rb; | 402 | return rb; |
| 380 | } else { | 403 | } else { |
| 381 | TLive tLive = tLiveService.selectByParams(appId, activityid); | 404 | TLive tLive = tLiveService.selectByParams(appId, activityid); |
| 382 | - Map<String, Object> map = new HashMap<String, Object>(); | ||
| 383 | - map.put("location", tLive.getPlayback_url()); | ||
| 384 | - rb.setData(map); | ||
| 385 | - rb.setErrorCode("0"); | ||
| 386 | - rb.setErrorMessage("获取直播回放成功"); | ||
| 387 | - return rb; | 405 | + if (tLive == null) { |
| 406 | + map.put("location", ""); | ||
| 407 | + rb.setData(map); | ||
| 408 | + rb.setErrorCode("500"); | ||
| 409 | + rb.setErrorMessage("获取直播回放失败,活动对象为空"); | ||
| 410 | + return rb; | ||
| 411 | + } else { | ||
| 412 | + map.put("location", tLive.getPlayback_url()); | ||
| 413 | + rb.setData(map); | ||
| 414 | + rb.setErrorCode("0"); | ||
| 415 | + rb.setErrorMessage("获取直播回放成功"); | ||
| 416 | + return rb; | ||
| 417 | + } | ||
| 388 | } | 418 | } |
| 389 | } | 419 | } |
| 390 | - | 420 | + |
| 391 | /** | 421 | /** |
| 392 | * 1.8 获取APP直播URL接口.md | 422 | * 1.8 获取APP直播URL接口.md |
| 393 | * | 423 | * |
| @@ -409,26 +439,35 @@ public class LiveAction { | @@ -409,26 +439,35 @@ public class LiveAction { | ||
| 409 | return rb; | 439 | return rb; |
| 410 | } else { | 440 | } else { |
| 411 | TLive tLive = tLiveService.selectByParams(appId, activityid); | 441 | TLive tLive = tLiveService.selectByParams(appId, activityid); |
| 412 | - TChannel tchannel = tLiveService.selectChannel(tLive.getRelation_id()); | ||
| 413 | - if(tchannel!=null){ | ||
| 414 | - // 请求到app....... | ||
| 415 | - redirect(response, "http://ips.cnlive.com/IPS/liveplayByAPP.action?appId="+appId+"&channelID="+tLive.getRelation_id()); | 442 | + if (tLive == null) { |
| 416 | map.put("location", ""); | 443 | map.put("location", ""); |
| 417 | rb.setData(map); | 444 | rb.setData(map); |
| 418 | - rb.setErrorCode("0"); | ||
| 419 | - rb.setErrorMessage("302重定向到app"); | ||
| 420 | - return rb; | ||
| 421 | - }else{ | ||
| 422 | - map.put("location", tLive.getLive_url()); | ||
| 423 | - rb.setData(map); | ||
| 424 | - rb.setErrorCode("0"); | ||
| 425 | - rb.setErrorMessage("启动app活动成功"); | 445 | + rb.setErrorCode("500"); |
| 446 | + rb.setErrorMessage("启动app活动失败,活动对象为空"); | ||
| 426 | return rb; | 447 | return rb; |
| 448 | + } else { | ||
| 449 | + TChannel tchannel = tLiveService.selectChannel(tLive.getRelation_id()); | ||
| 450 | + if (tchannel != null) { | ||
| 451 | + // 请求到app....... | ||
| 452 | + redirect(response, "http://ips.cnlive.com/IPS/liveplayByAPP.action?appId=" + appId + "&channelID=" | ||
| 453 | + + tLive.getRelation_id()); | ||
| 454 | + map.put("location", ""); | ||
| 455 | + rb.setData(map); | ||
| 456 | + rb.setErrorCode("0"); | ||
| 457 | + rb.setErrorMessage("302重定向到app"); | ||
| 458 | + return rb; | ||
| 459 | + } else { | ||
| 460 | + map.put("location", tLive.getLive_url()); | ||
| 461 | + rb.setData(map); | ||
| 462 | + rb.setErrorCode("0"); | ||
| 463 | + rb.setErrorMessage("启动app活动成功"); | ||
| 464 | + return rb; | ||
| 465 | + } | ||
| 427 | } | 466 | } |
| 428 | } | 467 | } |
| 429 | - | 468 | + |
| 430 | } | 469 | } |
| 431 | - | 470 | + |
| 432 | /** | 471 | /** |
| 433 | * 1.9 获取H5直播URL接口.md | 472 | * 1.9 获取H5直播URL接口.md |
| 434 | * | 473 | * |
| @@ -450,26 +489,35 @@ public class LiveAction { | @@ -450,26 +489,35 @@ public class LiveAction { | ||
| 450 | return rb; | 489 | return rb; |
| 451 | } else { | 490 | } else { |
| 452 | TLive tLive = tLiveService.selectByParams(appId, activityid); | 491 | TLive tLive = tLiveService.selectByParams(appId, activityid); |
| 453 | - TChannel tchannel = tLiveService.selectChannel(tLive.getRelation_id()); | ||
| 454 | - if(tchannel!=null){ | ||
| 455 | - // 重定向到h5....... | ||
| 456 | - redirect(response, "http://ips.cnlive.com/IPS/liveplayByH5?appId="+appId+"&channelID="+tLive.getRelation_id()); | 492 | + if (tLive == null) { |
| 457 | map.put("location", ""); | 493 | map.put("location", ""); |
| 458 | rb.setData(map); | 494 | rb.setData(map); |
| 459 | - rb.setErrorCode("0"); | ||
| 460 | - rb.setErrorMessage("302重定向到h5"); | ||
| 461 | - return rb; | ||
| 462 | - }else{ | ||
| 463 | - map.put("location", tLive.getLive_url()); | ||
| 464 | - rb.setData(map); | ||
| 465 | - rb.setErrorCode("0"); | ||
| 466 | - rb.setErrorMessage("启动h5活动成功"); | 495 | + rb.setErrorCode("500"); |
| 496 | + rb.setErrorMessage("启动h5活动失败,活动对象为空"); | ||
| 467 | return rb; | 497 | return rb; |
| 498 | + } else { | ||
| 499 | + TChannel tchannel = tLiveService.selectChannel(tLive.getRelation_id()); | ||
| 500 | + if (tchannel != null) { | ||
| 501 | + // 重定向到h5....... | ||
| 502 | + redirect(response, "http://ips.cnlive.com/IPS/liveplayByH5?appId=" + appId + "&channelID=" | ||
| 503 | + + tLive.getRelation_id()); | ||
| 504 | + map.put("location", ""); | ||
| 505 | + rb.setData(map); | ||
| 506 | + rb.setErrorCode("0"); | ||
| 507 | + rb.setErrorMessage("302重定向到h5"); | ||
| 508 | + return rb; | ||
| 509 | + } else { | ||
| 510 | + map.put("location", tLive.getLive_url()); | ||
| 511 | + rb.setData(map); | ||
| 512 | + rb.setErrorCode("0"); | ||
| 513 | + rb.setErrorMessage("启动h5活动成功"); | ||
| 514 | + return rb; | ||
| 515 | + } | ||
| 468 | } | 516 | } |
| 469 | } | 517 | } |
| 470 | - | 518 | + |
| 471 | } | 519 | } |
| 472 | - | 520 | + |
| 473 | /** | 521 | /** |
| 474 | * 2.0 获取SWF直播URL接口.md | 522 | * 2.0 获取SWF直播URL接口.md |
| 475 | * | 523 | * |
| @@ -491,22 +539,34 @@ public class LiveAction { | @@ -491,22 +539,34 @@ public class LiveAction { | ||
| 491 | return rb; | 539 | return rb; |
| 492 | } else { | 540 | } else { |
| 493 | TLive tLive = tLiveService.selectByParams(appId, activityid); | 541 | TLive tLive = tLiveService.selectByParams(appId, activityid); |
| 494 | - TChannel tchannel = tLiveService.selectChannel(tLive.getRelation_id()); | ||
| 495 | - rb.setData(map); | ||
| 496 | - rb.setErrorCode("0"); | ||
| 497 | - if(tchannel!=null){ | ||
| 498 | - // 302重定向到swf....... | ||
| 499 | - redirect(response, "http://ips.cnlive.com/IPS/liveplayBySWF.action?appId="+appId+"&channelID="+tLive.getRelation_id()); | 542 | + if (tLive == null) { |
| 500 | map.put("location", ""); | 543 | map.put("location", ""); |
| 501 | - rb.setErrorMessage("302重定向到swf"); | ||
| 502 | - return rb; | ||
| 503 | - }else{ | ||
| 504 | - map.put("location", tLive.getLive_url()); | ||
| 505 | - rb.setErrorMessage("启动swf活动成功"); | 544 | + rb.setData(map); |
| 545 | + rb.setErrorCode("500"); | ||
| 546 | + rb.setErrorMessage("启动swf活动失败,活动对象为空"); | ||
| 506 | return rb; | 547 | return rb; |
| 548 | + } else { | ||
| 549 | + TChannel tchannel = tLiveService.selectChannel(tLive.getRelation_id()); | ||
| 550 | + rb.setData(map); | ||
| 551 | + rb.setErrorCode("0"); | ||
| 552 | + if (tchannel != null) { | ||
| 553 | + // 302重定向到swf....... | ||
| 554 | + redirect(response, "http://ips.cnlive.com/IPS/liveplayBySWF.action?appId=" + appId + "&channelID=" | ||
| 555 | + + tLive.getRelation_id()); | ||
| 556 | + map.put("location", ""); | ||
| 557 | + rb.setErrorMessage("302重定向到swf"); | ||
| 558 | + return rb; | ||
| 559 | + } else { | ||
| 560 | + | ||
| 561 | + map.put("location", tLive.getLive_url()); | ||
| 562 | + rb.setErrorMessage("启动swf活动成功"); | ||
| 563 | + return rb; | ||
| 564 | + } | ||
| 507 | } | 565 | } |
| 508 | } | 566 | } |
| 567 | + | ||
| 509 | } | 568 | } |
| 569 | + | ||
| 510 | /** | 570 | /** |
| 511 | * 2.1 获取推流直播播放地址.md | 571 | * 2.1 获取推流直播播放地址.md |
| 512 | * | 572 | * |
| @@ -527,14 +587,15 @@ public class LiveAction { | @@ -527,14 +587,15 @@ public class LiveAction { | ||
| 527 | return rb; | 587 | return rb; |
| 528 | } else { | 588 | } else { |
| 529 | TLive tLive = tLiveService.selectByParams(appId, activityid); | 589 | TLive tLive = tLiveService.selectByParams(appId, activityid); |
| 530 | - Map<String, Object> map = new HashMap<String, Object>(); | ||
| 531 | - map.put("location", tLive.getLive_url()); | ||
| 532 | - rb.setData(map); | ||
| 533 | - rb.setErrorCode("0"); | ||
| 534 | - rb.setErrorMessage("启动活动成功"); | ||
| 535 | - return rb; | ||
| 536 | - } | 590 | + Map<String, Object> map = new HashMap<String, Object>(); |
| 591 | + map.put("location", tLive.getLive_url()); | ||
| 592 | + rb.setData(map); | ||
| 593 | + rb.setErrorCode("0"); | ||
| 594 | + rb.setErrorMessage("启动活动成功"); | ||
| 595 | + return rb; | ||
| 537 | } | 596 | } |
| 597 | + } | ||
| 598 | + | ||
| 538 | @Request.Post("/live/epg/error500") | 599 | @Request.Post("/live/epg/error500") |
| 539 | public ResultBean error(Params params) { | 600 | public ResultBean error(Params params) { |
| 540 | ResultBean rb = new ResultBean(); | 601 | ResultBean rb = new ResultBean(); |
| @@ -545,57 +606,47 @@ public class LiveAction { | @@ -545,57 +606,47 @@ public class LiveAction { | ||
| 545 | rb.setErrorMessage("失败"); | 606 | rb.setErrorMessage("失败"); |
| 546 | return rb; | 607 | return rb; |
| 547 | } | 608 | } |
| 548 | - | 609 | + |
| 549 | public static void redirect(HttpServletResponse response, String redirectUrl) { | 610 | public static void redirect(HttpServletResponse response, String redirectUrl) { |
| 550 | - try { | ||
| 551 | - response.setContentType("application/mpegurl"); | ||
| 552 | - response.setStatus(302); | ||
| 553 | - response.setHeader("Location", redirectUrl); | ||
| 554 | - response.setHeader("Connection", "close"); | ||
| 555 | - } catch (Exception e) { | ||
| 556 | - throw new RuntimeException(e); | ||
| 557 | - } | ||
| 558 | - } | 611 | + try { |
| 612 | + response.setContentType("application/mpegurl"); | ||
| 613 | + response.setStatus(302); | ||
| 614 | + response.setHeader("Location", redirectUrl); | ||
| 615 | + response.setHeader("Connection", "close"); | ||
| 616 | + } catch (Exception e) { | ||
| 617 | + throw new RuntimeException(e); | ||
| 618 | + } | ||
| 619 | + } | ||
| 620 | + | ||
| 559 | @Request.Get("/live/epg/302") | 621 | @Request.Get("/live/epg/302") |
| 560 | public void red302() { | 622 | public void red302() { |
| 561 | - HttpServletResponse response =DataContext.getResponse(); | 623 | + HttpServletResponse response = DataContext.getResponse(); |
| 562 | redirect(response, "http://ips.cnlive.com/IPS/liveplayBySWF.action?activityId=12345"); | 624 | redirect(response, "http://ips.cnlive.com/IPS/liveplayBySWF.action?activityId=12345"); |
| 563 | } | 625 | } |
| 564 | 626 | ||
| 565 | public static void main(String[] args) { | 627 | public static void main(String[] args) { |
| 566 | - | ||
| 567 | - /*NameValuePair[] nvp = new NameValuePair[6]; | ||
| 568 | - NameValuePair nv1 = new NameValuePair(); | ||
| 569 | - nv1.setName("appId"); | ||
| 570 | - nv1.setValue("123"); | ||
| 571 | - nvp[0] = nv1; | ||
| 572 | - NameValuePair nv2 = new NameValuePair(); | ||
| 573 | - nv2.setName("activityId"); | ||
| 574 | - nv2.setValue("234e"); | ||
| 575 | - nvp[1] = nv2; | ||
| 576 | - NameValuePair nv3 = new NameValuePair(); | ||
| 577 | - nv3.setName("activityName"); | ||
| 578 | - nv3.setValue("ee"); | ||
| 579 | - nvp[2] = nv3; | ||
| 580 | - NameValuePair nv4 = new NameValuePair(); | ||
| 581 | - nv4.setName("activityStatus"); | ||
| 582 | - nv4.setValue("11"); | ||
| 583 | - nvp[3] = nv4; | ||
| 584 | - NameValuePair nv5 = new NameValuePair(); | ||
| 585 | - nv5.setName("isHorizontalScreen"); | ||
| 586 | - nv5.setValue("321"); | ||
| 587 | - nvp[4] = nv5; | ||
| 588 | - NameValuePair nv6 = new NameValuePair(); | ||
| 589 | - nv6.setName("channelId"); | ||
| 590 | - nv6.setValue("ww"); | ||
| 591 | - nvp[5] = nv6; | ||
| 592 | - String ss = HttpReq.postRequestWidthResult("http://bc.cnlive.com/live/epg/createActivity", nvp); | ||
| 593 | - System.out.println(ss); | ||
| 594 | -<<<<<<< HEAD | 628 | + |
| 629 | + /* | ||
| 630 | + * NameValuePair[] nvp = new NameValuePair[6]; NameValuePair nv1 = new | ||
| 631 | + * NameValuePair(); nv1.setName("appId"); nv1.setValue("123"); nvp[0] = | ||
| 632 | + * nv1; NameValuePair nv2 = new NameValuePair(); | ||
| 633 | + * nv2.setName("activityId"); nv2.setValue("234e"); nvp[1] = nv2; | ||
| 634 | + * NameValuePair nv3 = new NameValuePair(); nv3.setName("activityName"); | ||
| 635 | + * nv3.setValue("ee"); nvp[2] = nv3; NameValuePair nv4 = new | ||
| 636 | + * NameValuePair(); nv4.setName("activityStatus"); nv4.setValue("11"); | ||
| 637 | + * nvp[3] = nv4; NameValuePair nv5 = new NameValuePair(); | ||
| 638 | + * nv5.setName("isHorizontalScreen"); nv5.setValue("321"); nvp[4] = nv5; | ||
| 639 | + * NameValuePair nv6 = new NameValuePair(); nv6.setName("channelId"); | ||
| 640 | + * nv6.setValue("ww"); nvp[5] = nv6; String ss = | ||
| 641 | + * HttpReq.postRequestWidthResult( | ||
| 642 | + * "http://bc.cnlive.com/live/epg/createActivity", nvp); | ||
| 643 | + * System.out.println(ss); <<<<<<< HEAD String aa = HttpReq | ||
| 644 | + * .getRequestWidthResult( | ||
| 645 | + * "http://bc.cnlive.com/live/epg/startActivity?appId=123&activityId=234" | ||
| 646 | + * ); System.out.println(aa); | ||
| 647 | + */ | ||
| 595 | String aa = HttpReq | 648 | String aa = HttpReq |
| 596 | .getRequestWidthResult("http://bc.cnlive.com/live/epg/startActivity?appId=123&activityId=234"); | 649 | .getRequestWidthResult("http://bc.cnlive.com/live/epg/startActivity?appId=123&activityId=234"); |
| 597 | - System.out.println(aa);*/ | ||
| 598 | - String aa = HttpReq.getRequestWidthResult("http://bc.cnlive.com/live/epg/startActivity?appId=123&activityId=234"); | ||
| 599 | System.out.println(aa); | 650 | System.out.println(aa); |
| 600 | } | 651 | } |
| 601 | } | 652 | } |
| 602 | \ No newline at end of file | 653 | \ No newline at end of file |
src/main/java/com/cnlive/mz/live/action/VideoAction.java
| 1 | -package com.cnlive.mz.live.action; | ||
| 2 | - | ||
| 3 | -import java.util.Date; | ||
| 4 | -import java.util.LinkedHashMap; | ||
| 5 | -import java.util.Map; | ||
| 6 | - | ||
| 7 | -import org.apache.commons.lang3.StringUtils; | ||
| 8 | -import org.apache.log4j.Logger; | ||
| 9 | -import org.smart4j.framework.dao.bean.Pager; | ||
| 10 | -import org.smart4j.framework.ioc.annotation.Inject; | ||
| 11 | -import org.smart4j.framework.mvc.DataContext; | ||
| 12 | -import org.smart4j.framework.mvc.annotation.Action; | ||
| 13 | -import org.smart4j.framework.mvc.annotation.Request; | ||
| 14 | -import org.smart4j.framework.mvc.bean.ApiBean; | ||
| 15 | -import org.smart4j.framework.mvc.bean.Params; | ||
| 16 | -import org.smart4j.framework.mvc.bean.Result; | ||
| 17 | -import org.smart4j.framework.mvc.bean.View; | ||
| 18 | -import org.smart4j.framework.util.CastUtil; | ||
| 19 | - | ||
| 20 | -import com.cnlive.mz.commons.CnliveUtil; | ||
| 21 | -import com.cnlive.mz.commons.sensitive.FilteredResult; | ||
| 22 | -import com.cnlive.mz.commons.sensitive.WordFilterUtil; | ||
| 23 | -import com.cnlive.mz.live.common.Constants; | ||
| 24 | -import com.cnlive.mz.live.common.LiveUtils; | ||
| 25 | -import com.cnlive.mz.live.entity.TLive; | ||
| 26 | -import com.cnlive.mz.live.entity.TVideo; | ||
| 27 | -import com.cnlive.mz.live.service.TDispatchServerService; | ||
| 28 | -import com.cnlive.mz.live.service.TLiveService; | ||
| 29 | -import com.cnlive.mz.live.service.TUserService; | ||
| 30 | -import com.cnlive.mz.live.service.TVideoService; | ||
| 31 | - | ||
| 32 | -@Action | ||
| 33 | -public class VideoAction { | ||
| 34 | - | ||
| 35 | - private Logger log = Logger.getLogger("action"); | ||
| 36 | - @Inject | ||
| 37 | - private TDispatchServerService tDispatchServerService; | ||
| 38 | - @Inject | ||
| 39 | - private TVideoService tVideoService; | ||
| 40 | - @Inject | ||
| 41 | - private TUserService tUserService; | ||
| 42 | - @Inject | ||
| 43 | - private TLiveService tLiveService; | ||
| 44 | - | ||
| 45 | - /** | ||
| 46 | - * 服务器定向 | ||
| 47 | - * | ||
| 48 | - * @param params | ||
| 49 | - * @return | ||
| 50 | - * {"mediaComment":"","nickName":"阳Sir","appId":"1","mediaName":"","userId" | ||
| 51 | - * :"1167015","uuid": | ||
| 52 | - * "1167015_1463725085798_6a551f9122494a05ac8566b7a2ae1092"} | ||
| 53 | - */ | ||
| 54 | - @Request.Post("/api/video/redirect") | ||
| 55 | - public ApiBean redirect(Params params) { | ||
| 56 | - String app_access_key = params.getString("app_access_key"); | ||
| 57 | - String video_type = params.getString("video_type"); | ||
| 58 | - String user_id = params.getString("relation_id"); | ||
| 59 | - ApiBean apiBean = tDispatchServerService.redirect(video_type, app_access_key, user_id); | ||
| 60 | - return apiBean; | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - @Request.Post("/api/video/supload") | ||
| 64 | - public ApiBean supload(Params params) { | ||
| 65 | - Map data = new LinkedHashMap(); | ||
| 66 | - String app_access_key = params.getString("app_access_key"); | ||
| 67 | - String video_type = params.getString("video_type"); | ||
| 68 | - String user_access_key = params.getString("user_access_key"); | ||
| 69 | - String server_access_key = params.getString("server_access_key"); | ||
| 70 | - String active_id = params.getString("active_id"); | ||
| 71 | - String title = params.getString("title"); | ||
| 72 | - if (title.length() > 50) { | ||
| 73 | - title = title.substring(0, 50); | ||
| 74 | - } | ||
| 75 | - String description = params.getString("description"); | ||
| 76 | - WordFilterUtil wf = new WordFilterUtil(); | ||
| 77 | - FilteredResult resTitle = wf.filterHtml(title, '*'); | ||
| 78 | - title = resTitle.getFilteredContent().toString(); | ||
| 79 | - FilteredResult resDescr = wf.filterHtml(description, '*'); | ||
| 80 | - description = resDescr.getFilteredContent().toString(); | ||
| 81 | - | ||
| 82 | - String direct = params.getString("direct"); | ||
| 83 | - String custom_args = params.getString("custom_args"); | ||
| 84 | - String md5 = params.getString("md5"); | ||
| 85 | - String relation_id = params.getString("relation_id"); | ||
| 86 | - String uuid = ""; | ||
| 87 | - boolean success = true; | ||
| 88 | - if (video_type.equals("2")) { | ||
| 89 | - // 2:sdk上传录播文件 | ||
| 90 | - TVideo tVideo = new TVideo(); | ||
| 91 | - tVideo.setCustom_args(custom_args); | ||
| 92 | - tVideo.setRelation_id(relation_id); | ||
| 93 | - tVideo.setName(params.getString("name")); | ||
| 94 | - tVideo.setVideo_type(params.getString("video_type")); | ||
| 95 | - tVideo.setPlat(params.getString("plat")); | ||
| 96 | - tVideo.setState(207); | ||
| 97 | - tVideo.setMd5(md5); | ||
| 98 | - uuid = CnliveUtil.getUUID(); | ||
| 99 | - tVideo.setVideo_uuid(uuid); | ||
| 100 | - tVideo.setTitle(title); | ||
| 101 | - tVideo.setDescription(description); | ||
| 102 | - tVideoService.saveSdkVideo(tVideo, server_access_key, user_access_key, app_access_key); | ||
| 103 | - } else if (video_type.equals("3")) { | ||
| 104 | - TLive tLive = tLiveService.getTLiveByUUId(active_id); | ||
| 105 | - tLive.setT_status_id(1); | ||
| 106 | - tLive.setTitle(title); | ||
| 107 | - tLive.setDescription(description); | ||
| 108 | - tLive.setStart_time(new Date()); | ||
| 109 | - tLive.setUser_uuid(params.getString("name")); | ||
| 110 | - tLive.setRelation_id(relation_id); | ||
| 111 | - tLive.setCustom_args(custom_args); | ||
| 112 | - uuid = tLive.getUuid(); | ||
| 113 | - if (StringUtils.isEmpty(direct)) { | ||
| 114 | - tLive.setDirect(0); | ||
| 115 | - } else { | ||
| 116 | - tLive.setDirect(Integer.parseInt(direct)); | ||
| 117 | - } | ||
| 118 | - tLive.setLive_url(Constants.KS_HOST_RTMP + tLive.getT_user_id() + "_" + uuid); | ||
| 119 | - success = tLiveService.startLive(tLive); | ||
| 120 | - } | ||
| 121 | - data.put("video_uuid", uuid); | ||
| 122 | - ApiBean apiBean = new ApiBean(); | ||
| 123 | - if (success) { | ||
| 124 | - apiBean.setCode(100); | ||
| 125 | - apiBean.setMessage("请求成功"); | ||
| 126 | - } else { | ||
| 127 | - apiBean.setCode(201); | ||
| 128 | - apiBean.setMessage("发起直播失败"); | ||
| 129 | - } | ||
| 130 | - apiBean.setData(data); | ||
| 131 | - return apiBean; | ||
| 132 | - } | ||
| 133 | - | ||
| 134 | - @Request.Post("/api/video/all") | ||
| 135 | - public ApiBean all(Params params) { | ||
| 136 | - String app_access_key = params.getString("app_access_key"); | ||
| 137 | - String relationId = params.getString("relation_id"); | ||
| 138 | - String pageNo = params.getString("page_no"); | ||
| 139 | - String relation_id = params.getString("relation_id"); | ||
| 140 | - String upload_type = params.getString("upload_type"); | ||
| 141 | - // String video_type = params.getString("video_type"); | ||
| 142 | - Pager<TVideo> page = tVideoService.findAll(app_access_key, relationId, pageNo); | ||
| 143 | - ApiBean apiBean = new ApiBean(); | ||
| 144 | - apiBean.setCode(100); | ||
| 145 | - apiBean.setMessage("请求成功"); | ||
| 146 | - apiBean.setData(page); | ||
| 147 | - return apiBean; | ||
| 148 | - } | ||
| 149 | - | ||
| 150 | - @Request.Get("/video/list/{page_number}") | ||
| 151 | - public View list(int page_number) { | ||
| 152 | - int user_id = CastUtil.castInt(DataContext.getRequest().getSession().getAttribute(LiveUtils.SESSION_KEY_ID)); | ||
| 153 | - Pager<TVideo> page = tVideoService.list(user_id, page_number, 33); | ||
| 154 | - return new View("live/video_management.jsp").data("videos", page); | ||
| 155 | - } | ||
| 156 | - | ||
| 157 | - @Request.Get("/video/check/{page_number}") | ||
| 158 | - public View check(int page_number) { | ||
| 159 | - Pager<TVideo> page = tVideoService.list(page_number, 33); | ||
| 160 | - return new View("live/video_management.jsp").data("videos", page); | ||
| 161 | - } | ||
| 162 | - | ||
| 163 | - @Request.Get("/video/pass/{id}") | ||
| 164 | - public Result pass(int id) { | ||
| 165 | - tVideoService.pass(id); | ||
| 166 | - return new Result(true); | ||
| 167 | - } | ||
| 168 | - | ||
| 169 | - @Request.Get("/video/view/{id}") | ||
| 170 | - public View view(int id) { | ||
| 171 | - TVideo tVideo = tVideoService.getVideoById(id); | ||
| 172 | - System.out.println("------" + tVideo); | ||
| 173 | - return new View("live/video_view.jsp").data("tVideo", tVideo); | ||
| 174 | - } | ||
| 175 | - | ||
| 176 | - @Request.Post("/api/video/one") | ||
| 177 | - public ApiBean one(Params params) { | ||
| 178 | - String app_access_key = params.getString("app_access_key"); | ||
| 179 | - String video_uuid = params.getString("video_uuid"); | ||
| 180 | - TVideo page = tVideoService.getVideoByUuId(video_uuid); | ||
| 181 | - ApiBean apiBean = new ApiBean(); | ||
| 182 | - apiBean.setCode(100); | ||
| 183 | - apiBean.setMessage("请求成功"); | ||
| 184 | - apiBean.setData(page); | ||
| 185 | - return apiBean; | ||
| 186 | - } | ||
| 187 | - | ||
| 188 | - @Request.Post("/api/video/uploadNotify") | ||
| 189 | - public ApiBean uploadNotify(Params params) { | ||
| 190 | - String video_uuid = params.getString("video_uuid"); | ||
| 191 | - String upload_type = params.getString("upload_type"); | ||
| 192 | - String video_type = params.getString("video_type"); | ||
| 193 | - String state = params.getString("state"); | ||
| 194 | - String duration = params.getString("duration"); | ||
| 195 | - xLog("uploadNotify", "duration", duration, video_uuid, video_type, state); | ||
| 196 | - if (video_type.equals("2")) { | ||
| 197 | - // 点播通知 | ||
| 198 | - tVideoService.notify(video_uuid); | ||
| 199 | - } else if (video_type.equals("3")) { | ||
| 200 | - // 直播通知 | ||
| 201 | - // tLiveService.notify(video_uuid); | ||
| 202 | - // 直播正常结束 | ||
| 203 | - tLiveService.notify(video_uuid, 2); | ||
| 204 | - } | ||
| 205 | - ApiBean apiBean = new ApiBean(); | ||
| 206 | - apiBean.setCode(100); | ||
| 207 | - apiBean.setMessage("请求成功"); | ||
| 208 | - return apiBean; | ||
| 209 | - } | ||
| 210 | - | ||
| 211 | - @Request.Get("/api/video/error/{video_uuid}") | ||
| 212 | - public ApiBean error(String video_uuid) { | ||
| 213 | - // 直播异常结束 | ||
| 214 | - tLiveService.notify(video_uuid, -2); | ||
| 215 | - ApiBean apiBean = new ApiBean(); | ||
| 216 | - apiBean.setCode(100); | ||
| 217 | - apiBean.setMessage("请求成功"); | ||
| 218 | - return apiBean; | ||
| 219 | - } | ||
| 220 | - | ||
| 221 | - @Request.Post("/api/video/delete") | ||
| 222 | - public ApiBean delete(Params params) { | ||
| 223 | - String user_access_key = params.getString("user_access_key"); | ||
| 224 | - String video_uuid = params.getString("video_uuid"); | ||
| 225 | - String app_access_key = params.getString("app_access_key"); | ||
| 226 | - String video_type = params.getString("video_type");// 视频类型 | ||
| 227 | - tVideoService.delete(video_uuid); | ||
| 228 | - ApiBean apiBean = new ApiBean(); | ||
| 229 | - apiBean.setCode(100); | ||
| 230 | - apiBean.setMessage("请求成功"); | ||
| 231 | - return apiBean; | ||
| 232 | - } | ||
| 233 | - | ||
| 234 | - private void xLog(String... str) { | ||
| 235 | - StringBuffer sb = new StringBuffer(); | ||
| 236 | - for (int i = 0; i < str.length; i++) { | ||
| 237 | - sb.append(str[i]); | ||
| 238 | - sb.append("|"); | ||
| 239 | - } | ||
| 240 | - log.info(sb.toString()); | ||
| 241 | - } | ||
| 242 | - | ||
| 243 | - @Request.Get("/video/unline/{id}") | ||
| 244 | - public Result underLine(int id) { | ||
| 245 | - boolean flag = tVideoService.underLine(id); | ||
| 246 | - return new Result(flag); | ||
| 247 | - } | ||
| 248 | -} | 1 | +package com.cnlive.mz.live.action; |
| 2 | + | ||
| 3 | +import java.util.Date; | ||
| 4 | +import java.util.LinkedHashMap; | ||
| 5 | +import java.util.Map; | ||
| 6 | + | ||
| 7 | +import org.apache.commons.lang3.StringUtils; | ||
| 8 | +import org.apache.log4j.Logger; | ||
| 9 | +import org.smart4j.framework.dao.bean.Pager; | ||
| 10 | +import org.smart4j.framework.ioc.annotation.Inject; | ||
| 11 | +import org.smart4j.framework.mvc.DataContext; | ||
| 12 | +import org.smart4j.framework.mvc.annotation.Action; | ||
| 13 | +import org.smart4j.framework.mvc.annotation.Request; | ||
| 14 | +import org.smart4j.framework.mvc.bean.ApiBean; | ||
| 15 | +import org.smart4j.framework.mvc.bean.Params; | ||
| 16 | +import org.smart4j.framework.mvc.bean.Result; | ||
| 17 | +import org.smart4j.framework.mvc.bean.View; | ||
| 18 | +import org.smart4j.framework.util.CastUtil; | ||
| 19 | + | ||
| 20 | +import com.cnlive.mz.commons.CnliveUtil; | ||
| 21 | +import com.cnlive.mz.commons.sensitive.FilteredResult; | ||
| 22 | +import com.cnlive.mz.commons.sensitive.WordFilterUtil; | ||
| 23 | +import com.cnlive.mz.live.common.Constants; | ||
| 24 | +import com.cnlive.mz.live.common.LiveUtils; | ||
| 25 | +import com.cnlive.mz.live.entity.TLive; | ||
| 26 | +import com.cnlive.mz.live.entity.TVideo; | ||
| 27 | +import com.cnlive.mz.live.service.TDispatchServerService; | ||
| 28 | +import com.cnlive.mz.live.service.TLiveService; | ||
| 29 | +import com.cnlive.mz.live.service.TUserService; | ||
| 30 | +import com.cnlive.mz.live.service.TVideoService; | ||
| 31 | + | ||
| 32 | +@Action | ||
| 33 | +public class VideoAction { | ||
| 34 | + | ||
| 35 | + private Logger log = Logger.getLogger("action"); | ||
| 36 | + @Inject | ||
| 37 | + private TDispatchServerService tDispatchServerService; | ||
| 38 | + @Inject | ||
| 39 | + private TVideoService tVideoService; | ||
| 40 | + @Inject | ||
| 41 | + private TUserService tUserService; | ||
| 42 | + @Inject | ||
| 43 | + private TLiveService tLiveService; | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 服务器定向 | ||
| 47 | + * | ||
| 48 | + * @param params | ||
| 49 | + * @return | ||
| 50 | + * {"mediaComment":"","nickName":"阳Sir","appId":"1","mediaName":"","userId" | ||
| 51 | + * :"1167015","uuid": | ||
| 52 | + * "1167015_1463725085798_6a551f9122494a05ac8566b7a2ae1092"} | ||
| 53 | + */ | ||
| 54 | + @Request.Post("/api/video/redirect") | ||
| 55 | + public ApiBean redirect(Params params) { | ||
| 56 | + String app_access_key = params.getString("app_access_key"); | ||
| 57 | + String video_type = params.getString("video_type"); | ||
| 58 | + String user_id = params.getString("relation_id"); | ||
| 59 | + ApiBean apiBean = tDispatchServerService.redirect(video_type, app_access_key, user_id); | ||
| 60 | + return apiBean; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + @Request.Post("/api/video/supload") | ||
| 64 | + public ApiBean supload(Params params) { | ||
| 65 | + Map data = new LinkedHashMap(); | ||
| 66 | + String app_access_key = params.getString("app_access_key"); | ||
| 67 | + String video_type = params.getString("video_type"); | ||
| 68 | + String user_access_key = params.getString("user_access_key"); | ||
| 69 | + String server_access_key = params.getString("server_access_key"); | ||
| 70 | + String active_id = params.getString("active_id"); | ||
| 71 | + String title = params.getString("title"); | ||
| 72 | + if (title.length() > 50) { | ||
| 73 | + title = title.substring(0, 50); | ||
| 74 | + } | ||
| 75 | + String description = params.getString("description"); | ||
| 76 | + WordFilterUtil wf = new WordFilterUtil(); | ||
| 77 | + FilteredResult resTitle = wf.filterHtml(title, '*'); | ||
| 78 | + title = resTitle.getFilteredContent().toString(); | ||
| 79 | + FilteredResult resDescr = wf.filterHtml(description, '*'); | ||
| 80 | + description = resDescr.getFilteredContent().toString(); | ||
| 81 | + | ||
| 82 | + String direct = params.getString("direct"); | ||
| 83 | + String custom_args = params.getString("custom_args"); | ||
| 84 | + String md5 = params.getString("md5"); | ||
| 85 | + String relation_id = params.getString("relation_id"); | ||
| 86 | + String uuid = ""; | ||
| 87 | + boolean success = true; | ||
| 88 | + if (video_type.equals("2")) { | ||
| 89 | + // 2:sdk上传录播文件 | ||
| 90 | + TVideo tVideo = new TVideo(); | ||
| 91 | + tVideo.setCustom_args(custom_args); | ||
| 92 | + tVideo.setRelation_id(relation_id); | ||
| 93 | + tVideo.setName(params.getString("name")); | ||
| 94 | + tVideo.setVideo_type(params.getString("video_type")); | ||
| 95 | + tVideo.setPlat(params.getString("plat")); | ||
| 96 | + tVideo.setState(207); | ||
| 97 | + tVideo.setMd5(md5); | ||
| 98 | + uuid = CnliveUtil.getUUID(); | ||
| 99 | + tVideo.setVideo_uuid(uuid); | ||
| 100 | + tVideo.setTitle(title); | ||
| 101 | + tVideo.setDescription(description); | ||
| 102 | + tVideoService.saveSdkVideo(tVideo, server_access_key, user_access_key, app_access_key); | ||
| 103 | + } else if (video_type.equals("3")) { | ||
| 104 | + TLive tLive = tLiveService.getTLiveByUUId(active_id); | ||
| 105 | + tLive.setT_status_id(1); | ||
| 106 | + tLive.setTitle(title); | ||
| 107 | + tLive.setDescription(description); | ||
| 108 | + tLive.setStart_time(new Date()); | ||
| 109 | + tLive.setUser_uuid(params.getString("name")); | ||
| 110 | + tLive.setRelation_id(relation_id); | ||
| 111 | + tLive.setCustom_args(custom_args); | ||
| 112 | + uuid = tLive.getUuid(); | ||
| 113 | + if (StringUtils.isEmpty(direct)) { | ||
| 114 | + tLive.setDirect(0); | ||
| 115 | + } else { | ||
| 116 | + tLive.setDirect(Integer.parseInt(direct)); | ||
| 117 | + } | ||
| 118 | + tLive.setLive_url(Constants.KS_HOST_RTMP + tLive.getT_user_id() ); | ||
| 119 | + success = tLiveService.startLive(tLive); | ||
| 120 | + } | ||
| 121 | + data.put("video_uuid", uuid); | ||
| 122 | + ApiBean apiBean = new ApiBean(); | ||
| 123 | + if (success) { | ||
| 124 | + apiBean.setCode(100); | ||
| 125 | + apiBean.setMessage("请求成功"); | ||
| 126 | + } else { | ||
| 127 | + apiBean.setCode(201); | ||
| 128 | + apiBean.setMessage("发起直播失败"); | ||
| 129 | + } | ||
| 130 | + apiBean.setData(data); | ||
| 131 | + return apiBean; | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + @Request.Post("/api/video/all") | ||
| 135 | + public ApiBean all(Params params) { | ||
| 136 | + String app_access_key = params.getString("app_access_key"); | ||
| 137 | + String relationId = params.getString("relation_id"); | ||
| 138 | + String pageNo = params.getString("page_no"); | ||
| 139 | + String relation_id = params.getString("relation_id"); | ||
| 140 | + String upload_type = params.getString("upload_type"); | ||
| 141 | + // String video_type = params.getString("video_type"); | ||
| 142 | + Pager<TVideo> page = tVideoService.findAll(app_access_key, relationId, pageNo); | ||
| 143 | + ApiBean apiBean = new ApiBean(); | ||
| 144 | + apiBean.setCode(100); | ||
| 145 | + apiBean.setMessage("请求成功"); | ||
| 146 | + apiBean.setData(page); | ||
| 147 | + return apiBean; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + @Request.Get("/video/list/{page_number}") | ||
| 151 | + public View list(int page_number) { | ||
| 152 | + int user_id = CastUtil.castInt(DataContext.getRequest().getSession().getAttribute(LiveUtils.SESSION_KEY_ID)); | ||
| 153 | + Pager<TVideo> page = tVideoService.list(user_id, page_number, 33); | ||
| 154 | + return new View("live/video_management.jsp").data("videos", page); | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + @Request.Get("/video/check/{page_number}") | ||
| 158 | + public View check(int page_number) { | ||
| 159 | + Pager<TVideo> page = tVideoService.list(page_number, 33); | ||
| 160 | + return new View("live/video_management.jsp").data("videos", page); | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + @Request.Get("/video/pass/{id}") | ||
| 164 | + public Result pass(int id) { | ||
| 165 | + tVideoService.pass(id); | ||
| 166 | + return new Result(true); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + @Request.Get("/video/view/{id}") | ||
| 170 | + public View view(int id) { | ||
| 171 | + TVideo tVideo = tVideoService.getVideoById(id); | ||
| 172 | + System.out.println("------" + tVideo); | ||
| 173 | + return new View("live/video_view.jsp").data("tVideo", tVideo); | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + @Request.Post("/api/video/one") | ||
| 177 | + public ApiBean one(Params params) { | ||
| 178 | + String app_access_key = params.getString("app_access_key"); | ||
| 179 | + String video_uuid = params.getString("video_uuid"); | ||
| 180 | + TVideo page = tVideoService.getVideoByUuId(video_uuid); | ||
| 181 | + ApiBean apiBean = new ApiBean(); | ||
| 182 | + apiBean.setCode(100); | ||
| 183 | + apiBean.setMessage("请求成功"); | ||
| 184 | + apiBean.setData(page); | ||
| 185 | + return apiBean; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + @Request.Post("/api/video/uploadNotify") | ||
| 189 | + public ApiBean uploadNotify(Params params) { | ||
| 190 | + String video_uuid = params.getString("video_uuid"); | ||
| 191 | + String upload_type = params.getString("upload_type"); | ||
| 192 | + String video_type = params.getString("video_type"); | ||
| 193 | + String state = params.getString("state"); | ||
| 194 | + String duration = params.getString("duration"); | ||
| 195 | + xLog("uploadNotify", "duration", duration, video_uuid, video_type, state); | ||
| 196 | + if (video_type.equals("2")) { | ||
| 197 | + // 点播通知 | ||
| 198 | + tVideoService.notify(video_uuid); | ||
| 199 | + } else if (video_type.equals("3")) { | ||
| 200 | + // 直播通知 | ||
| 201 | + // tLiveService.notify(video_uuid); | ||
| 202 | + // 直播正常结束 | ||
| 203 | + tLiveService.notify(video_uuid, 2); | ||
| 204 | + } | ||
| 205 | + ApiBean apiBean = new ApiBean(); | ||
| 206 | + apiBean.setCode(100); | ||
| 207 | + apiBean.setMessage("请求成功"); | ||
| 208 | + return apiBean; | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + @Request.Get("/api/video/error/{video_uuid}") | ||
| 212 | + public ApiBean error(String video_uuid) { | ||
| 213 | + // 直播异常结束 | ||
| 214 | + tLiveService.notify(video_uuid, -2); | ||
| 215 | + ApiBean apiBean = new ApiBean(); | ||
| 216 | + apiBean.setCode(100); | ||
| 217 | + apiBean.setMessage("请求成功"); | ||
| 218 | + return apiBean; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + @Request.Post("/api/video/delete") | ||
| 222 | + public ApiBean delete(Params params) { | ||
| 223 | + String user_access_key = params.getString("user_access_key"); | ||
| 224 | + String video_uuid = params.getString("video_uuid"); | ||
| 225 | + String app_access_key = params.getString("app_access_key"); | ||
| 226 | + String video_type = params.getString("video_type");// 视频类型 | ||
| 227 | + tVideoService.delete(video_uuid); | ||
| 228 | + ApiBean apiBean = new ApiBean(); | ||
| 229 | + apiBean.setCode(100); | ||
| 230 | + apiBean.setMessage("请求成功"); | ||
| 231 | + return apiBean; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + private void xLog(String... str) { | ||
| 235 | + StringBuffer sb = new StringBuffer(); | ||
| 236 | + for (int i = 0; i < str.length; i++) { | ||
| 237 | + sb.append(str[i]); | ||
| 238 | + sb.append("|"); | ||
| 239 | + } | ||
| 240 | + log.info(sb.toString()); | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + @Request.Get("/video/unline/{id}") | ||
| 244 | + public Result underLine(int id) { | ||
| 245 | + boolean flag = tVideoService.underLine(id); | ||
| 246 | + return new Result(flag); | ||
| 247 | + } | ||
| 248 | +} |