Commit 8da282ed336c70e83ecf5b5fda3bcd90febc0a73

Authored by 张宗朋
1 parent ae7626ef

checkaction

src/main/java/com/cnlive/mz/live/action/CheckAction.java
1   -package com.cnlive.mz.live.action;
2   -
3   -import java.io.UnsupportedEncodingException;
4   -import java.net.URLEncoder;
5   -import java.util.List;
6   -import java.util.Map;
7   -
8   -import org.smart4j.framework.dao.bean.Pager;
9   -import org.smart4j.framework.ioc.annotation.Inject;
10   -import org.smart4j.framework.mvc.DataContext;
11   -import org.smart4j.framework.mvc.annotation.Action;
12   -import org.smart4j.framework.mvc.annotation.Request;
13   -import org.smart4j.framework.mvc.bean.Params;
14   -import org.smart4j.framework.mvc.bean.Result;
15   -import org.smart4j.framework.mvc.bean.View;
16   -import org.smart4j.framework.util.CastUtil;
17   -
18   -import com.cnlive.mz.commons.JsonUtil;
19   -import com.cnlive.mz.commons.net.HttpReq;
20   -import com.cnlive.mz.live.common.LiveUtils;
21   -import com.cnlive.mz.live.entity.TLive;
22   -import com.cnlive.mz.live.rest.BaseUtil;
23   -import com.cnlive.mz.live.service.TCheckService;
24   -import com.cnlive.mz.live.service.TLiveService;
25   -import com.cnlive.mz.live.service.TRoomService;
26   -
27   -@Action
28   -public class CheckAction {
29   -
30   - @Inject
31   - private TLiveService tLiveService;
32   - @Inject
33   - private TRoomService tRoomService;
34   - @Inject
35   - private TCheckService tCheckService;
36   -
37   - @Request.Get("/check/list/{page_number}")
38   - public View list(int page_number) {
39   - int user_id = CastUtil.castInt(DataContext.getRequest().getSession().getAttribute(LiveUtils.SESSION_KEY_ID));
40   - System.out.println(user_id);
41   - Pager<TLive> tLive = tCheckService.getTCheckLivePager(page_number, 9, user_id);
42   - List list = tLiveService.getLives(user_id);
43   - View view = new View("check/check_management.jsp");
44   - view.data("tLive", tLive);
45   - view.data("list", list);
46   - return view;
47   - //return new View("check/demo.html");
48   - }
49   - @Request.Post("/check/close/{id}")
50   - public Result coseLive(int id,Params params) throws UnsupportedEncodingException{
51   - String userId = params.getString("user_id");
52   - String streamName = userId+"_"+id;
53   - String accesskey = BaseUtil.getAccessKey();
54   - accesskey = java.net.URLEncoder.encode(accesskey,"utf-8");
55   - String signature = BaseUtil.signature(streamName);
56   - String del = "del";
57   - String delsignature = BaseUtil.signature(del,streamName);
58   - String expire = BaseUtil.getTimestamp();
59   - System.out.println(expire+"---expire---");
60   - //添加到黑名单。。
61   - try {
62   - addBlackList(signature,accesskey,expire,streamName);
63   - delBlackList(delsignature,accesskey,expire,streamName);
64   - } catch (UnsupportedEncodingException e) {
65   - e.printStackTrace();
66   - }
67   - boolean flag = tCheckService.closeLive(id);
68   - return new Result(flag);
69   - }
70   - /**
71   - * 添加到黑名单
72   - * @param signature
73   - * @param accesskey
74   - * @param expire
75   - * @param streamName
76   - * @return
77   - * @throws UnsupportedEncodingException
78   - */
79   - public String addBlackList(String signature, String accesskey, String expire,String streamName) throws UnsupportedEncodingException {
80   - String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature="+signature+"&accesskey="+accesskey+"&expire="+expire+"&app=live&method=add&name=" + streamName;
81   - System.out.println(url);
82   - String jsonArrStr = HttpReq.getRequestWidthResult(url);
83   - int status = HttpReq.getRequest(url);
84   - System.out.println(status+"......and......"+jsonArrStr);
85   - /*Map map = JsonUtil.getMapFromJsonObjStr(jsonArrStr);
86   - String chatRoomid = (String) map.get("Content-Length");*/
87   - return jsonArrStr;
88   - }
89   - /**
90   - * 从黑名单删除
91   - * @param signature
92   - * @param accesskey
93   - * @param expire
94   - * @param streamName
95   - * @return
96   - * @throws UnsupportedEncodingException
97   - */
98   - public Object delBlackList(String signature, String accesskey, String expire,String streamName) throws UnsupportedEncodingException {
99   - String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature="+signature+"&accesskey="+accesskey+"&expire="+expire+"&app=live&method=del&name=" + streamName;
100   - System.out.println("..url.."+url);
101   - String jsonArrStr = HttpReq.getRequestWidthResult(url);
102   - System.out.println("..jsonArrStr.."+jsonArrStr);
103   - /*Map map = JsonUtil.getMapFromJsonObjStr(jsonArrStr);
104   - String chatRoomid = (String) map.get("Content-Length");*/
105   - return jsonArrStr;
106   - }
107   -
108   -}