管道基础大数据平台系统开发-【后端】-Server
xing
2023-02-28 548bb8f71f595ecffb9ab7233f4a2fe709093abb
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.lf.server.controller.all;
 
import com.alibaba.fastjson.JSON;
import com.lf.server.entity.ctrl.SdkDecryptEntity;
import com.lf.server.entity.ctrl.SdkSecretEntity;
import com.lf.server.entity.other.FloatServerResponse;
import com.lf.server.entity.other.ReqParamFloatServer;
import com.lf.server.helper.HttpHelper;
import com.lf.server.helper.LicHelper;
import com.lf.server.helper.WebHelper;
import io.swagger.annotations.Api;
import org.apache.http.HttpEntity;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.util.EntityUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
/**
 * FloatServer
 * @author WWW
 */
@RestController
@RequestMapping("/floatserver")
public class FloatServerController extends BaseController {
    private static LicHelper licHelper;
 
    private final static boolean IS_REDIRECT = false;
 
    @PostMapping({"/checkout/license"})
    public void license(HttpServletRequest req, HttpServletResponse res) {
        try {
            if (IS_REDIRECT) {
                HttpHelper httpHelper = new HttpHelper();
                httpHelper.service(req, res, "http://192.168.20.43:38080/floatserver/checkout/license", null);
                return;
            }
 
            HttpEntity entity = new InputStreamEntity(req.getInputStream(), getContentLength(req));
            String str = EntityUtils.toString(entity, "UTF-8");
 
            LicHelper helper = getHelper();
            String reqJson = helper.b(str);
 
            ReqParamFloatServer rfs = JSON.parseObject(reqJson, ReqParamFloatServer.class);
            FloatServerResponse fsr = new FloatServerResponse(rfs);
 
            String resJson = JSON.toJSONString(fsr);
            String strRes = helper.a(resJson);
 
            res.getWriter().write(strRes);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
 
    private Integer getContentLength(HttpServletRequest request) {
        String contentLengthHeader = request.getHeader("Content-Length");
        if (contentLengthHeader != null) {
            return Integer.parseInt(contentLengthHeader);
        }
 
        return -1;
    }
 
    private static LicHelper getHelper() {
        if (licHelper == null) {
            licHelper = new LicHelper();
            licHelper.d("&kdaow$IEW.##%5-");
            licHelper.c("*y91z72a;pclfleoqc20161v$DSP&%3+");
        }
 
        return licHelper;
    }
 
    @SuppressWarnings("AlibabaUndefineMagicConstant")
    private static String getClientIpAddr(HttpServletRequest req) {
        String ip;
        if ((ip = req.getHeader("x-forwarded-for")) == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = req.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = req.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = req.getRemoteAddr();
        }
 
        return ip;
    }
 
    public static void test() {
        try {
            ReqParamFloatServer reqParam = new ReqParamFloatServer("192.168.20.106", "12316");
            String json = JSON.toJSONString(reqParam);
 
            String licCode = "78a82f0920de0f557f8177bec1e48601c4dc25e4054a00728e4314b56528d3a1632de5298edee38a65412277977a174fea5d91c452b19ef138dbc2ba089ba632";
 
            LicHelper helper = getHelper();
            String str = helper.a(json);
            System.out.println("ReqParamFloatServer: " + str);
 
            String data = "8dfb75298185cbcc4b2d485fdb4f25627f7aeb4dd41329076b5015586e4d56cfe2c56f12cd9852c447904210117b41fe2672b24d7e82fd581ad5a0983b501b5bcbe97d65dbbe770dbdc4a98e80d2966a71ecd0041a5282283bff853d70caf7aed671bc9c9d4bedf6d1d0294394861af40f195d68a965d957d53c78aa50ada3afc65d1a526c54648e6e081e8f7f7ab1c31b9f75916170e638b0b9216d30204864afe3a7a1bc8a6563bf44daf6a29e27c19f798c4f82dbb904ea4aa4fcc87a82226d9bf3e891ecb97b94263064fec025e3aa7c440d7c0e8ed559b84ae2438ec0fc438444a03c992883170ecdde20e08552efcf9d584de469930b27c81f946548d5c6e63e815671182b03b5e6e622ddb10a3f6a35ad3f44ec247a3b2dee0e936020d48efb7abc2d2abfb555f61d54c85eca";
            String rs = helper.b(data);
            System.out.println("Lic: " + rs);
        } catch (Exception ex) {
            System.out.println(ex.getStackTrace());
        }
    }
 
    @GetMapping({"/licenseEncryption/getLicenseSecret"})
    @PostMapping({"/licenseEncryption/getLicenseSecret"})
    public void getLicenseSecret(HttpServletResponse res) {
        try {
            String json = JSON.toJSONString(new SdkSecretEntity());
            WebHelper.write2Page(res, json);
        } catch (Exception ex) {
            // http://127.0.0.1:12316/server/floatserver/licenseEncryption/getLicenseSecret
        }
    }
 
    @GetMapping({"/licenseEncryption/getLicenseDecrypt"})
    @PostMapping({"/licenseEncryption/getLicenseDecrypt"})
    public void getLicenseDecrypt(HttpServletResponse res) {
        try {
            String json = JSON.toJSONString(new SdkDecryptEntity());
            WebHelper.write2Page(res, json);
        } catch (Exception ex) {
            // http://127.0.0.1:12316/server/floatserver/licenseEncryption/getLicenseDecrypt
        }
    }
}