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 | 50 | public Result coseLive(int id,Params params) throws UnsupportedEncodingException{ |
| 51 | 51 | String userId = params.getString("user_id"); |
| 52 | 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 | 55 | String signature = BaseUtil.signature(streamName); |
| 56 | + String del = "del"; | |
| 57 | + String delsignature = BaseUtil.signature(del,streamName); | |
| 57 | 58 | String expire = BaseUtil.getTimestamp(); |
| 58 | 59 | System.out.println(expire+"---expire---"); |
| 59 | 60 | //添加到黑名单。。 |
| 60 | 61 | try { |
| 61 | 62 | addBlackList(signature,accesskey,expire,streamName); |
| 63 | + delBlackList(delsignature,accesskey,expire,streamName); | |
| 62 | 64 | } catch (UnsupportedEncodingException e) { |
| 63 | 65 | e.printStackTrace(); |
| 64 | 66 | } |
| ... | ... | @@ -75,7 +77,7 @@ public class CheckAction { |
| 75 | 77 | * @throws UnsupportedEncodingException |
| 76 | 78 | */ |
| 77 | 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 | 81 | System.out.println(url); |
| 80 | 82 | String jsonArrStr = HttpReq.getRequestWidthResult(url); |
| 81 | 83 | int status = HttpReq.getRequest(url); |
| ... | ... | @@ -94,9 +96,10 @@ public class CheckAction { |
| 94 | 96 | * @throws UnsupportedEncodingException |
| 95 | 97 | */ |
| 96 | 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 | 101 | String jsonArrStr = HttpReq.getRequestWidthResult(url); |
| 99 | - System.out.println(); | |
| 102 | + System.out.println("..jsonArrStr.."+jsonArrStr); | |
| 100 | 103 | /*Map map = JsonUtil.getMapFromJsonObjStr(jsonArrStr); |
| 101 | 104 | String chatRoomid = (String) map.get("Content-Length");*/ |
| 102 | 105 | return jsonArrStr; | ... | ... |
src/main/java/com/cnlive/mz/live/rest/BaseUtil.java
| ... | ... | @@ -21,14 +21,16 @@ import javax.crypto.spec.SecretKeySpec; |
| 21 | 21 | |
| 22 | 22 | import org.apache.commons.codec.binary.Base64; |
| 23 | 23 | |
| 24 | +import com.cnlive.mz.commons.net.HttpReq; | |
| 25 | + | |
| 24 | 26 | import sun.misc.BASE64Encoder; |
| 25 | 27 | |
| 26 | 28 | public class BaseUtil { |
| 27 | 29 | |
| 28 | 30 | private static final String ENCODING = "UTF-8"; |
| 29 | 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 | 36 | * 计算MD5+BASE64 |
| ... | ... | @@ -88,7 +90,9 @@ public class BaseUtil { |
| 88 | 90 | Calendar cal = Calendar.getInstance(); |
| 89 | 91 | cal.setTime(date); |
| 90 | 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 | 105 | public static String signature(String streamName) throws UnsupportedEncodingException { |
| 102 | 106 | |
| 103 | 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 | 120 | // 2.计算 HMAC-SHA1 |
| 111 | 121 | String signature = HMACSha1(stringToSign, SECRET_KEY); |
| 112 | - System.out.println(signature + "---signature---"); | |
| 122 | + System.out.println( "---signature---"+signature ); | |
| 113 | 123 | signature = java.net.URLEncoder.encode(signature, "utf-8"); |
| 114 | 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 | 148 | public static String getUUid() { |
| 118 | 149 | String uuid = UUID.randomUUID().toString(); |
| 119 | 150 | uuid = uuid.replaceAll("-", ""); |
| 120 | 151 | return uuid; |
| 121 | 152 | } |
| 153 | + public static String getAccessKey() { | |
| 154 | + return ACCESS_KEY; | |
| 155 | + } | |
| 122 | 156 | |
| 123 | 157 | public static int random_7(int number) { |
| 124 | 158 | int x = (int) (Math.random() * 10); |
| ... | ... | @@ -218,26 +252,26 @@ public class BaseUtil { |
| 218 | 252 | /* |
| 219 | 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 | 268 | // 打开和URL之间的连接 |
| 235 | 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 | 276 | connection.connect(); |
| 243 | 277 | // 定义 BufferedReader输入流来读取URL的响应 |
| ... | ... | @@ -283,14 +317,11 @@ public class BaseUtil { |
| 283 | 317 | System.out.println(".............."); |
| 284 | 318 | // String str = signature(); |
| 285 | 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 | 325 | // long d = getTimestamp(); |
| 295 | 326 | // System.out.println(d); |
| 296 | 327 | } | ... | ... |