Commit 53fa794fb6cb6343a8486a1953249f8c42bc4fc4
1 parent
9af6d59d
live接口
Showing
5 changed files
with
183 additions
and
24 deletions
.classpath
| @@ -26,7 +26,7 @@ | @@ -26,7 +26,7 @@ | ||
| 26 | </classpathentry> | 26 | </classpathentry> |
| 27 | <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> | 27 | <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> |
| 28 | <attributes> | 28 | <attributes> |
| 29 | - <attribute name="maven.pomderived" value="true"/> | 29 | + <attribute name="owner.project.facets" value="java"/> |
| 30 | </attributes> | 30 | </attributes> |
| 31 | </classpathentry> | 31 | </classpathentry> |
| 32 | <classpathentry kind="output" path="target/classes"/> | 32 | <classpathentry kind="output" path="target/classes"/> |
.settings/org.eclipse.wst.common.project.facet.core.xml
| @@ -3,5 +3,5 @@ | @@ -3,5 +3,5 @@ | ||
| 3 | <installed facet="jst.web" version="3.0"/> | 3 | <installed facet="jst.web" version="3.0"/> |
| 4 | <installed facet="wst.jsdt.web" version="1.0"/> | 4 | <installed facet="wst.jsdt.web" version="1.0"/> |
| 5 | <installed facet="jst.jaxrs" version="1.1"/> | 5 | <installed facet="jst.jaxrs" version="1.1"/> |
| 6 | - <installed facet="java" version="1.6"/> | 6 | + <installed facet="java" version="1.7"/> |
| 7 | </faceted-project> | 7 | </faceted-project> |
src/main/java/com/cnlive/mz/live/action/LiveAction.java
| @@ -9,11 +9,15 @@ | @@ -9,11 +9,15 @@ | ||
| 9 | 9 | ||
| 10 | package com.cnlive.mz.live.action; | 10 | package com.cnlive.mz.live.action; |
| 11 | 11 | ||
| 12 | +import java.io.IOException; | ||
| 12 | import java.io.UnsupportedEncodingException; | 13 | import java.io.UnsupportedEncodingException; |
| 13 | import java.util.HashMap; | 14 | import java.util.HashMap; |
| 14 | import java.util.List; | 15 | import java.util.List; |
| 15 | import java.util.Map; | 16 | import java.util.Map; |
| 16 | 17 | ||
| 18 | +import javax.servlet.http.HttpServletRequest; | ||
| 19 | +import javax.servlet.http.HttpServletResponse; | ||
| 20 | + | ||
| 17 | import org.apache.commons.httpclient.NameValuePair; | 21 | import org.apache.commons.httpclient.NameValuePair; |
| 18 | import org.apache.commons.lang.StringUtils; | 22 | import org.apache.commons.lang.StringUtils; |
| 19 | import org.apache.log4j.Logger; | 23 | import org.apache.log4j.Logger; |
| @@ -34,6 +38,7 @@ import org.smart4j.framework.util.CastUtil; | @@ -34,6 +38,7 @@ import org.smart4j.framework.util.CastUtil; | ||
| 34 | import com.cnlive.mz.commons.Constants; | 38 | import com.cnlive.mz.commons.Constants; |
| 35 | import com.cnlive.mz.commons.net.HttpReq; | 39 | import com.cnlive.mz.commons.net.HttpReq; |
| 36 | import com.cnlive.mz.live.common.LiveUtils; | 40 | import com.cnlive.mz.live.common.LiveUtils; |
| 41 | +import com.cnlive.mz.live.entity.TChannel; | ||
| 37 | import com.cnlive.mz.live.entity.TLive; | 42 | import com.cnlive.mz.live.entity.TLive; |
| 38 | import com.cnlive.mz.live.entity.TRoom; | 43 | import com.cnlive.mz.live.entity.TRoom; |
| 39 | import com.cnlive.mz.live.rest.BaseUtil; | 44 | import com.cnlive.mz.live.rest.BaseUtil; |
| @@ -306,6 +311,8 @@ public class LiveAction { | @@ -306,6 +311,8 @@ public class LiveAction { | ||
| 306 | rb.setErrorCode("0"); | 311 | rb.setErrorCode("0"); |
| 307 | rb.setErrorMessage("创建活动成功"); | 312 | rb.setErrorMessage("创建活动成功"); |
| 308 | log.info("创建活动成功"); | 313 | log.info("创建活动成功"); |
| 314 | + //通知cms直播 | ||
| 315 | + boolean success = tLiveService.startLive(tLive); | ||
| 309 | return rb; | 316 | return rb; |
| 310 | } else { | 317 | } else { |
| 311 | Map<String, Object> map = new HashMap<String, Object>(); | 318 | Map<String, Object> map = new HashMap<String, Object>(); |
| @@ -391,10 +398,11 @@ public class LiveAction { | @@ -391,10 +398,11 @@ public class LiveAction { | ||
| 391 | String delsignature = BaseUtil.signature(del, streamName); | 398 | String delsignature = BaseUtil.signature(del, streamName); |
| 392 | String expire = BaseUtil.getTimestamp(); | 399 | String expire = BaseUtil.getTimestamp(); |
| 393 | System.out.println(expire + "---expire---"); | 400 | System.out.println(expire + "---expire---"); |
| 394 | - // 断流。 | 401 | + // 直播断流。 |
| 395 | addBlackList(signature, accesskey, expire, streamName); | 402 | addBlackList(signature, accesskey, expire, streamName); |
| 403 | + //通知cms停止直播 | ||
| 404 | + tLiveService.releaseChatRoom(tLive); | ||
| 396 | } catch (UnsupportedEncodingException e1) { | 405 | } catch (UnsupportedEncodingException e1) { |
| 397 | - // TODO Auto-generated catch block | ||
| 398 | e1.printStackTrace(); | 406 | e1.printStackTrace(); |
| 399 | } | 407 | } |
| 400 | // 直播通知 | 408 | // 直播通知 |
| @@ -494,7 +502,156 @@ public class LiveAction { | @@ -494,7 +502,156 @@ public class LiveAction { | ||
| 494 | return rb; | 502 | return rb; |
| 495 | } | 503 | } |
| 496 | } | 504 | } |
| 497 | - | 505 | + |
| 506 | + /** | ||
| 507 | + * 1.8 获取APP直播URL接口.md | ||
| 508 | + * | ||
| 509 | + * @param params | ||
| 510 | + * @return | ||
| 511 | + */ | ||
| 512 | + @Request.Get("/live/epg/play/app") | ||
| 513 | + public ResultBean appURL(Params params) throws IOException { | ||
| 514 | + HttpServletResponse response = DataContext.getResponse(); | ||
| 515 | + ResultBean rb = new ResultBean(); | ||
| 516 | + String appId = params.getString("appId"); | ||
| 517 | + String activityid = params.getString("activityId"); | ||
| 518 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
| 519 | + if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(activityid)) { | ||
| 520 | + map.put("location", ""); | ||
| 521 | + rb.setData(map); | ||
| 522 | + rb.setErrorCode("500"); | ||
| 523 | + rb.setErrorMessage("启动app活动失败"); | ||
| 524 | + return rb; | ||
| 525 | + } else { | ||
| 526 | + TLive tLive = tLiveService.selectByParams(appId, activityid); | ||
| 527 | + TChannel tchannel = tLiveService.selectChannel(tLive.getRelation_id()); | ||
| 528 | + if(tchannel!=null){ | ||
| 529 | + // 请求到app....... | ||
| 530 | + redirect(response, "http://ips.cnlive.com/IPS/liveplayByAPP.action?appId="+appId+"&channelID="+tLive.getRelation_id()); | ||
| 531 | + map.put("location", ""); | ||
| 532 | + rb.setData(map); | ||
| 533 | + rb.setErrorCode("0"); | ||
| 534 | + rb.setErrorMessage("302重定向到app"); | ||
| 535 | + return rb; | ||
| 536 | + }else{ | ||
| 537 | + map.put("location", tLive.getLive_url()); | ||
| 538 | + rb.setData(map); | ||
| 539 | + rb.setErrorCode("0"); | ||
| 540 | + rb.setErrorMessage("启动app活动成功"); | ||
| 541 | + return rb; | ||
| 542 | + } | ||
| 543 | + } | ||
| 544 | + | ||
| 545 | + } | ||
| 546 | + | ||
| 547 | + /** | ||
| 548 | + * 1.9 获取H5直播URL接口.md | ||
| 549 | + * | ||
| 550 | + * @param params | ||
| 551 | + * @return | ||
| 552 | + */ | ||
| 553 | + @Request.Get("/live/epg/play/h5") | ||
| 554 | + public ResultBean h5URL(Params params) { | ||
| 555 | + HttpServletResponse response = DataContext.getResponse(); | ||
| 556 | + ResultBean rb = new ResultBean(); | ||
| 557 | + String appId = params.getString("appId"); | ||
| 558 | + String activityid = params.getString("activityId"); | ||
| 559 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
| 560 | + if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(activityid)) { | ||
| 561 | + map.put("location", ""); | ||
| 562 | + rb.setData(map); | ||
| 563 | + rb.setErrorCode("500"); | ||
| 564 | + rb.setErrorMessage("启动h5活动失败"); | ||
| 565 | + return rb; | ||
| 566 | + } else { | ||
| 567 | + TLive tLive = tLiveService.selectByParams(appId, activityid); | ||
| 568 | + TChannel tchannel = tLiveService.selectChannel(tLive.getRelation_id()); | ||
| 569 | + if(tchannel!=null){ | ||
| 570 | + // 重定向到h5....... | ||
| 571 | + redirect(response, "http://ips.cnlive.com/IPS/liveplayByH5?appId="+appId+"&channelID="+tLive.getRelation_id()); | ||
| 572 | + map.put("location", ""); | ||
| 573 | + rb.setData(map); | ||
| 574 | + rb.setErrorCode("0"); | ||
| 575 | + rb.setErrorMessage("302重定向到h5"); | ||
| 576 | + return rb; | ||
| 577 | + }else{ | ||
| 578 | + map.put("location", tLive.getLive_url()); | ||
| 579 | + rb.setData(map); | ||
| 580 | + rb.setErrorCode("0"); | ||
| 581 | + rb.setErrorMessage("启动h5活动成功"); | ||
| 582 | + return rb; | ||
| 583 | + } | ||
| 584 | + } | ||
| 585 | + | ||
| 586 | + } | ||
| 587 | + | ||
| 588 | + /** | ||
| 589 | + * 2.0 获取SWF直播URL接口.md | ||
| 590 | + * | ||
| 591 | + * @param params | ||
| 592 | + * @return | ||
| 593 | + */ | ||
| 594 | + @Request.Get("/live/epg/play/swf") | ||
| 595 | + public ResultBean swfURL(Params params) { | ||
| 596 | + HttpServletResponse response = DataContext.getResponse(); | ||
| 597 | + ResultBean rb = new ResultBean(); | ||
| 598 | + String appId = params.getString("appId"); | ||
| 599 | + String activityid = params.getString("activityId"); | ||
| 600 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
| 601 | + if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(activityid)) { | ||
| 602 | + map.put("location", ""); | ||
| 603 | + rb.setData(map); | ||
| 604 | + rb.setErrorCode("500"); | ||
| 605 | + rb.setErrorMessage("启动swf活动失败"); | ||
| 606 | + return rb; | ||
| 607 | + } else { | ||
| 608 | + TLive tLive = tLiveService.selectByParams(appId, activityid); | ||
| 609 | + TChannel tchannel = tLiveService.selectChannel(tLive.getRelation_id()); | ||
| 610 | + rb.setData(map); | ||
| 611 | + rb.setErrorCode("0"); | ||
| 612 | + if(tchannel!=null){ | ||
| 613 | + // 302重定向到swf....... | ||
| 614 | + redirect(response, "http://ips.cnlive.com/IPS/liveplayBySWF.action?appId="+appId+"&channelID="+tLive.getRelation_id()); | ||
| 615 | + map.put("location", ""); | ||
| 616 | + rb.setErrorMessage("302重定向到swf"); | ||
| 617 | + return rb; | ||
| 618 | + }else{ | ||
| 619 | + | ||
| 620 | + map.put("location", tLive.getLive_url()); | ||
| 621 | + rb.setErrorMessage("启动swf活动成功"); | ||
| 622 | + return rb; | ||
| 623 | + } | ||
| 624 | + } | ||
| 625 | + | ||
| 626 | + } | ||
| 627 | + /** | ||
| 628 | + * 2.1 获取推流直播播放地址.md | ||
| 629 | + * | ||
| 630 | + * @param params | ||
| 631 | + * @return | ||
| 632 | + */ | ||
| 633 | + @Request.Get("/live/epg/play") | ||
| 634 | + public ResultBean startLiveActivity(Params params) { | ||
| 635 | + ResultBean rb = new ResultBean(); | ||
| 636 | + String appId = params.getString("appId"); | ||
| 637 | + String activityid = params.getString("activityId"); | ||
| 638 | + if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(activityid)) { | ||
| 639 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
| 640 | + map.put("location", ""); | ||
| 641 | + rb.setData(map); | ||
| 642 | + rb.setErrorCode("500"); | ||
| 643 | + rb.setErrorMessage("启动活动失败"); | ||
| 644 | + return rb; | ||
| 645 | + } else { | ||
| 646 | + TLive tLive = tLiveService.selectByParams(appId, activityid); | ||
| 647 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
| 648 | + map.put("location", tLive.getLive_url()); | ||
| 649 | + rb.setData(map); | ||
| 650 | + rb.setErrorCode("0"); | ||
| 651 | + rb.setErrorMessage("启动活动成功"); | ||
| 652 | + return rb; | ||
| 653 | + } | ||
| 654 | + } | ||
| 498 | @Request.Post("/live/epg/error500") | 655 | @Request.Post("/live/epg/error500") |
| 499 | public ResultBean error(Params params) { | 656 | public ResultBean error(Params params) { |
| 500 | ResultBean rb = new ResultBean(); | 657 | ResultBean rb = new ResultBean(); |
| @@ -505,23 +662,25 @@ public class LiveAction { | @@ -505,23 +662,25 @@ public class LiveAction { | ||
| 505 | rb.setErrorMessage("失败"); | 662 | rb.setErrorMessage("失败"); |
| 506 | return rb; | 663 | return rb; |
| 507 | } | 664 | } |
| 665 | + | ||
| 666 | + public static void redirect(HttpServletResponse response, String redirectUrl) { | ||
| 667 | + try { | ||
| 668 | + response.setContentType("application/mpegurl"); | ||
| 669 | + response.setStatus(302); | ||
| 670 | + response.setHeader("Location", redirectUrl); | ||
| 671 | + response.setHeader("Connection", "close"); | ||
| 672 | + } catch (Exception e) { | ||
| 673 | + throw new RuntimeException(e); | ||
| 674 | + } | ||
| 675 | + } | ||
| 676 | + @Request.Get("/live/epg/302") | ||
| 677 | + public void red302() { | ||
| 678 | + HttpServletResponse response =DataContext.getResponse(); | ||
| 679 | + redirect(response, "http://ips.cnlive.com/IPS/liveplayBySWF.action?activityId=12345"); | ||
| 680 | + } | ||
| 508 | public static void main(String[] args) { | 681 | public static void main(String[] args) { |
| 509 | - /* | ||
| 510 | - * Map<String, Object> mapFiles = new HashMap<String, Object>(); | ||
| 511 | - * mapFiles.put("app_id", null); mapFiles.put("start_time", ""); | ||
| 512 | - * mapFiles.put("end_time",""); // TODO 活动id mapFiles.put("category", | ||
| 513 | - * ""); boolean flag = DataSet.insert(TLive.class, mapFiles); | ||
| 514 | - * System.out.println(flag); | ||
| 515 | - */ | ||
| 516 | - // String appId = params.getString("appId"); | ||
| 517 | - // String activityid = params.getString("activityid"); | ||
| 518 | - // String activityname = params.getString("activityname"); | ||
| 519 | - // int activitystatus = params.getInt("activitystatus"); | ||
| 520 | - // int isHorizontalScreen = params.getInt("isHorizontalScreen"); | ||
| 521 | - // String channelID = params.getString("channelID"); | ||
| 522 | - // NameValuePair nv1 = new NameValuePair("appId", "123"); | ||
| 523 | - // NameValuePair nv2 = new NameValuePair("activityid", "234"); | ||
| 524 | - NameValuePair[] nvp = new NameValuePair[6]; | 682 | + |
| 683 | + /*NameValuePair[] nvp = new NameValuePair[6]; | ||
| 525 | NameValuePair nv1 = new NameValuePair(); | 684 | NameValuePair nv1 = new NameValuePair(); |
| 526 | nv1.setName("appId"); | 685 | nv1.setName("appId"); |
| 527 | nv1.setValue("123"); | 686 | nv1.setValue("123"); |
| @@ -550,6 +709,6 @@ public class LiveAction { | @@ -550,6 +709,6 @@ public class LiveAction { | ||
| 550 | System.out.println(ss); | 709 | System.out.println(ss); |
| 551 | String aa = HttpReq | 710 | String aa = HttpReq |
| 552 | .getRequestWidthResult("http://bc.cnlive.com/live/epg/startActivity?appId=123&activityId=234"); | 711 | .getRequestWidthResult("http://bc.cnlive.com/live/epg/startActivity?appId=123&activityId=234"); |
| 553 | - System.out.println(aa); | 712 | + System.out.println(aa);*/ |
| 554 | } | 713 | } |
| 555 | } | 714 | } |
| 556 | \ No newline at end of file | 715 | \ No newline at end of file |
src/main/java/com/cnlive/socket/SocketServer.java
| @@ -130,7 +130,7 @@ public class SocketServer { | @@ -130,7 +130,7 @@ public class SocketServer { | ||
| 130 | oos.flush(); | 130 | oos.flush(); |
| 131 | } */ | 131 | } */ |
| 132 | } catch (Exception e) { | 132 | } catch (Exception e) { |
| 133 | - System.out.println(System.currentTimeMillis()-lastReceiveTime); | 133 | + System.out.println(System.currentTimeMillis()-lastReceiveTime); |
| 134 | e.printStackTrace(); | 134 | e.printStackTrace(); |
| 135 | overThis(); | 135 | overThis(); |
| 136 | } | 136 | } |
target/m2e-wtp/web-resources/META-INF/maven/com.cnlive.mz.live.web/cnlive_live_web/pom.properties
| 1 | #Generated by Maven Integration for Eclipse | 1 | #Generated by Maven Integration for Eclipse |
| 2 | -#Fri Aug 12 09:21:48 CST 2016 | 2 | +#Fri Aug 19 09:15:52 CST 2016 |
| 3 | version=0.0.1-SNAPSHOT | 3 | version=0.0.1-SNAPSHOT |
| 4 | groupId=com.cnlive.mz.live.web | 4 | groupId=com.cnlive.mz.live.web |
| 5 | m2e.projectName=cnlive_live_web | 5 | m2e.projectName=cnlive_live_web |