| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.nacos.common.utils.JacksonUtils; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.MapperFeature; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.ruoyi.common.core.utils.HttpUtils; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.integration.drainage.model.*; |
| | |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import static com.ruoyi.integration.drainage.TCECUtil.getToken; |
| | |
| | | private static final String DataSecret = "50a61b93919c9604"; |
| | | private static final String DataSecretIV = "7c8ac6861661d584"; |
| | | |
| | | |
| | | private static final String OurDataSecret = "50a61b93919c9605"; |
| | | private static final String OurDataSecretIV = "7c8ac6861661d585"; |
| | | private static final String OurSigSecret = "a6fedf0e1b27d6f6"; |
| | | private static final String OurOperatorID = "MA01H3BQ3"; |
| | | private static final String OurOperatorSecret = "f1331ef0b37c2d1a"; |
| | | @Autowired |
| | | private RedisService redisService; |
| | | public static final String TOKEN_KEY = "charge_token:"; |
| | |
| | | *推送充电订单信息 |
| | | */ |
| | | private final static String supervise_notification_charge_order_info = "/supervise_notification_charge_order_info"; |
| | | private final static String supervise_notification_operation_stats_info = "/supervise_notification_operation_stats_info"; |
| | | private final static String supervise_notification_realtime_power_info = "/supervise_notification_realtime_power_info"; |
| | | private final static String supervise_notification_station_info = "/supervise_notification_station_info"; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取token |
| | | */ |
| | | public String queryToken(Operator operator){ |
| | | public String queryToken(){ |
| | | String token = redisService.getCacheObject(TOKEN_KEY); |
| | | if(StringUtils.hasLength(token)){ |
| | | return token; |
| | |
| | | redisService.setCacheObject(TOKEN_KEY,token, (long) (TokenAvailableTime - 60), TimeUnit.SECONDS); |
| | | return token; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 设备状态变化推送 |
| | |
| | | return null; |
| | | } |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), DataSecret, DataSecretIV); |
| | | log.info("推送三方平台设备状态Data:" + decrypt); |
| | | NotificationStationStatusResult notificationStationStatusResult = JSON.parseObject(decrypt, NotificationStationStatusResult.class); |
| | | return notificationStationStatusResult; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 推动充电状态 |
| | | * @param info |
| | |
| | | return null; |
| | | } |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), DataSecret, DataSecretIV); |
| | | log.info("推送三方平台充电状态Data:" + decrypt); |
| | | NotificationEquipChargeStatusResult notificationEquipChargeStatusResult = JSON.parseObject(decrypt, NotificationEquipChargeStatusResult.class); |
| | | return notificationEquipChargeStatusResult; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 推送充电订单信息 |
| | | * @param info |
| | |
| | | return null; |
| | | } |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), DataSecret, DataSecretIV); |
| | | log.info("推送三方平台充电订单信息Data:" + decrypt); |
| | | NotificationChargeOrderInfoResult notificationChargeOrderInfoResult = JSON.parseObject(decrypt, NotificationChargeOrderInfoResult.class); |
| | | return notificationChargeOrderInfoResult; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 构建请求参数和消息头 |
| | | * @param post |
| | |
| | | public void buildBody(HttpRequest post, Object o, Operator operator){ |
| | | Long timeStamp = Long.valueOf(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); |
| | | post.contentType("application/json;charset=utf-8"); |
| | | post.header("Authorization", "Bearer " + getToken(operator)); |
| | | post.header("Authorization", "Bearer " + queryToken()); |
| | | BaseRequest baseRequest = new BaseRequest(); |
| | | baseRequest.setOperatorID(operator.getOurOperatorId()); |
| | | baseRequest.setTimeStamp(timeStamp); |
| | | baseRequest.setSeq("0001"); |
| | | String jsonString = JacksonUtils.toJson(o); |
| | | String encrypt = AesEncryption.encrypt(jsonString, operator.getDataSecret(), operator.getDataSecretIv()); |
| | | // 使用 Jackson 转换为 JSON |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | objectMapper.enable(MapperFeature.USE_ANNOTATIONS); // 启用注解支持 |
| | | String jsonString = null; |
| | | try { |
| | | jsonString = objectMapper.writeValueAsString(o); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String encrypt = AesEncryption.encrypt(jsonString, DataSecret, DataSecretIV); |
| | | baseRequest.setData(encrypt); |
| | | baseRequest.setOperator(operator); |
| | | // baseRequest.setSig(buildSign(baseRequest)); |
| | | SequenceGenerator generator = new SequenceGenerator(); |
| | | String nextSequence = generator.getNextSequence(); |
| | | String hmacMD5 = HMacMD5Util.getHMacMD5(OperatorID,timeStamp+"", encrypt,nextSequence,SigSecret); |
| | | baseRequest.setSig(hmacMD5); |
| | | String request_json = JacksonUtils.toJson(baseRequest); |
| | | post.body(request_json); |
| | | log.info("推送三方平台请求地址:" + post.getUrl()); |
| | |
| | | log.info("推送三方平台请求Data:" + jsonString); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 推送充电用能统计 |
| | | * @param info |
| | | * @return |
| | | */ |
| | | public void superviseNotificationOperationStatsInfo(StationStatsInfoResult info){ |
| | | Operator operator = new Operator(); |
| | | HttpRequest post = HttpUtil.createPost(url+supervise_notification_operation_stats_info); |
| | | buildBody(post, info, operator); |
| | | HttpResponse execute = post.execute(); |
| | | if(200 != execute.getStatus()){ |
| | | log.error("推送充电用能统计失败:" + execute.body()); |
| | | return ; |
| | | } |
| | | log.info("推送充电用能统计信息响应:" + execute.body()); |
| | | BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class); |
| | | Integer Ret = baseResult.getRet(); |
| | | if(0 != Ret){ |
| | | log.error("推送充电用能统计信息失败:" + baseResult.getMsg()); |
| | | return ; |
| | | } |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), DataSecret, DataSecretIV); |
| | | log.info("推送充电用能统计信息Data:" + decrypt); |
| | | |
| | | } |
| | | /** |
| | | * 推送充换电站信息 |
| | | * @param info |
| | | * @return |
| | | */ |
| | | public void superviseNotificationStationInfo(SupStationInfoResult info){ |
| | | Operator operator = new Operator(); |
| | | HttpRequest post = HttpUtil.createPost(url+supervise_notification_station_info); |
| | | buildBody(post, info, operator); |
| | | HttpResponse execute = post.execute(); |
| | | if(200 != execute.getStatus()){ |
| | | log.error("推送充换电站信息失败:" + execute.body()); |
| | | return ; |
| | | } |
| | | log.info("推送充换电站信息信息响应:" + execute.body()); |
| | | BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class); |
| | | Integer Ret = baseResult.getRet(); |
| | | if(0 != Ret){ |
| | | log.error("推送充换电站信息失败:" + baseResult.getMsg()); |
| | | return ; |
| | | } |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), DataSecret, DataSecretIV); |
| | | log.info("推送充换电站信息信息Data:" + decrypt); |
| | | } |
| | | /** |
| | | * 充换电站功率信息 |
| | | * @param info |
| | | * @return |
| | | */ |
| | | public void superviseNotificationRealtimePowerInfo(SupStationPowerInfoResult info){ |
| | | Operator operator = new Operator(); |
| | | HttpRequest post = HttpUtil.createPost(url+supervise_notification_realtime_power_info); |
| | | buildBody(post, info, operator); |
| | | HttpResponse execute = post.execute(); |
| | | if(200 != execute.getStatus()){ |
| | | log.error("推送充换电站实时功率失败:" + execute.body()); |
| | | return ; |
| | | } |
| | | log.info("推送充换电站实时功率信息响应:" + execute.body()); |
| | | BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class); |
| | | Integer Ret = baseResult.getRet(); |
| | | if(0 != Ret){ |
| | | log.error("推送充换电站实时功率信息失败:" + baseResult.getMsg()); |
| | | return ; |
| | | } |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), DataSecret, DataSecretIV); |
| | | log.info("推送充换电站实时功率信息Data:" + decrypt); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | BaseModel model = new BaseModel(); |
| | | model.setOperatorID("MA25CNM38"); |
| | | model.setOperatorID("MA01H3BQ2"); |
| | | model.setData("AoArdDDcmHcmOMkCLHodTpY1xLtt9yhLqxvKPyfdlmEOBj1LJnQM+Z4JOZllt3Pj9rubfgxJ51zMAfzquQegJzHGAT9Y7JrKFzFe6jGtXo0="); |
| | | model.setTimeStamp(20250205120800L); |
| | | model.setSeq("0001"); |
| | |
| | | // 打印计算得到的签名Sig |
| | | String s = SignUtil.bytesToHexString(hmacMd5); |
| | | System.err.println(s); |
| | | |
| | | |
| | | |
| | | |
| | | // BaseModel model = new BaseModel(); |
| | | // model.setOperatorID("MA25CNM38"); |
| | | // model.setData("xQYYEPiwoc4JENnQsF50qP6Tmnj7uU/AshWn3QbIgrMIk8zvFpy6fWLIiLzQHcLPFCihqH1uzoNhGVNcS8Wvf5gIx9+cWJvYtjwtsjAGMEwNQ6y+rF1jjKnqCNcQbHbhqJ2l76sD54QCFKyenKxymrXri19bDV8hizn3nBw+jcHBtqKHWzjdSHwPDWPIw4rXnrbWLya2PXVgYtVg93WPtliw+0xsqW0BxJamE70/Ilbg4wB5fOAOvXmbLFI+v9jRjpcA7ImhprqPMYkXYAfa2QlICrJEBK7DfpJvRMzKzeT90kOAITqIqFvbfV0ti+greRqToLP6ni4o6w3ID42UmKasIpLTnx+qtR4bVTBTRuDzXvNXDA92RqHaJO21xbSen1eHN/yGfrchBIM0gmav7EpaYAerfU4ubnmJ6xujR6okYepJwBD5DiSIrObfS+GWVPRekvnjvm7BC02NXTrGKA=="); |