package com.yeshi.buwan.controller.api; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.yeshi.buwan.domain.AcFunTemporary; import com.yeshi.buwan.domain.AcfunValidate; import com.yeshi.buwan.log.LogHelper; import com.yeshi.buwan.service.imp.AcFunTemporaryService; import com.yeshi.buwan.util.JsonUtil; import com.yeshi.buwan.util.StringUtil; import com.yeshi.buwan.util.TimeUtil; @Controller @RequestMapping("video/acFun") public class AcFunController { @Resource private AcFunTemporaryService acFunTemporaryService; @RequestMapping(value = "acFcVideo") public void acFunVideo(AcfunValidate valiData, String json, PrintWriter out, HttpServletResponse res, HttpServletRequest request) { try { request.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } res.setHeader("Content-type", "text/json;charset=UTF-8"); try { LogHelper.print(json); long _t = valiData.getT(); String key = "acFun"; String mySgin = StringUtil.Md5(_t + key); String sign = valiData.getSign(); if (mySgin.equals(sign)) { LogHelper.error("Acfun签名验证成功"); AcFunTemporary act = new AcFunTemporary(); act.setJson(json); act.setIsConsume(false); act.setErrorCount(0); acFunTemporaryService.save(act); LogHelper.error("Acfun数据暂存成功"); out.print(JsonUtil.loadTrueAdmin("success")); } else { LogHelper.error("Acfun签名验证失败"); out.print(JsonUtil.loadFalseAdmin("验证失败")); } } catch (Exception e) { printError(e); out.print(JsonUtil.loadFalseAdmin("异常错误:" + e.getMessage())); } } private void printError(Exception e) { try { String date = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy_MM_dd"); String os = System.getProperty("os.name"); String filePath = String.format("/usr/local/tomcat8_buwan/logs/error_detail_%s.txt", date); if (os.toLowerCase().startsWith("win")) { filePath = String.format("C:/logs/error_detail_%s.txt", date); } else filePath = String.format("/usr/local/tomcat8_buwan/logs/error_detail_%s.txt", date); OutputStream out = new FileOutputStream(new File(filePath), true); try { PrintStream ps = new PrintStream(out); ps.print(TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); ps.print("\n"); e.printStackTrace(ps); ps.flush(); ps.close(); } finally { out.close(); } } catch (Exception e1) { } } }