Commit 1226c53e18c63701c119d1f831bf96ae28b4252b

Authored by 周伟鹏
1 parent 883d34b0

回调错误处理

src/main/java/com/cnlive/shenhe/api/CommentsControllerApi.java
... ... @@ -37,9 +37,9 @@ public class CommentsControllerApi {
37 37 */
38 38 @PostMapping("/import")
39 39 @ResponseBody
40   - public ResponseBean impotComment(@RequestBody JSONObject param) {
41   - logger.info("评论入库,param====="+param.toJSONString());
42   - JSONObject json = param.getJSONObject("param");
  40 + public ResponseBean impotComment(String param) {
  41 + logger.info("评论入库,param====="+param);
  42 + JSONObject json = JSONObject.parseObject(param);
43 43 ShyComments shyComments = new ShyComments();
44 44 ShySites shySites = new ShySites();
45 45 shyComments.setState(CommonConst.AUDIT_INTT);
... ... @@ -59,7 +59,12 @@ public class CommentsControllerApi {
59 59 json1.put("state", 3);
60 60 json1.put("attr_tags", "");
61 61 json1.put("msg", "");
62   - JSONObject result = Pass.commentPass(json1);
  62 + JSONObject result = new JSONObject();
  63 + try{
  64 + result = Pass.commentPass(json1);
  65 + }catch (Exception e){
  66 + return new ResponseBean(ErrorEnum.BACK_ERROR);
  67 + }
63 68 Integer code = result.getInteger("errorCode");
64 69 if (code != 0) {
65 70 return new ResponseBean(code, result.getString("errorMessage"));
... ...
src/main/java/com/cnlive/shenhe/api/VideosControllerApi.java
... ... @@ -56,7 +56,12 @@ public class VideosControllerApi {
56 56 List<String> asList = Arrays.asList(business);
57 57 if (asList.contains(CommonConst.BUSINESS_VIDEO + "")) {
58 58 logger.info("白名单回调通过:videoId==="+videoId);
59   - JSONObject result = Pass.auditPass(videoId, 3, "", "");
  59 + JSONObject result = new JSONObject();
  60 + try{
  61 + result = Pass.auditPass(videoId, 3, "", "");
  62 + }catch (Exception e){
  63 + return new ResponseBean(ErrorEnum.BACK_ERROR);
  64 + }
60 65 Integer code = result.getInteger("code");
61 66 if (code != 0) {
62 67 return new ResponseBean(code, result.getString("msg"));
... ...
src/main/java/com/cnlive/shenhe/bean/ErrorEnum.java
... ... @@ -7,7 +7,8 @@ public enum ErrorEnum {
7 7 ERROR(500, "服务异常"),
8 8 RECORD_NOT_EXIST(10001, "记录不存在"),
9 9 PARAM_ERROR(10002, "参数错误"),
10   - NOT_LOGIN(4000, "登录失效或未登录"),
  10 + BACK_ERROR(10003, "回调请求失败"),
  11 + NOT_LOGIN(40000, "登录失效或未登录"),
11 12 ACCESS_DENIED(40001, "没有权限");
12 13  
13 14  
... ...
src/main/java/com/cnlive/shenhe/serviceImpl/CommentsServiceImpl.java
... ... @@ -7,9 +7,12 @@ import com.cnlive.shenhe.entity.ShyUsers;
7 7 import com.cnlive.shenhe.mapper.ShyCommentsMapper;
8 8 import com.cnlive.shenhe.mapper.ShySitesMapper;
9 9 import com.cnlive.shenhe.mapper.ShyUsersMapper;
  10 +import com.cnlive.shenhe.utils.AuditPass;
10 11 import com.cnlive.shenhe.utils.CommonUtils;
11 12 import com.github.pagehelper.PageHelper;
12 13 import com.github.pagehelper.PageInfo;
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
13 16 import org.springframework.beans.factory.annotation.Autowired;
14 17 import org.springframework.stereotype.Service;
15 18 import tk.mybatis.mapper.entity.Example;
... ... @@ -24,13 +27,16 @@ import java.util.List;
24 27 */
25 28 @Service
26 29 public class CommentsServiceImpl {
  30 +
  31 + private static Logger logger = LoggerFactory.getLogger(CommentsServiceImpl.class);
27 32 @Autowired
28 33 ShyCommentsMapper shyCommentsMapper;
29 34 @Autowired
30 35 ShySitesMapper shySitesMapper;
31 36 @Autowired
32 37 ShyUsersMapper shyUsersMapper;
33   -
  38 + @Autowired
  39 + AuditPass Pass;
34 40  
35 41 public List<ShySites> getBusiness(ShySites shySites) {
36 42 List<ShySites> sitesList = shySitesMapper.select(shySites);
... ... @@ -110,6 +116,25 @@ public class CommentsServiceImpl {
110 116 String[] commentIds = ids.split(",");
111 117 for (String commentId : commentIds) {
112 118 ShyComments comment = shyCommentsMapper.selectByPrimaryKey(Integer.parseInt(commentId));
  119 + JSONObject json = new JSONObject();
  120 + json.put("activity_id", comment.getActivity_id());
  121 + json.put("state", state + 2);
  122 + json.put("attr_tags", "");
  123 + json.put("msg", "");
  124 + JSONObject result = new JSONObject();
  125 + try {
  126 + result = Pass.commentPass(json);
  127 + } catch (Exception e) {
  128 + logger.error("评论回调失败,activity_id:{}", comment.getActivity_id());
  129 + success = false;
  130 + break;
  131 + }
  132 + Integer code = result.getInteger("errorCode");
  133 + if (code != 0) {
  134 + logger.error("评论回调失败,activity_id:{},errorCode:{},errorMessage:{}", comment.getActivity_id(), code, result.getString("errorMessage"));
  135 + success = false;
  136 + break;
  137 + }
113 138 comment.setState(state);
114 139 comment.setAuditor_id(userId);
115 140 int i = shyCommentsMapper.updateByPrimaryKeySelective(comment);
... ...
src/main/java/com/cnlive/shenhe/utils/AuditPass.java
... ... @@ -27,7 +27,8 @@ public class AuditPass {
27 27 private String platformValue;//点播platformValue
28 28 @Value("${commenturl}")
29 29 private String commentUrl;
30   -
  30 + @Value("${token}")
  31 + private String token;
31 32 /**
32 33 * 点播视频回调
33 34 * @param video_id
... ... @@ -38,14 +39,6 @@ public class AuditPass {
38 39 */
39 40 public JSONObject auditPass(String video_id,int state,String attr_tags,String msg){
40 41 logger.info("点播回调:video_id:{},state:{},attr_tags:{},msg:{}",video_id,state,attr_tags,msg);
41   - String token = null;
42   - try {
43   - token = CommonUtils.md5(url+platformKey+platformValue);
44   - } catch (NoSuchAlgorithmException e) {
45   - e.printStackTrace();
46   - } catch (UnsupportedEncodingException e) {
47   - e.printStackTrace();
48   - }
49 42 Map<String, String> paramsMap = new HashMap<>();
50 43 JSONObject params = new JSONObject();
51 44 params.put("video_id",video_id);
... ...
src/main/resources/application.properties
... ... @@ -24,6 +24,7 @@ sync_users_app_key=314a9dd4-a9b7-4c12-bbbe-1150a36491ae
24 24 url=http://mam.innerapi.cnlive.com/v1/inner/ShenHeInfo/shenheNotify
25 25 platformKey =AUDIT
26 26 platformValue=10011438
  27 +token=2718c88930175686e40398994cead75c
27 28  
28 29 #ÆÀÂۻص÷µØÖ·
29 30 commenturl=http://comment.cnlive.com/services/commentForHd/auditCallBack
30 31 \ No newline at end of file
... ...