VideosController.java 3.53 KB
package com.cnlive.shenhe.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.serviceImpl.VideosServiceImpl;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.cnlive.shenhe.utils.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Auther: chenhao
 * @Date: 2018/11/30 14:22
 * @Description:视频送审接口
 */
@Controller
@RequestMapping("/videos")
public class VideosController {
    @Autowired
    VideosServiceImpl videosService;
    @PostMapping("/import")
    @ResponseBody
    public String impotVideo(@RequestBody  JSONObject json){
        ShySites shySites = new ShySites();
        ShyVideos shyVideos = new ShyVideos();
        //判断是否白名单
        shySites.setSpid(Integer.parseInt(json.getString("spId")));
        List<ShySites> shySitesList = videosService.getBusiness(shySites);
        if(!shySitesList.isEmpty()){
            if(!shySitesList.get(0).getWrite_business().isEmpty()){
                shyVideos.setState(CommonConst.AUDIT_SUCCESS);
            }else {
                shyVideos.setState(CommonConst.AUDIT_INTT);
            }
        }else {
            return "没有此站点";
        }
        //封装数据入库
        shyVideos.setVideo_id(json.getString("videoId"));
        shyVideos.setVideo_title(json.getString("videoTitle"));
        shyVideos.setVideo_url(json.getString("videoUrl"));
        shyVideos.setVideo_imgs(json.getString("videoCoverUrl"));
        shyVideos.setVideo_desc(json.getString("videoIntro"));
        shyVideos.setVideo_keyword(json.getString("videoKeyword"));
        shyVideos.setVideo_priority(json.getString("priority"));
        shyVideos.setCallback(json.getString("callback"));
        shyVideos.setSpid(Integer.parseInt(json.getString("spId")));
        int i = videosService.impotVideo(shyVideos);
        if(i>0){
            return  "\"errorCode\" = 0,\"errorMessage\" = \"点播审核请求收到成功\"";
        }else {
            return  "\"errorCode\" = 0,\"errorMessage\" = \"点播审核请求收到失败\"";
        }
    }
    public String getInfo(String activity_id,int state,String attr_tags,String msg){
        String url ="http://mam.innerapi.cnlive.com/v1/inner/ShenHeInfo/shenheNotify";
        String platformKey ="AUDIT";
        String platformValue="10011438";
        String token = null;
        try {
            token = CommonUtils.md5(url+platformKey+platformValue);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Map<String, String> params = new HashMap<>();
        params.put("activity_id",activity_id);
        params.put("state",state+"");
        params.put("attr_tags",attr_tags);
        params.put("msg",msg);
        HttpUtil httpUtil = HttpUtil.init();
        String URL =url+"platform="+platformKey+"&token="+token;
        httpUtil.setParamMap(params);
        Map<String, String> post = httpUtil.post(URL);
        String result = JSON.toJSONString(post);
        videosService.updateVideo(activity_id,state,attr_tags,msg);
        return  result;
    }


}