AuditPass.java 9.09 KB
package com.cnlive.shenhe.utils;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: chenhao
 * @Date: 2018/12/3 16:00
 * @Description:如果是白名单直接审核通过
 */
@Component
public class AuditPass {
    private static Logger logger = LoggerFactory.getLogger(AuditPass.class);
    @Value("${platformKey}")
    private String platformKey;//点播platformKey
    @Value("${platformValue}")
    private String platformValue;//点播platformValue
    @Value("${live_url}")
    private String live_url;//直播同步信息
    
    @Value("${queryUserByMobile}")
    private String queryUserByMobile;//用户云查网家家用户信息(通过手机号)
    
    @Value("${queryUserByUserId}")
    private String queryUserByUserId;//用户云查网家家用户信息(通过用户id)
    
    public static void main(String[] args) {
    	JSONObject map= new JSONObject();
    	map.put("platform","a" );
    	map.put("commentUserAvatar","http://yweb0.cnliveimg.com/images/headImg/2019/1129/1575022593286.jpg" );
    	map.put("appId","60#iqw7flx829" );
    	map.put("commentUserIP", null);
    	map.put("type", "topic");
    	map.put("activityId", "802:video:comets:604_ab79303bd0074a24965a92dd6514681a#20939");
    	HttpUtil httpUtil = HttpUtil.init();
    	httpUtil.setParam("param", map.toJSONString());
    	Map<String, String> post = httpUtil.post("http://test.shen.cnlive.com/api/comments/import");
    }

