Commit 09df8605d20274eb53a7bbdc2e89f1984dfd6df4
1 parent
08199d34
check
Showing
2 changed files
with
75 additions
and
41 deletions
src/main/java/com/cnlive/mz/live/action/CheckAction.java
| @@ -50,15 +50,17 @@ public class CheckAction { | @@ -50,15 +50,17 @@ public class CheckAction { | ||
| 50 | public Result coseLive(int id,Params params) throws UnsupportedEncodingException{ | 50 | public Result coseLive(int id,Params params) throws UnsupportedEncodingException{ |
| 51 | String userId = params.getString("user_id"); | 51 | String userId = params.getString("user_id"); |
| 52 | String streamName = userId+"_"+id; | 52 | String streamName = userId+"_"+id; |
| 53 | - //String streamName = "498122_57"; | ||
| 54 | - String accesskey = "I3TC8a4xboPUMe5xlp22"; | ||
| 55 | - //accesskey = java.net.URLEncoder.encode(accesskey,"utf-8"); | 53 | + String accesskey = BaseUtil.getAccessKey(); |
| 54 | + accesskey = java.net.URLEncoder.encode(accesskey,"utf-8"); | ||
| 56 | String signature = BaseUtil.signature(streamName); | 55 | String signature = BaseUtil.signature(streamName); |
| 56 | + String del = "del"; | ||
| 57 | + String delsignature = BaseUtil.signature(del,streamName); | ||
| 57 | String expire = BaseUtil.getTimestamp(); | 58 | String expire = BaseUtil.getTimestamp(); |
| 58 | System.out.println(expire+"---expire---"); | 59 | System.out.println(expire+"---expire---"); |
| 59 | //添加到黑名单。。 | 60 | //添加到黑名单。。 |
| 60 | try { | 61 | try { |
| 61 | addBlackList(signature,accesskey,expire,streamName); | 62 | addBlackList(signature,accesskey,expire,streamName); |
| 63 | + delBlackList(delsignature,accesskey,expire,streamName); | ||
| 62 | } catch (UnsupportedEncodingException e) { | 64 | } catch (UnsupportedEncodingException e) { |
| 63 | e.printStackTrace(); | 65 | e.printStackTrace(); |
| 64 | } | 66 | } |
| @@ -75,7 +77,7 @@ public class CheckAction { | @@ -75,7 +77,7 @@ public class CheckAction { | ||
| 75 | * @throws UnsupportedEncodingException | 77 | * @throws UnsupportedEncodingException |
| 76 | */ | 78 | */ |
| 77 | public String addBlackList(String signature, String accesskey, String expire,String streamName) throws UnsupportedEncodingException { | 79 | public String addBlackList(String signature, String accesskey, String expire,String streamName) throws UnsupportedEncodingException { |
| 78 | - String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature="+signature+"&accesskey="+accesskey+"&expire="+expire+"&method=add&app=live&name="+streamName; | 80 | + String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature="+signature+"&accesskey="+accesskey+"&expire="+expire+"&app=live&method=add&name=" + streamName; |
| 79 | System.out.println(url); | 81 | System.out.println(url); |
| 80 | String jsonArrStr = HttpReq.getRequestWidthResult(url); | 82 | String jsonArrStr = HttpReq.getRequestWidthResult(url); |
| 81 | int status = HttpReq.getRequest(url); | 83 | int status = HttpReq.getRequest(url); |
| @@ -94,9 +96,10 @@ public class CheckAction { | @@ -94,9 +96,10 @@ public class CheckAction { | ||
| 94 | * @throws UnsupportedEncodingException | 96 | * @throws UnsupportedEncodingException |
| 95 | */ | 97 | */ |
| 96 | public Object delBlackList(String signature, String accesskey, String expire,String streamName) throws UnsupportedEncodingException { | 98 | public Object delBlackList(String signature, String accesskey, String expire,String streamName) throws UnsupportedEncodingException { |
| 97 | - String url = "http://cnlive.uplive.ks-cdn.com/blacklist?signature="+signature+"&accesskey="+accesskey+"&expire="+expire+"&method=del&app=live&name="+streamName; | 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); | ||
| 98 | String jsonArrStr = HttpReq.getRequestWidthResult(url); | 101 | String jsonArrStr = HttpReq.getRequestWidthResult(url); |
| 99 | - System.out.println(); | 102 | + System.out.println("..jsonArrStr.."+jsonArrStr); |
| 100 | /*Map map = JsonUtil.getMapFromJsonObjStr(jsonArrStr); | 103 | /*Map map = JsonUtil.getMapFromJsonObjStr(jsonArrStr); |
| 101 | String chatRoomid = (String) map.get("Content-Length");*/ | 104 | String chatRoomid = (String) map.get("Content-Length");*/ |
| 102 | return jsonArrStr; | 105 | return jsonArrStr; |
src/main/java/com/cnlive/mz/live/rest/BaseUtil.java
| @@ -21,14 +21,16 @@ import javax.crypto.spec.SecretKeySpec; | @@ -21,14 +21,16 @@ import javax.crypto.spec.SecretKeySpec; | ||
| 21 | 21 | ||
| 22 | import org.apache.commons.codec.binary.Base64; | 22 | import org.apache.commons.codec.binary.Base64; |
| 23 | 23 | ||
| 24 | +import com.cnlive.mz.commons.net.HttpReq; | ||
| 25 | + | ||
| 24 | import sun.misc.BASE64Encoder; | 26 | import sun.misc.BASE64Encoder; |
| 25 | 27 | ||
| 26 | public class BaseUtil { | 28 | public class BaseUtil { |
| 27 | 29 | ||
| 28 | private static final String ENCODING = "UTF-8"; | 30 | private static final String ENCODING = "UTF-8"; |
| 29 | // AccessKey、SecretKey | 31 | // AccessKey、SecretKey |
| 30 | - private static final String SECRET_KEY = "7SxVU5lFpqCEQIqxLprQat9BWoyZNKlKfSScTuIk"; | ||
| 31 | - private static final String ACCESS_KEY = "I3TC8a4xboPUMe5xlp22"; | 32 | + private static final String SECRET_KEY = "iqljE4WxQaSMeSd1QP+PPYSpvtK0uWyH0/r6tgi7"; |
| 33 | + private static final String ACCESS_KEY = "I3TC8a4xboN9kSJnUIQh"; | ||
| 32 | 34 | ||
| 33 | /* | 35 | /* |
| 34 | * 计算MD5+BASE64 | 36 | * 计算MD5+BASE64 |
| @@ -88,7 +90,9 @@ public class BaseUtil { | @@ -88,7 +90,9 @@ public class BaseUtil { | ||
| 88 | Calendar cal = Calendar.getInstance(); | 90 | Calendar cal = Calendar.getInstance(); |
| 89 | cal.setTime(date); | 91 | cal.setTime(date); |
| 90 | long timestamp = cal.getTimeInMillis(); | 92 | long timestamp = cal.getTimeInMillis(); |
| 91 | - return String.valueOf(timestamp).substring(0, 10); | 93 | + System.out.println("------timestamp-----"+timestamp); |
| 94 | + //return String.valueOf(timestamp).substring(0, 10); | ||
| 95 | + return "1483200000"; | ||
| 92 | } | 96 | } |
| 93 | 97 | ||
| 94 | /** | 98 | /** |
| @@ -101,24 +105,54 @@ public class BaseUtil { | @@ -101,24 +105,54 @@ public class BaseUtil { | ||
| 101 | public static String signature(String streamName) throws UnsupportedEncodingException { | 105 | public static String signature(String streamName) throws UnsupportedEncodingException { |
| 102 | 106 | ||
| 103 | String method = "GET"; | 107 | String method = "GET"; |
| 104 | - String Expire = BaseUtil.getTimestamp(); | ||
| 105 | - String nonce = getUUid(); | ||
| 106 | - System.out.println(Expire + "---expire----"); | ||
| 107 | - String Resource = "app=live&method=add&nonce=" + nonce + "&public=0&vdoid=12345&stream=" + streamName; | ||
| 108 | - Resource = java.net.URLEncoder.encode(Resource, "utf-8"); | ||
| 109 | - String stringToSign = method + "\n" + Expire + "\n" + Resource; | 108 | + String expire = BaseUtil.getTimestamp(); |
| 109 | + String app = "live"; | ||
| 110 | + String methodadd = "add"; | ||
| 111 | + String name = streamName; | ||
| 112 | + app = java.net.URLEncoder.encode(app, "utf-8"); | ||
| 113 | + methodadd = java.net.URLEncoder.encode(methodadd, "utf-8"); | ||
| 114 | + name = java.net.URLEncoder.encode(name, "utf-8"); | ||
| 115 | + System.out.println(expire + "---expire----"); | ||
| 116 | + String Resource = "app="+app+"&method="+methodadd+"&name=" + name; | ||
| 117 | + //Resource = java.net.URLEncoder.encode(Resource, "utf-8"); | ||
| 118 | + String stringToSign = method + "\n" + expire + "\n" + Resource; | ||
| 119 | + System.out.println("--stringToSign--"+stringToSign); | ||
| 110 | // 2.计算 HMAC-SHA1 | 120 | // 2.计算 HMAC-SHA1 |
| 111 | String signature = HMACSha1(stringToSign, SECRET_KEY); | 121 | String signature = HMACSha1(stringToSign, SECRET_KEY); |
| 112 | - System.out.println(signature + "---signature---"); | 122 | + System.out.println( "---signature---"+signature ); |
| 113 | signature = java.net.URLEncoder.encode(signature, "utf-8"); | 123 | signature = java.net.URLEncoder.encode(signature, "utf-8"); |
| 114 | return signature; | 124 | return signature; |
| 115 | } | 125 | } |
| 126 | + public static String signature(String methodNname,String streamName) throws UnsupportedEncodingException { | ||
| 116 | 127 | ||
| 128 | + String method = "GET"; | ||
| 129 | + String expire = BaseUtil.getTimestamp(); | ||
| 130 | + String app = "live"; | ||
| 131 | + //String methodadd = methodNname; | ||
| 132 | + //String name = streamName; | ||
| 133 | + app = java.net.URLEncoder.encode(app, "utf-8"); | ||
| 134 | + methodNname = java.net.URLEncoder.encode(methodNname, "utf-8"); | ||
| 135 | + streamName = java.net.URLEncoder.encode(streamName, "utf-8"); | ||
| 136 | + System.out.println(expire + "---expire----"); | ||
| 137 | + String Resource = "app="+app+"&method="+methodNname+"&name=" + streamName; | ||
| 138 | + //Resource = java.net.URLEncoder.encode(Resource, "utf-8"); | ||
| 139 | + String stringToSign = method + "\n" + expire + "\n" + Resource; | ||
| 140 | + System.out.println("--stringToSign--"+stringToSign); | ||
| 141 | + // 2.计算 HMAC-SHA1 | ||
| 142 | + String signature = HMACSha1(stringToSign, SECRET_KEY); | ||
| 143 | + System.out.println( "---signature---"+signature ); | ||
| 144 | + signature = java.net.URLEncoder.encode(signature, "utf-8"); | ||
| 145 | + return signature; | ||
| 146 | + } | ||
| 147 | + | ||
| 117 | public static String getUUid() { | 148 | public static String getUUid() { |
| 118 | String uuid = UUID.randomUUID().toString(); | 149 | String uuid = UUID.randomUUID().toString(); |
| 119 | uuid = uuid.replaceAll("-", ""); | 150 | uuid = uuid.replaceAll("-", ""); |
| 120 | return uuid; | 151 | return uuid; |
| 121 | } | 152 | } |
| 153 | + public static String getAccessKey() { | ||
| 154 | + return ACCESS_KEY; | ||
| 155 | + } | ||
| 122 | 156 | ||
| 123 | public static int random_7(int number) { | 157 | public static int random_7(int number) { |
| 124 | int x = (int) (Math.random() * 10); | 158 | int x = (int) (Math.random() * 10); |
| @@ -218,26 +252,26 @@ public class BaseUtil { | @@ -218,26 +252,26 @@ public class BaseUtil { | ||
| 218 | /* | 252 | /* |
| 219 | * http header 参数 | 253 | * http header 参数 |
| 220 | */ | 254 | */ |
| 221 | - String method = "GET"; | ||
| 222 | - String Expire = "1436976000"; | ||
| 223 | - String Resource = "nonce=4e1f2519c626cbfbab1520c255830c26&public=0&vdoid=12345"; | ||
| 224 | - String content_type = "application/json"; | ||
| 225 | - String path = realUrl.getFile(); | ||
| 226 | - String date = toGMTString(new Date()); | ||
| 227 | - // 1.对body做MD5+BASE64加密 | ||
| 228 | - // String bodyMd5 = MD5Base64(body); | ||
| 229 | - String stringToSign = method + "\n" + Expire + "\n" + Resource; | ||
| 230 | - // 2.计算 HMAC-SHA1 | ||
| 231 | - String signature = HMACSha1(stringToSign, ak_secret); | ||
| 232 | - // 3.得到 authorization header | ||
| 233 | - String authHeader = "Dataplus " + ak_id + ":" + signature; | 255 | +// String method = "GET"; |
| 256 | +// String Expire = "1436976000"; | ||
| 257 | +// String Resource = "nonce=4e1f2519c626cbfbab1520c255830c26&public=0&vdoid=12345"; | ||
| 258 | +// String content_type = "application/json"; | ||
| 259 | +// String path = realUrl.getFile(); | ||
| 260 | +// String date = toGMTString(new Date()); | ||
| 261 | +// // 1.对body做MD5+BASE64加密 | ||
| 262 | +// // String bodyMd5 = MD5Base64(body); | ||
| 263 | +// String stringToSign = method + "\n" + Expire + "\n" + Resource; | ||
| 264 | +// // 2.计算 HMAC-SHA1 | ||
| 265 | +// String signature = HMACSha1(stringToSign, ak_secret); | ||
| 266 | +// // 3.得到 authorization header | ||
| 267 | +// String authHeader = "Dataplus " + ak_id + ":" + signature; | ||
| 234 | // 打开和URL之间的连接 | 268 | // 打开和URL之间的连接 |
| 235 | URLConnection connection = realUrl.openConnection(); | 269 | URLConnection connection = realUrl.openConnection(); |
| 236 | // 设置通用的请求属性 | 270 | // 设置通用的请求属性 |
| 237 | - connection.setRequestProperty("accept", "json"); | ||
| 238 | - connection.setRequestProperty("content-type", content_type); | ||
| 239 | - connection.setRequestProperty("date", date); | ||
| 240 | - connection.setRequestProperty("Authorization", authHeader); | 271 | +// connection.setRequestProperty("accept", "json"); |
| 272 | +// connection.setRequestProperty("content-type", content_type); | ||
| 273 | +// connection.setRequestProperty("date", date); | ||
| 274 | +// connection.setRequestProperty("Authorization", authHeader); | ||
| 241 | // 建立实际的连接 | 275 | // 建立实际的连接 |
| 242 | connection.connect(); | 276 | connection.connect(); |
| 243 | // 定义 BufferedReader输入流来读取URL的响应 | 277 | // 定义 BufferedReader输入流来读取URL的响应 |
| @@ -283,14 +317,11 @@ public class BaseUtil { | @@ -283,14 +317,11 @@ public class BaseUtil { | ||
| 283 | System.out.println(".............."); | 317 | System.out.println(".............."); |
| 284 | // String str = signature(); | 318 | // String str = signature(); |
| 285 | // System.out.println(str);//L2muBoImPzyvwyzfBtGXEu+wRNE= | 319 | // System.out.println(str);//L2muBoImPzyvwyzfBtGXEu+wRNE= |
| 286 | - /* | ||
| 287 | - * // 发送GET请求 String ak_id1 = "fWUN8KDtJZJGo0ArQ4qo"; //用户ak String | ||
| 288 | - * ak_secret1 = "UIWPYVeaV8kq2vWImDkLBvWs/pwmTJVF9MCNHDsC"; // | ||
| 289 | - * 用户ak_secret String url1 = | ||
| 290 | - * "http://cnlive.uplive.ks-cdn.com?signature=L2muBoImPzyvwyzfBtGXEu+wRNE=&accesskey=fWUN8KDtJZJGo0ArQ4qo&expire=1436976000&method=add&app=live&name=498122_57"; | ||
| 291 | - * System.out.println("response body:" +sendGet(url1, ak_id1, | ||
| 292 | - * ak_secret1)); | ||
| 293 | - */ | 320 | + |
| 321 | + // 发送GET请求 | ||
| 322 | + String url1 = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature=iDPKaesXXW3A26CScNyjpNkzxZs%3D&accesskey=I3TC8a4xboPUMe5xlp22&expire=1483200000&app=live&method=add&stream=310166_863"; | ||
| 323 | + System.out.println("response body:" +sendGet(url1, ACCESS_KEY, SECRET_KEY)); | ||
| 324 | + | ||
| 294 | // long d = getTimestamp(); | 325 | // long d = getTimestamp(); |
| 295 | // System.out.println(d); | 326 | // System.out.println(d); |
| 296 | } | 327 | } |