admin
2021-08-13 cdc3690a0354e01b44852f4c9da3b7204128d2eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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) {
 
        }
 
    }
 
}