    /**
     * 点播视频回调
     *
     * @param video_id
     * @param state
     * @param attr_tags
     * @param msg
     * @return
     */
    public JSONObject auditPass(String video_id, int state, String attr_tags, String msg, String callBack) {
        logger.info("点播回调:video_id:{},state:{},attr_tags:{},msg:{}", video_id, state, attr_tags, msg);
        JSONObject params = new JSONObject();
        params.put("video_id", video_id);
        params.put("state", state + "");
        params.put("attr_tags", attr_tags);
        params.put("msg", msg);
        HttpUtil httpUtil = HttpUtil.init();
        httpUtil.setParam("param", params.toJSONString());
        String token = "";
        try {
            String cb = callBack.replace("//", "");
            cb = cb.substring(cb.indexOf("/"));
            token = CommonUtils.md5(cb + platformKey + platformValue);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String URL = callBack + "?platform=" + platformKey + "&token=" + token;
        Map<String, String> post = httpUtil.post(URL);
        logger.info("点播回调结果:{}",post.get("result"));
        return JSONObject.parseObject(post.get("result"));
    }
    /**
     * 直播视频回调
     *
     * @param activity_id
     * @param state
     * @param attr_tags
     * @param msg
     * @return
     */
    public JSONObject livePass(String activity_id, int state, String attr_tags, String msg, String callBack) {
    	logger.info("直播回调:id:{},state:{},attr_tags:{},exceptionMessage:{}", activity_id, state, attr_tags, msg);
    	JSONObject params = new JSONObject();
    	params.put("id", activity_id);
    	params.put("state", state);
    	params.put("attr_tags", attr_tags);
    	params.put("exceptionMessage", msg);
    	HttpUtil httpUtil = HttpUtil.init();
    	httpUtil.setParam("param", params.toJSONString());
    	Map<String, String> post = httpUtil.post(callBack);
		String result = post.get("result");
		logger.info("直播回调result:{}",result);
		return JSONObject.parseObject(post.get("result"));
    }
    
    /**
     * 直播视频回调
     *
     * @param activity_id
     * @param state
     * @param attr_tags
     * @param msg
     * @return
     */
    public JSONObject liveApplyPass(String activity_id, int state, String attr_tags, String msg, String callBack) {
    	logger.info("直播申请回调:id:{},state:{},attr_tags:{},exceptionMessage:{}", activity_id, state, attr_tags, msg);
    	JSONObject params = new JSONObject();
    	params.put("id", activity_id);
    	params.put("state", state);
    	params.put("attr_tags", attr_tags);
    	params.put("exceptionMessage", msg);
    	HttpUtil httpUtil = HttpUtil.init();
    	httpUtil.setParam("param", params.toJSONString());
    	Map<String, String> post = httpUtil.post(callBack);
    	return JSONObject.parseObject(post.get("result"));
    }
    
    /**
    * 直播云信息同步
    * @param json
    * @param callBack
    * @return
    */
   public JSONObject syncLive(String activity_id) {
   	logger.info("直播云信息同步:activity_id:{}", activity_id);
   	HttpUtil httpUtil = HttpUtil.init();
	httpUtil.setParam("activityId", activity_id);
	Map<String, String> post = httpUtil.post(live_url);
	return JSONObject.parseObject(post.get("result"));
   }

    /**
     * 评论审核回调
     * @param json
     * @param callBack
     * @return
     */
    public JSONObject commentPass(JSONObject json, String callBack) {
    	logger.info("评论审核回调:param:{}", json);
        Map<String, String> map = new HashMap<>();
        map.put("param", json.toJSONString());
        String result = HttpUtil.form(callBack, map);
        return JSONObject.parseObject(result);
    }
    /**
     * 评论禁言
     * @param json
     * @param callBack
     * @return
     */
    public JSONObject commentSpeak(JSONObject json, String callBack) {
    	logger.info("评论禁言:param:{}", json);
    	Map<String, String> map = new HashMap<>();
    	map.put("param", json.toJSONString());
    	String result = HttpUtil.form(callBack, map);
    	return JSONObject.parseObject(result);
    }
    
    /**
     * 频道审核回调
     * @param json
     * @param callBack
     * @return
     */
    public JSONObject channelPass(JSONObject json, String callBack) {
    	logger.info("频道审核回调:param:{}", json);
    	Map<String, String> map = new HashMap<>();
    	map.put("param", json.toJSONString());
    	String result = HttpUtil.form(callBack, map);
    	return JSONObject.parseObject(result);
    }
    
    
    /**
     * 图文审核回调
     * @param ids
     * @param type  1(fabu),2(xiaxian),3(shanchu)
     * @param shenheStatus 1
     * @param msg
     * @param callBack
     * @return
     */
    public JSONObject contentPass(String contentId, String type,String msg, String callBack) {
        logger.info("图文回调:ids:{},type:{},msg:{}", contentId, type, msg);
        HttpUtil httpUtil = HttpUtil.init();
        String URL = callBack + "?contentId=" + contentId + "&type=" + type+ "&shenMsg=" + msg;
        Map<String, String> post = httpUtil.post(URL);
        return JSONObject.parseObject(post.get("result"));
    }
	public JSONObject momentPass(String content_id, Integer state, String msg, String callback, String userId) {
		logger.info("朋友圈回调:content_id:{},state:{},msg:{},userId:{}", content_id, state, msg,userId);
		JSONObject json=new JSONObject();
		json.put("userId",userId );
		json.put("momentId",content_id );
		json.put("status",state );
		json.put("msg", msg);
		String httpUtilResult = HttpClientUtils.HttpPostWithJson(callback, json.toString());
		logger.info("朋友圈返回数据,httpUtilResult=====" + httpUtilResult);
        JSONObject result = JSONObject.parseObject(httpUtilResult);
		return result;
	}
	public JSONObject queryUser(String userId, String userMobile) {
		 logger.info("用户云查询用户:userId:{},userMobile:{}", userId, userMobile);
	        HttpUtil httpUtil = HttpUtil.init();
	        String URL = "";
	        if(CommonUtils.isNotEmpty(userId)){
	        	URL = queryUserByUserId + userId;
	        }else{
	        	URL = queryUserByMobile + userMobile;
	        }
	        logger.info("用户云查询用户使用url:"+URL);
	        Map<String, String> post = httpUtil.post(URL);
	        return JSONObject.parseObject(post.get("result"));
	}

	//音频回调
	public JSONObject audioPass(String audioId, int state, String attr_tags, String msg, String callBack) {
		logger.info("点播音频回调:audioId:{},state:{},attr_tags:{},msg:{}", audioId, state, attr_tags, msg);
		JSONObject params = new JSONObject();
		params.put("video_id", audioId);
		//3-成功  4-失败
		params.put("state", state + "");
		params.put("attr_tags", attr_tags);
		params.put("msg", msg);
		HttpUtil httpUtil = HttpUtil.init();
		httpUtil.setParam("param", params.toJSONString());
		String token = "";
		try {
			String cb = callBack.replace("//", "");
			cb = cb.substring(cb.indexOf("/"));
			token = CommonUtils.md5(cb + platformKey + platformValue);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		String URL = callBack + "?platform=" + platformKey + "&token=" + token;
		Map<String, String> post = httpUtil.post(URL);
		return JSONObject.parseObject(post.get("result"));
	}
}