package com.ruoyi.jianguan.elutong.controller;
|
|
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpResponse;
|
import cn.hutool.http.HttpUtil;
|
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson2.JSON;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.jianguan.elutong.config.AppServerConfig;
|
import com.ruoyi.jianguan.elutong.core.AESTools;
|
import com.ruoyi.jianguan.elutong.core.CommonRequest;
|
import com.ruoyi.jianguan.elutong.core.CommonResponse;
|
import com.ruoyi.jianguan.elutong.core.SignatureTools;
|
import com.ruoyi.integration.api.elutong.model.ConnectorStatusReq;
|
import com.ruoyi.integration.api.elutong.model.StationInfoReq;
|
import com.ruoyi.integration.api.elutong.model.StationsStatusReq;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.MediaType;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.client.RestTemplate;
|
|
import java.text.DateFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
|
@Slf4j
|
@RestController
|
@RequestMapping("/elutong")
|
public class SampleController {
|
|
@Autowired
|
private AppServerConfig appServerConfig;
|
@Autowired
|
private RestTemplate restTemplate;
|
|
/**
|
* 签名
|
*
|
* @param request
|
* @param privateKey
|
* @return
|
*/
|
public static CommonRequest sign(CommonRequest request, String privateKey) {
|
String signStr = SignatureTools.buildSignStr(request);
|
signStr = signStr + "&filename=" + request.getFilename();
|
log.info("【E路通】signStr : {}", signStr);
|
String sign = SignatureTools.rsa256Sign(signStr, privateKey);
|
request.setSign(sign);
|
return request;
|
}
|
|
/**
|
* 验签
|
*
|
* @param response
|
* @return
|
*/
|
public boolean verifySign(CommonResponse response) {
|
String signStr = SignatureTools.buildSignStr(response);
|
log.info("【E路通】signStr : {}", signStr);
|
log.info("【E路通】sign : {}", response.getSign());
|
return SignatureTools.rsa256Verify(signStr, appServerConfig.getSignPub(), response.getSign());
|
}
|
|
|
|
@GetMapping("/test")
|
public String test() {
|
Date date = new Date();
|
DateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
String filename = "CHARGE_DATA_STATIONINFO_REQ"+"_"+appServerConfig.getAppId()+"_"+format.format(date)+".json";
|
//String filename = "SAIS_SERVICEAREA_LPAGE_REQ" + "_" + appServerConfig.getAppId() + "_" + format.format(date) + ".json";
|
|
|
CommonRequest req = new CommonRequest();
|
req.setEncryptType("AES");
|
req.setSignType("RSA256");
|
req.setFilename(filename);
|
format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
req.setTimestamp(format.format(date));
|
|
String requestJson = "{\n" +
|
"\"operatorId\":\"91530xxxxK3LK15Y\",\n" +
|
"\"operatorInfo\":{\n" +
|
"\"operatorId\":\"91530xxxxK3LK15Y\",\n" +
|
"\"operatorName\":\"xxx产业发展有限公司\",\n" +
|
"\"operatorTel1\":\"0871-61408801\",\n" +
|
"\"operatorTel2\":\"0871-61408801\",\n" +
|
"\"operatorRegAddress\":\"xxx西山区前卫街道前福路231号\",\n" +
|
"\"operatorNote\":null\n" +
|
"},\n" +
|
"\"stationId\":\"G56-111111-220-2-02819-0-CD-01025001\",\n" +
|
"\"serAreaCode\":\"G56-111111-220-2-02819-0\",\n" +
|
"\"itemSize\":1,\n" +
|
"\"stationInfos\":[\n" +
|
"{\n" +
|
"\"serAreaCode\":\"G56-111111-220-2-02819-0\",\n" +
|
"\"stationId\":\"G56-111111-220-2-02819-0-CD-01025001\",\n" +
|
"\"stationMode\":\"CD\",\n" +
|
"\"operatorId\":\"915300016K3LK15Y\",\n" +
|
"\"stationName\":\"黄草xxx车区上行\",\n" +
|
"\"areaCode\":\"510100\",\n" +
|
"\"serviceTel\":\"0871-68408801\",\n" +
|
"\"stationType\":1,\n" +
|
"\"stationStatus\":50,\n" +
|
"\"parkNums\":2,\n" +
|
"\"stationLng\":98.7116251,\n" +
|
"\"stationLat\":24.6117291,\n" +
|
"\"siteGuide\":null,\n" +
|
"\"construction\":11,\n" +
|
"\"pictures\":null,\n" +
|
"\"matchCars\":null,\n" +
|
"\"businessHours\":\"周一至周日00:00-24:00\",\n" +
|
"\"electricityFee\":null,\n" +
|
"\"serviceFee\":null,\n" +
|
"\"parkFee\":null,\n" +
|
"\"payment\":null,\n" +
|
"\"supportOrder\":null,\n" +
|
"\"equipmentInfos\":[\n" +
|
"{\n" +
|
"\"equipmentId\":\"02025001\",\n" +
|
"\"manufacturerId\":\"11\",\n" +
|
"\"manufacturerName\":null,\n" +
|
"\"equipmentModel\":null,\n" +
|
"\"productionDate\":null,\n" +
|
"\"equipmentType\":1,\n" +
|
"\"connectorInfos\":[\n" +
|
"{\n" +
|
"\"connectorId\":\"0202500101\",\n" +
|
"\"connectorName\":null,\n" +
|
"\"connectorType\":1,\n" +
|
"\"voltageUpperLimits\":750,\n" +
|
"\"voltageLowerLimits\":150,\n" +
|
"\"current\":40,\n" +
|
"\"power\":30.0,\n" +
|
"\"parkNo\":null,\n" +
|
"\"nationalStandard\":2\n" +
|
"}\n" +
|
"],\n" +
|
"\"equipmentLng\":null,\n" +
|
"\"equipmentLat\":null,\n" +
|
"\"power\":37.0,\n" +
|
"\"equipmentName\":null\n" +
|
"}\n" +
|
"],\n" +
|
"\"remark\":null\n" +
|
"}\n" +
|
"]\n" +
|
"}\n";
|
//String requestJson = "{\"pageNum\":1,\"pageSize\":700}";
|
System.out.println("queryParam : " + requestJson);
|
String bizContentJson = AESTools.encrypt(requestJson, appServerConfig.getAesKey());
|
|
req.setBizContent(bizContentJson);
|
System.out.println("encrypt CommonRequest toJson : " + JSONObject.toJSONString(req));
|
req = sign(req, appServerConfig.getPriKey());
|
System.out.println("sign : " + req.getSign());
|
System.out.println("request body : " + JSONObject.toJSONString(req));
|
|
HttpHeaders headers = new HttpHeaders();
|
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
String bodyStr = JSONObject.toJSONString(req);
|
HttpEntity<String> request = new HttpEntity<String>(bodyStr, headers);
|
ResponseEntity<String> response = restTemplate.postForEntity(appServerConfig.getServerUrl(), request, String.class);
|
String result = "";
|
if (response.getStatusCodeValue() == 200) {
|
result = response.getBody();
|
System.out.println("response result : " + result);
|
CommonResponse commonResponse = JSONObject.parseObject(result, CommonResponse.class);
|
if ("200".equals(commonResponse.getStatusCode())) {
|
boolean rsa256Verify = verifySign(commonResponse);
|
System.out.println("verify sign result : " + rsa256Verify);
|
}
|
}
|
return result;
|
}
|
|
|
/**
|
* 推送充电站静态信息
|
* @param stationInfoReq
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/pushStationInfo")
|
public R pushStationInfo(@RequestBody StationInfoReq stationInfoReq){
|
Date date = new Date();
|
DateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
String filename = "CHARGE_DATA_STATIONINFO_REQ_" + appServerConfig.getAppId() + "_" + format.format(date) + ".json";
|
|
CommonRequest req = new CommonRequest();
|
req.setEncryptType("AES");
|
req.setSignType("RSA256");
|
req.setFilename(filename);
|
format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
req.setTimestamp(format.format(date));
|
|
String requestJson = JSON.toJSONString(stationInfoReq);
|
log.info("【E路通-推送充电站静态信息】queryParam : {}", requestJson);
|
String bizContentJson = AESTools.encrypt(requestJson, appServerConfig.getAesKey());
|
|
req.setBizContent(bizContentJson);
|
log.info("【E路通-推送充电站静态信息】encrypt CommonRequest toJson : {}", JSONObject.toJSONString(req));
|
req = sign(req, appServerConfig.getPriKey());
|
log.info("【E路通-推送充电站静态信息】sign : {}", req.getSign());
|
log.info("【E路通-推送充电站静态信息】request body : {}", JSONObject.toJSONString(req));
|
|
HttpRequest post = HttpUtil.createPost(appServerConfig.getServerUrl());
|
HttpHeaders headers = new HttpHeaders();
|
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
post.header(headers);
|
String bodyStr = JSONObject.toJSONString(req);
|
post.body(bodyStr);
|
HttpResponse execute = post.execute();
|
String result = "";
|
if (execute.getStatus() == 200) {
|
result = execute.body();
|
log.info("【E路通-推送充电站静态信息】response result : {}", result);
|
CommonResponse commonResponse = JSONObject.parseObject(result, CommonResponse.class);
|
if ("200".equals(commonResponse.getStatusCode())) {
|
boolean rsa256Verify = verifySign(commonResponse);
|
log.info("【E路通-推送充电站静态信息】verify sign result : {}", rsa256Verify);
|
return R.ok();
|
}else{
|
return R.fail(commonResponse.getErrorMsg());
|
}
|
}
|
return R.fail("推送接口请求失败");
|
}
|
|
|
/**
|
* 推送充电站状态信息
|
* @param stationsStatusReq
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/pushStationsStatus")
|
public R pushStationsStatus(@RequestBody StationsStatusReq stationsStatusReq){
|
Date date = new Date();
|
DateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
String filename = "CHARGE_DATA_STATIONSTATUS_REQ_" + appServerConfig.getAppId() + "_" + format.format(date) + ".json";
|
|
CommonRequest req = new CommonRequest();
|
req.setEncryptType("AES");
|
req.setSignType("RSA256");
|
req.setFilename(filename);
|
format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
req.setTimestamp(format.format(date));
|
|
String requestJson = JSON.toJSONString(stationsStatusReq);
|
log.info("【E路通-推送充电站状态信息】queryParam : {}", requestJson);
|
String bizContentJson = AESTools.encrypt(requestJson, appServerConfig.getAesKey());
|
|
req.setBizContent(bizContentJson);
|
log.info("【E路通-推送充电站状态信息】encrypt CommonRequest toJson : {}", JSONObject.toJSONString(req));
|
req = sign(req, appServerConfig.getPriKey());
|
log.info("【E路通-推送充电站状态信息】sign : {}", req.getSign());
|
log.info("【E路通-推送充电站状态信息】request body : {}", JSONObject.toJSONString(req));
|
|
HttpRequest post = HttpUtil.createPost(appServerConfig.getServerUrl());
|
HttpHeaders headers = new HttpHeaders();
|
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
post.header(headers);
|
String bodyStr = JSONObject.toJSONString(req);
|
post.body(bodyStr);
|
HttpResponse execute = post.execute();
|
String result = "";
|
if (execute.getStatus() == 200) {
|
result = execute.body();
|
log.info("【E路通-推送充电站状态信息】response result : {}", result);
|
CommonResponse commonResponse = JSONObject.parseObject(result, CommonResponse.class);
|
if ("200".equals(commonResponse.getStatusCode())) {
|
boolean rsa256Verify = verifySign(commonResponse);
|
log.info("【E路通-推送充电站状态信息】verify sign result : {}", rsa256Verify);
|
return R.ok();
|
}else{
|
return R.fail(commonResponse.getErrorMsg());
|
}
|
}
|
return R.fail("推送接口请求失败");
|
}
|
|
|
/**
|
* 推送设备接口状态信息
|
* @param connectorStatusReq
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/pushConnectorStatus")
|
public R pushConnectorStatus(@RequestBody ConnectorStatusReq connectorStatusReq){
|
Date date = new Date();
|
DateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
String filename = "CHARGE_NOTIFICATION_CONNECTORSTAUS_REQ_" + appServerConfig.getAppId() + "_" + format.format(date) + ".json";
|
|
CommonRequest req = new CommonRequest();
|
req.setEncryptType("AES");
|
req.setSignType("RSA256");
|
req.setFilename(filename);
|
format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
req.setTimestamp(format.format(date));
|
|
String requestJson = JSON.toJSONString(connectorStatusReq);
|
log.info("【E路通-推送设备接口状态信息】queryParam : {}", requestJson);
|
String bizContentJson = AESTools.encrypt(requestJson, appServerConfig.getAesKey());
|
|
req.setBizContent(bizContentJson);
|
log.info("【E路通-推送设备接口状态信息】encrypt CommonRequest toJson : {}", JSONObject.toJSONString(req));
|
req = sign(req, appServerConfig.getPriKey());
|
log.info("【E路通-推送设备接口状态信息】sign : {}", req.getSign());
|
log.info("【E路通-推送设备接口状态信息】request body : {}", JSONObject.toJSONString(req));
|
|
HttpRequest post = HttpUtil.createPost(appServerConfig.getServerUrl());
|
HttpHeaders headers = new HttpHeaders();
|
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
post.header(headers);
|
String bodyStr = JSONObject.toJSONString(req);
|
post.body(bodyStr);
|
HttpResponse execute = post.execute();
|
String result = "";
|
if (execute.getStatus() == 200) {
|
result = execute.body();
|
log.info("【E路通-推送设备接口状态信息】response result : {}", result);
|
CommonResponse commonResponse = JSONObject.parseObject(result, CommonResponse.class);
|
if ("200".equals(commonResponse.getStatusCode())) {
|
boolean rsa256Verify = verifySign(commonResponse);
|
log.info("【E路通-推送设备接口状态信息】verify sign result : {}", rsa256Verify);
|
return R.ok();
|
}else{
|
return R.fail(commonResponse.getErrorMsg());
|
}
|
}
|
return R.fail("推送接口请求失败");
|
}
|
|
}
|