Commit bead184f058c212fb0bacdff849dce545d0fb2a6
1 parent
ba62db80
回调修改
Showing
5 changed files
with
110 additions
and
21 deletions
src/main/java/com/cnlive/shenhe/api/CommentsControllerApi.java
| ... | ... | @@ -14,7 +14,6 @@ import org.slf4j.LoggerFactory; |
| 14 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | 15 | import org.springframework.stereotype.Controller; |
| 16 | 16 | import org.springframework.web.bind.annotation.PostMapping; |
| 17 | -import org.springframework.web.bind.annotation.RequestBody; | |
| 18 | 17 | import org.springframework.web.bind.annotation.RequestMapping; |
| 19 | 18 | import org.springframework.web.bind.annotation.ResponseBody; |
| 20 | 19 | |
| ... | ... | @@ -38,7 +37,7 @@ public class CommentsControllerApi { |
| 38 | 37 | @PostMapping("/import") |
| 39 | 38 | @ResponseBody |
| 40 | 39 | public ResponseBean impotComment(String param) { |
| 41 | - logger.info("评论入库,param====="+param); | |
| 40 | + logger.info("评论入库,param=====" + param); | |
| 42 | 41 | JSONObject json = JSONObject.parseObject(param); |
| 43 | 42 | ShyComments shyComments = new ShyComments(); |
| 44 | 43 | ShySites shySites = new ShySites(); |
| ... | ... | @@ -61,13 +60,15 @@ public class CommentsControllerApi { |
| 61 | 60 | json1.put("attr_tags", ""); |
| 62 | 61 | json1.put("msg", ""); |
| 63 | 62 | JSONObject result = new JSONObject(); |
| 64 | - try{ | |
| 65 | - result = Pass.commentPass(json1,callback); | |
| 66 | - }catch (Exception e){ | |
| 63 | + try { | |
| 64 | + result = Pass.commentPass(json1, callback); | |
| 65 | + } catch (Exception e) { | |
| 66 | + logger.error("评论回调失败,activity_id:{}", json.getString("activityId")); | |
| 67 | 67 | return new ResponseBean(ErrorEnum.BACK_ERROR); |
| 68 | 68 | } |
| 69 | 69 | Integer code = result.getInteger("errorCode"); |
| 70 | 70 | if (code != 0) { |
| 71 | + logger.error("评论回调错误,activity_id:{},code:{},errorMessage:{}", json.getString("activityId"), code, result.getString("errorMessage")); | |
| 71 | 72 | return new ResponseBean(code, result.getString("errorMessage")); |
| 72 | 73 | } |
| 73 | 74 | shyComments.setState(CommonConst.AUDIT_SUCCESS); | ... | ... |
src/main/java/com/cnlive/shenhe/api/VideosControllerApi.java
| ... | ... | @@ -40,7 +40,7 @@ public class VideosControllerApi { |
| 40 | 40 | @PostMapping("/import") |
| 41 | 41 | @ResponseBody |
| 42 | 42 | public ResponseBean impotVideo(String param) { |
| 43 | - logger.info("点播入库,param====="+param); | |
| 43 | + logger.info("点播入库,param=====" + param); | |
| 44 | 44 | JSONObject json = JSONObject.parseObject(param); |
| 45 | 45 | ShySites shySites = new ShySites(); |
| 46 | 46 | ShyVideos shyVideos = new ShyVideos(); |
| ... | ... | @@ -56,15 +56,17 @@ public class VideosControllerApi { |
| 56 | 56 | String[] business = write_business.split(","); |
| 57 | 57 | List<String> asList = Arrays.asList(business); |
| 58 | 58 | if (asList.contains(CommonConst.BUSINESS_VIDEO + "")) { |
| 59 | - logger.info("白名单回调通过:videoId==="+videoId); | |
| 59 | + logger.info("白名单回调通过:videoId===" + videoId); | |
| 60 | 60 | JSONObject result = new JSONObject(); |
| 61 | - try{ | |
| 62 | - result = Pass.auditPass(videoId, 3, "", "",callback); | |
| 63 | - }catch (Exception e){ | |
| 61 | + try { | |
| 62 | + result = Pass.auditPass(videoId, 3, "", "", callback); | |
| 63 | + } catch (Exception e) { | |
| 64 | + logger.error("点播回调失败,videoId:{}", videoId); | |
| 64 | 65 | return new ResponseBean(ErrorEnum.BACK_ERROR); |
| 65 | 66 | } |
| 66 | 67 | Integer code = result.getInteger("code"); |
| 67 | 68 | if (code != 0) { |
| 69 | + logger.error("点播回调错误,videoId:{},code:{},msg:{}", videoId, code, result.getString("msg")); | |
| 68 | 70 | return new ResponseBean(code, result.getString("msg")); |
| 69 | 71 | } |
| 70 | 72 | shyVideos.setState(CommonConst.AUDIT_SUCCESS); |
| ... | ... | @@ -77,7 +79,7 @@ public class VideosControllerApi { |
| 77 | 79 | shyVideos.setVideo_url(json.getString("videoUrl")); |
| 78 | 80 | String videoCoverUrl = json.getString("videoCoverUrl"); |
| 79 | 81 | shyVideos.setVideo_imgs(videoCoverUrl); |
| 80 | - if(CommonUtils.isNotEmpty(videoCoverUrl)){ | |
| 82 | + if (CommonUtils.isNotEmpty(videoCoverUrl)) { | |
| 81 | 83 | String poster = json.getJSONObject("videoCoverUrl").getString("224*126"); |
| 82 | 84 | shyVideos.setVideo_poster(poster); |
| 83 | 85 | } | ... | ... |
src/main/java/com/cnlive/shenhe/serviceImpl/CommentsServiceImpl.java
| ... | ... | @@ -131,7 +131,7 @@ public class CommentsServiceImpl { |
| 131 | 131 | } |
| 132 | 132 | Integer code = result.getInteger("errorCode"); |
| 133 | 133 | if (code != 0) { |
| 134 | - logger.error("评论回调失败,activity_id:{},errorCode:{},errorMessage:{}", comment.getActivity_id(), code, result.getString("errorMessage")); | |
| 134 | + logger.error("评论回调错误,activity_id:{},errorCode:{},errorMessage:{}", comment.getActivity_id(), code, result.getString("errorMessage")); | |
| 135 | 135 | success = false; |
| 136 | 136 | break; |
| 137 | 137 | } | ... | ... |
src/main/java/com/cnlive/shenhe/utils/AuditPass.java
| ... | ... | @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; |
| 6 | 6 | import org.springframework.beans.factory.annotation.Value; |
| 7 | 7 | import org.springframework.stereotype.Component; |
| 8 | 8 | |
| 9 | +import java.util.HashMap; | |
| 9 | 10 | import java.util.Map; |
| 10 | 11 | |
| 11 | 12 | /** |
| ... | ... | @@ -38,7 +39,6 @@ public class AuditPass { |
| 38 | 39 | params.put("attr_tags",attr_tags); |
| 39 | 40 | params.put("msg",msg); |
| 40 | 41 | HttpUtil httpUtil = HttpUtil.init(); |
| 41 | - httpUtil.setHeader("Content-Type","x-www-form-urlencoded;charset=UTF-8"); | |
| 42 | 42 | httpUtil.setParam("param",params.toJSONString()); |
| 43 | 43 | String URL =callBack+"?platform="+platformKey+"&token="+token; |
| 44 | 44 | Map<String, String> post = httpUtil.post(URL); |
| ... | ... | @@ -46,10 +46,9 @@ public class AuditPass { |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | public JSONObject commentPass(JSONObject json,String callBack){ |
| 49 | - HttpUtil httpUtil = HttpUtil.init(); | |
| 50 | - httpUtil.setHeader("Content-Type","x-www-form-urlencoded;charset=UTF-8"); | |
| 51 | - httpUtil.setParam("param",json.toJSONString()); | |
| 52 | - Map<String, String> post = httpUtil.post(callBack); | |
| 53 | - return JSONObject.parseObject(post.get("result")); | |
| 49 | + Map<String, String> map = new HashMap<>(); | |
| 50 | + map.put("param",json.toJSONString()); | |
| 51 | + String result = HttpUtil.form(callBack, map); | |
| 52 | + return JSONObject.parseObject(result); | |
| 54 | 53 | } |
| 55 | 54 | } | ... | ... |
src/main/java/com/cnlive/shenhe/utils/HttpUtil.java
| 1 | 1 | package com.cnlive.shenhe.utils; |
| 2 | 2 | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 3 | 4 | import org.apache.http.Header; |
| 4 | 5 | import org.apache.http.HttpEntity; |
| 5 | 6 | import org.apache.http.HttpStatus; |
| ... | ... | @@ -31,11 +32,11 @@ import org.slf4j.LoggerFactory; |
| 31 | 32 | import org.springframework.util.CollectionUtils; |
| 32 | 33 | import org.springframework.util.StringUtils; |
| 33 | 34 | |
| 34 | -import java.io.File; | |
| 35 | -import java.io.InputStream; | |
| 36 | -import java.io.UnsupportedEncodingException; | |
| 35 | +import java.io.*; | |
| 36 | +import java.net.HttpURLConnection; | |
| 37 | 37 | import java.net.URI; |
| 38 | 38 | import java.net.URISyntaxException; |
| 39 | +import java.net.URL; | |
| 39 | 40 | import java.nio.charset.UnsupportedCharsetException; |
| 40 | 41 | import java.util.ArrayList; |
| 41 | 42 | import java.util.HashMap; |
| ... | ... | @@ -398,4 +399,90 @@ public class HttpUtil { |
| 398 | 399 | } |
| 399 | 400 | return uri; |
| 400 | 401 | } |
| 402 | + | |
| 403 | + | |
| 404 | + /** | |
| 405 | + * from请求 | |
| 406 | + * @param url | |
| 407 | + * @param params | |
| 408 | + * @return | |
| 409 | + */ | |
| 410 | + public static String form(String url, Map<String, String> params) { | |
| 411 | + URL u = null; | |
| 412 | + HttpURLConnection con = null; | |
| 413 | + // 构建请求参数 | |
| 414 | + StringBuffer sb = new StringBuffer(); | |
| 415 | + if (params != null) { | |
| 416 | + for (Entry<String, String> e : params.entrySet()) { | |
| 417 | + sb.append(e.getKey()); | |
| 418 | + sb.append("="); | |
| 419 | + sb.append(e.getValue()); | |
| 420 | + sb.append("&"); | |
| 421 | + } | |
| 422 | + sb.substring(0, sb.length() - 1); | |
| 423 | + } | |
| 424 | + // 尝试发送请求 | |
| 425 | + try { | |
| 426 | + u = new URL(url); | |
| 427 | + con = (HttpURLConnection) u.openConnection(); | |
| 428 | + //// POST 只能为大写,严格限制,post会不识别 | |
| 429 | + con.setRequestMethod("POST"); | |
| 430 | + con.setDoOutput(true); | |
| 431 | + con.setDoInput(true); | |
| 432 | + con.setUseCaches(false); | |
| 433 | + con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); | |
| 434 | + OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream(), "UTF-8"); | |
| 435 | + osw.write(sb.toString()); | |
| 436 | + osw.flush(); | |
| 437 | + osw.close(); | |
| 438 | + } catch (Exception e) { | |
| 439 | + e.printStackTrace(); | |
| 440 | + } finally { | |
| 441 | + if (con != null) { | |
| 442 | + con.disconnect(); | |
| 443 | + } | |
| 444 | + } | |
| 445 | + | |
| 446 | + // 读取返回内容 | |
| 447 | + StringBuffer buffer = new StringBuffer(); | |
| 448 | + try { | |
| 449 | + //一定要有返回值,否则无法把请求发送给server端。 | |
| 450 | + BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8")); | |
| 451 | + String temp; | |
| 452 | + while ((temp = br.readLine()) != null) { | |
| 453 | + buffer.append(temp); | |
| 454 | + buffer.append("\n"); | |
| 455 | + } | |
| 456 | + } catch (Exception e) { | |
| 457 | + e.printStackTrace(); | |
| 458 | + } | |
| 459 | + | |
| 460 | + return buffer.toString(); | |
| 461 | + } | |
| 462 | + | |
| 463 | + | |
| 464 | + public static void main(String[] args) { | |
| 465 | + /*Map<String, String> map = new HashMap<>(); | |
| 466 | + JSONObject param = new JSONObject(); | |
| 467 | + param.put("activity_id","60:video:comets:10011#2"); | |
| 468 | + param.put("state",3); | |
| 469 | + param.put("attr_tags",""); | |
| 470 | + param.put("msg",""); | |
| 471 | + | |
| 472 | + map.put("param",param.toJSONString()); | |
| 473 | + String form = form("http://yp5ntd.natappfree.cc/CnInteraction/services/commentForHd/auditCallBackNew", map); | |
| 474 | + System.out.println(form);*/ | |
| 475 | + | |
| 476 | + | |
| 477 | + JSONObject params = new JSONObject(); | |
| 478 | + params.put("video_id","60_8be004799c424688949704814ea0d16d"); | |
| 479 | + params.put("state",3+""); | |
| 480 | + params.put("attr_tags",""); | |
| 481 | + params.put("msg",""); | |
| 482 | + HttpUtil httpUtil = HttpUtil.init(); | |
| 483 | + httpUtil.setParam("param",params.toJSONString()); | |
| 484 | + String URL ="http://mam.innerapi.cnlive.com/v1/inner/ShenHeInfo/shenheNotify?platform=AUDIT&token=2718c88930175686e40398994cead75c"; | |
| 485 | + Map<String, String> post = httpUtil.post(URL); | |
| 486 | + System.out.println(post.get("result")); | |
| 487 | + } | |
| 401 | 488 | } | ... | ... |