admin
2021-08-27 8fee151ffae0c3818694b7318583814bf92663e2
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
package com.yeshi.buwan.controller;
 
import com.yeshi.buwan.videos.pptv.PPTVApiUtil;
import com.yeshi.buwan.videos.pptv.PPTVUtil;
import com.yeshi.buwan.util.log.LoggerUtil;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
 
@Controller
@RequestMapping("pptv")
public class PPTVController {
 
    @ResponseBody
    @RequestMapping("user/{code}")
    public void validCode(@PathVariable String code, HttpServletResponse response) throws IOException {
        LoggerUtil.getTestLogger().info("PPTVCode回调:{}", code);
        response.setContentType("application/json;charset=UTF-8");
        PPTVUtil.PPTVCodeInfo codeInfo = PPTVUtil.decryptPPTVCode(code);
        if (codeInfo == null) {
            LoggerUtil.getTestLogger().info("PPTVCode回调-解码失败:{}", code);
            response.getWriter().print(loadFalseResult(1, "code校验失败,解码失败"));
        } else {
            //间隔时间大于1天
            if (System.currentTimeMillis() - codeInfo.time > 1000 * 60 * 60L * 24) {
                response.getWriter().print(loadFalseResult(2, "code校验失败,时间超限"));
                return;
            }
            LoggerUtil.getTestLogger().info("PPTVCode回调-解码成功:{},{}", code, codeInfo.pptvUid);
 
            response.getWriter().print(loadTrueResult(codeInfo.pptvUid));
        }
    }
 
    private String loadFalseResult(int code, String msg) {
        JSONObject root = new JSONObject();
        root.put("code", code);
        root.put("infoMsg", msg);
        return root.toString();
    }
 
 
    private String loadTrueResult(String pptvUid) {
        JSONObject root = new JSONObject();
        root.put("code", 100);
        root.put("infoMsg", "code校验成功");
        JSONObject data = new JSONObject();
        data.put("userid", pptvUid);
        data.put("channelNo", PPTVApiUtil.CHANNEL_ID);
        data.put("appKey", PPTVApiUtil.APP_KEY);
        root.put("data", data);
        return root.toString();
    }
 
 
}