| | |
| | | |
| | | 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 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; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 设备状态变化推送 |
| | |
| | | NotificationStationStatusResult notificationStationStatusResult = JSON.parseObject(decrypt, NotificationStationStatusResult.class); |
| | | return notificationStationStatusResult; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 推动充电状态 |
| | | * @param info |
| | |
| | | NotificationEquipChargeStatusResult notificationEquipChargeStatusResult = JSON.parseObject(decrypt, NotificationEquipChargeStatusResult.class); |
| | | return notificationEquipChargeStatusResult; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 推送充电订单信息 |
| | | * @param info |
| | |
| | | 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); |
| | |
| | | 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(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | 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(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | 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(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | log.info("推送充换电站实时功率信息Data:" + decrypt); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | BaseModel model = new BaseModel(); |
| | | model.setOperatorID("MA25CNM38"); |
| | |
| | | // 打印计算得到的签名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=="); |