Commit 655fb5f29ff636baee2f3b928a437220f10a03b1

Authored by 刘基城
1 parent 9edef5c1

修改加入黑名单

src/main/java/com/cnlive/mz/live/action/CheckAction.java
1 1 package com.cnlive.mz.live.action;
2 2  
3   -import java.io.UnsupportedEncodingException;
4   -import java.net.URLEncoder;
5   -import java.util.List;
6   -import java.util.Map;
7   -
8 3 import org.smart4j.framework.dao.bean.Pager;
9 4 import org.smart4j.framework.ioc.annotation.Inject;
10 5 import org.smart4j.framework.mvc.DataContext;
... ... @@ -15,11 +10,8 @@ import org.smart4j.framework.mvc.bean.Result;
15 10 import org.smart4j.framework.mvc.bean.View;
16 11 import org.smart4j.framework.util.CastUtil;
17 12  
18   -import com.cnlive.mz.commons.JsonUtil;
19   -import com.cnlive.mz.commons.net.HttpReq;
20 13 import com.cnlive.mz.live.common.LiveUtils;
21 14 import com.cnlive.mz.live.entity.TLive;
22   -import com.cnlive.mz.live.rest.BaseUtil;
23 15 import com.cnlive.mz.live.service.TCheckService;
24 16 import com.cnlive.mz.live.service.TLiveService;
25 17 import com.cnlive.mz.live.service.TRoomService;
... ... @@ -34,89 +26,61 @@ public class CheckAction {
34 26 @Inject
35 27 private TCheckService tCheckService;
36 28  
37   - // @Request.Get("/check/list/{page_number}")
38   - // public View list(int page_number) {
39   - // int user_id =
40   - // CastUtil.castInt(DataContext.getRequest().getSession().getAttribute(LiveUtils.SESSION_KEY_ID));
41   - // System.out.println(user_id);
42   - // Pager<TLive> tLive = tCheckService.getTCheckLivePager(page_number, 9,
43   - // user_id);
44   - // List list = tLiveService.getLives(user_id);
45   - // View view = new View("check/check_management.jsp");
46   - // view.data("tLive", tLive);
47   - // view.data("list", list);
48   - // return view;
49   - // //return new View("check/demo.html");
50   - // }
  29 + /**
  30 + * 切断直播流
  31 + * @param id
  32 + * @param params
  33 + * @return
  34 + */
51 35 @Request.Post("/check/close/{id}")
52   - public Result coseLive(int id, Params params) throws UnsupportedEncodingException {
53   - String userId = params.getString("user_id");
54   - String streamName = userId + "_" + id;
55   - String accesskey = BaseUtil.getAccessKey();
56   - accesskey = java.net.URLEncoder.encode(accesskey, "utf-8");
57   - String signature = BaseUtil.signature(streamName);
58   - String del = "del";
59   - String delsignature = BaseUtil.signature(del, streamName);
60   - String expire = BaseUtil.getTimestamp();
61   - System.out.println(expire + "---expire---");
62   - // ��ӵ�������
63   - try {
64   - addBlackList(signature, accesskey, expire, streamName);
65   - delBlackList(delsignature, accesskey, expire, streamName);
66   - } catch (UnsupportedEncodingException e) {
67   - e.printStackTrace();
68   - }
69   - boolean flag = tCheckService.closeLive(id);
  36 + public Result cose(int id, Params params) {
  37 + String streamName = params.getString("user_id");
  38 + String uuid = params.getString("uuid");
  39 + boolean flag = tCheckService.close(streamName,id,uuid);
70 40 return new Result(flag);
71 41 }
72 42  
73 43 /**
74   - * ��ӵ�����
75   - *
76   - * @param signature
77   - * @param accesskey
78   - * @param expire
79   - * @param streamName
  44 + * 回复黑名单
  45 + * @param id
  46 + * @param params
80 47 * @return
81   - * @throws UnsupportedEncodingException
82 48 */
83   - public String addBlackList(String signature, String accesskey, String expire, String streamName)
84   - throws UnsupportedEncodingException {
85   - String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature=" + signature + "&accesskey=" + accesskey
86   - + "&expire=" + expire + "&app=live&method=add&name=" + streamName;
87   - System.out.println(url);
88   - String jsonArrStr = HttpReq.getRequestWidthResult(url);
89   - int status = HttpReq.getRequest(url);
90   - System.out.println(status + "......and......" + jsonArrStr);
91   - /*
92   - * Map map = JsonUtil.getMapFromJsonObjStr(jsonArrStr); String
93   - * chatRoomid = (String) map.get("Content-Length");
94   - */
95   - return jsonArrStr;
  49 + @Request.Post("/check/resume/{id}")
  50 + public Result resume(int id, Params params){
  51 + String streamName = params.getString("user_id");
  52 + boolean flag = tCheckService.resume(streamName,id);
  53 + return new Result(flag);
96 54 }
  55 +
97 56  
98   - /**
99   - * �Ӻ���ɾ��
100   - *
101   - * @param signature
102   - * @param accesskey
103   - * @param expire
104   - * @param streamName
105   - * @return
106   - * @throws UnsupportedEncodingException
107   - */
108   - public Object delBlackList(String signature, String accesskey, String expire, String streamName)
109   - throws UnsupportedEncodingException {
110   - String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature=" + signature + "&accesskey=" + accesskey
111   - + "&expire=" + expire + "&app=live&method=del&name=" + streamName;
112   - System.out.println("..url.." + url);
113   - String jsonArrStr = HttpReq.getRequestWidthResult(url);
114   - System.out.println("..jsonArrStr.." + jsonArrStr);
115   - /*
116   - * Map map = JsonUtil.getMapFromJsonObjStr(jsonArrStr); String
117   - * chatRoomid = (String) map.get("Content-Length");
118   - */
119   - return jsonArrStr;
  57 + @Request.Get("/check/list/{page_number}")
  58 + public View check(int page_number) {
  59 + int user_id = CastUtil.castInt(DataContext.getRequest().getSession().getAttribute(LiveUtils.SESSION_KEY_ID));
  60 + Pager<TLive> tLive = tLiveService.getTCheckLivePager(page_number, 12, user_id);
  61 + View view = new View("check/monitor.jsp");
  62 + view.data("tLive", tLive);
  63 + return view;
  64 + }
  65 +
  66 + // 置顶
  67 + @Request.Get("/check/top/{id}")
  68 + public Result top(int id) {
  69 + tLiveService.top(id);
  70 + return new Result(true);
  71 + }
  72 +
  73 + // 通过审核
  74 + @Request.Get("/check/pass/{id}")
  75 + public Result pass(int id) {
  76 + tLiveService.pass(id);
  77 + return new Result(true);
  78 + }
  79 +
  80 + @Request.Post("/check/close/{id}/{uuid}")
  81 + public Result coseLive(int id, String uuid) {
  82 + boolean flag = tLiveService.closeLive(id, uuid);
  83 + return new Result(flag);
120 84 }
121 85  
122 86 }
... ...
src/main/java/com/cnlive/mz/live/action/LiveAction.java
... ... @@ -28,7 +28,6 @@ import org.smart4j.framework.mvc.bean.Params;
28 28 import org.smart4j.framework.mvc.bean.Result;
29 29 import org.smart4j.framework.mvc.bean.ResultBean;
30 30 import org.smart4j.framework.mvc.bean.View;
31   -import org.smart4j.framework.orm.DataSet;
32 31 import org.smart4j.framework.util.CastUtil;
33 32  
34 33 import com.cnlive.mz.commons.Constants;
... ... @@ -36,7 +35,6 @@ import com.cnlive.mz.commons.net.HttpReq;
36 35 import com.cnlive.mz.live.common.LiveUtils;
37 36 import com.cnlive.mz.live.entity.TLive;
38 37 import com.cnlive.mz.live.entity.TRoom;
39   -import com.cnlive.mz.live.rest.BaseUtil;
40 38 import com.cnlive.mz.live.service.TCheckService;
41 39 import com.cnlive.mz.live.service.TLiveService;
42 40 import com.cnlive.mz.live.service.TRoomService;
... ... @@ -109,107 +107,6 @@ public class LiveAction {
109 107 return view;
110 108 }
111 109  
112   - @Request.Get("/check/list/{page_number}")
113   - public View check(int page_number) {
114   - int user_id = CastUtil.castInt(DataContext.getRequest().getSession().getAttribute(LiveUtils.SESSION_KEY_ID));
115   - Pager<TLive> tLive = tLiveService.getTCheckLivePager(page_number, 12, user_id);
116   - View view = new View("check/monitor.jsp");
117   - view.data("tLive", tLive);
118   - return view;
119   - }
120   -
121   - // 置顶
122   - @Request.Get("/check/top/{id}")
123   - public Result top(int id) {
124   - tLiveService.top(id);
125   - return new Result(true);
126   - }
127   -
128   - // 切断
129   - @Request.Post("/check/cut/{id}")
130   - public Result cut(int id, Params params) throws UnsupportedEncodingException {
131   - String live_url = params.getString("live_url");
132   - if (live_url.isEmpty()) {
133   - return null;
134   - } else {
135   - int index = live_url.lastIndexOf("/");
136   - String streamName = live_url.substring(index + 1);
137   - System.out.println("streamName===" + streamName);
138   - String accesskey = BaseUtil.getAccessKey();
139   - accesskey = java.net.URLEncoder.encode(accesskey, "utf-8");
140   - String add = "add";
141   - String signature = BaseUtil.signature(add, streamName);
142   - String del = "del";
143   - String delsignature = BaseUtil.signature(del, streamName);
144   - String expire = BaseUtil.getTimestamp();
145   - System.out.println(expire + "---expire---");
146   - // 断流。
147   - try {
148   - addBlackList(signature, accesskey, expire, streamName);
149   - // delBlackList(delsignature, accesskey, expire, streamName);
150   - } catch (UnsupportedEncodingException e) {
151   - e.printStackTrace();
152   - }
153   - // 直播通知
154   - // tLiveService.notify(video_uuid, -1);
155   - boolean flag = tCheckService.closeLive(id);
156   - return new Result(flag);
157   - }
158   - }
159   -
160   - // 通过审核
161   - @Request.Get("/check/pass/{id}")
162   - public Result pass(int id) {
163   - tLiveService.pass(id);
164   - return new Result(true);
165   - }
166   -
167   - @Request.Post("/check/close/{id}/{uuid}")
168   - public Result coseLive(int id, String uuid) {
169   - boolean flag = tLiveService.closeLive(id, uuid);
170   - return new Result(flag);
171   - }
172   -
173   - /**
174   - * 添加到黑名单
175   - *
176   - * @param signature
177   - * @param accesskey
178   - * @param expire
179   - * @param streamName
180   - * @return
181   - * @throws UnsupportedEncodingException
182   - */
183   - public String addBlackList(String signature, String accesskey, String expire, String streamName)
184   - throws UnsupportedEncodingException {
185   - String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature=" + signature + "&accesskey=" + accesskey
186   - + "&expire=" + expire + "&app=live&method=add&name=" + streamName;
187   - String jsonArrStr = HttpReq.getRequestWidthResult(url);
188   - int status = HttpReq.getRequest(url);
189   - System.out.println(status + "......and......" + jsonArrStr);
190   - return jsonArrStr;
191   - }
192   -
193   - /**
194   - * 从黑名单删除
195   - *
196   - * @param signature
197   - * @param accesskey
198   - * @param expire
199   - * @param streamName
200   - * @return
201   - * @throws UnsupportedEncodingException
202   - */
203   - public Object delBlackList(String signature, String accesskey, String expire, String streamName)
204   - throws UnsupportedEncodingException {
205   - String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature=" + signature + "&accesskey=" + accesskey
206   - + "&expire=" + expire + "&app=live&method=del&name=" + streamName;
207   - String jsonArrStr = HttpReq.getRequestWidthResult(url);
208   - System.out.println("..jsonArrStr.." + jsonArrStr);
209   - return jsonArrStr;
210   -
211   - }
212   -
213 110 @Request.Get("/live/alllive/{page_number}")
214 111 public View liveList(int page_number) {
215 112 int user_id = CastUtil.castInt(DataContext.getRequest().getSession().getAttribute(LiveUtils.SESSION_KEY_ID));
... ... @@ -297,11 +194,10 @@ public class LiveAction {
297 194 log.error("创建活动失败,活动ID已存在");
298 195 return rb;
299 196 } else {
300   -
301 197 boolean flag = tLiveService.addAcitvity(params);
302 198 if (flag) {
303 199 Map<String, Object> map = new HashMap<String, Object>();
304   - map.put("location", "rtmp://jsrtmp.up.cnlive.com/live/1234");
  200 + map.put("location", com.cnlive.mz.live.common.Constants.KS_HOST_UP_RTMP+channelID+"?vdoid=" + activityId);
305 201 rb.setData(map);
306 202 rb.setErrorCode("0");
307 203 rb.setErrorMessage("创建活动成功");
... ... @@ -382,24 +278,6 @@ public class LiveAction {
382 278 int index = live_url.lastIndexOf("/");
383 279 String streamName = live_url.substring(index + 1);
384 280 System.out.println("streamName===" + streamName);
385   - String accesskey = BaseUtil.getAccessKey();
386   - try {
387   - accesskey = java.net.URLEncoder.encode(accesskey, "utf-8");
388   - String add = "add";
389   - String signature = BaseUtil.signature(add, streamName);
390   - String del = "del";
391   - String delsignature = BaseUtil.signature(del, streamName);
392   - String expire = BaseUtil.getTimestamp();
393   - System.out.println(expire + "---expire---");
394   - // 断流。
395   - addBlackList(signature, accesskey, expire, streamName);
396   - } catch (UnsupportedEncodingException e1) {
397   - // TODO Auto-generated catch block
398   - e1.printStackTrace();
399   - }
400   - // 直播通知
401   - // tLiveService.notify(video_uuid, -1);
402   - boolean flag = tCheckService.closeLive(Integer.parseInt(activityid));
403 281 Map<String, Object> map = new HashMap<String, Object>();
404 282 map.put("location", tLive.getLive_url());
405 283 rb.setData(map);
... ... @@ -505,6 +383,7 @@ public class LiveAction {
505 383 rb.setErrorMessage("失败");
506 384 return rb;
507 385 }
  386 +
508 387 public static void main(String[] args) {
509 388 /*
510 389 * Map<String, Object> mapFiles = new HashMap<String, Object>();
... ... @@ -548,8 +427,7 @@ public class LiveAction {
548 427 nvp[5] = nv6;
549 428 String ss = HttpReq.postRequestWidthResult("http://bc.cnlive.com/live/epg/createActivity", nvp);
550 429 System.out.println(ss);
551   - String aa = HttpReq
552   - .getRequestWidthResult("http://bc.cnlive.com/live/epg/startActivity?appId=123&activityId=234");
  430 + String aa = HttpReq.getRequestWidthResult("http://bc.cnlive.com/live/epg/startActivity?appId=123&activityId=234");
553 431 System.out.println(aa);
554 432 }
555 433 }
556 434 \ No newline at end of file
... ...