package com.moon.server.controller.all;
|
|
import com.alibaba.fastjson.JSON;
|
import com.moon.server.entity.ctrl.SdkDecryptEntity;
|
import com.moon.server.entity.ctrl.SdkSecretEntity;
|
import com.moon.server.entity.other.FloatServerResponse;
|
import com.moon.server.entity.other.ReqParamFloatServer;
|
import com.moon.server.helper.HttpHelper;
|
import com.moon.server.helper.LicHelper;
|
import com.moon.server.helper.WebHelper;
|
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;
|
import java.util.Arrays;
|
|
@RestController
|
@SuppressWarnings("ALL")
|
@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, null, "http://192.168.20.43:38080/floatserver/checkout/license");
|
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(Arrays.toString(ex.getStackTrace()));
|
}
|
}
|
|
@GetMapping({"/licenseEncryption/getLicenseSecret"})
|
@PostMapping({"/licenseEncryption/getLicenseSecret"})
|
public void getLicenseSecret(HttpServletResponse res) {
|
// http://127.0.0.1:12316/server/floatserver/licenseEncryption/getLicenseSecret
|
String json = JSON.toJSONString(new SdkSecretEntity());
|
WebHelper.writeStr2Page(res, json);
|
}
|
|
@GetMapping({"/licenseEncryption/getLicenseDecrypt"})
|
@PostMapping({"/licenseEncryption/getLicenseDecrypt"})
|
public void getLicenseDecrypt(HttpServletResponse res) {
|
// http://127.0.0.1:12316/server/floatserver/licenseEncryption/getLicenseDecrypt
|
String json = JSON.toJSONString(new SdkDecryptEntity());
|
WebHelper.writeStr2Page(res, json);
|
}
|
}
|