| | |
| | | * 获取token |
| | | */ |
| | | public static String queryToken(Operator operator){ |
| | | HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.QUERY_TOKEN.getUrl()); |
| | | HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.QUERY_TOKEN.getUrl()); |
| | | JSONObject info = new JSONObject(); |
| | | info.put("OperatorID", operator.getOurOperatorId()); |
| | | info.put("OperatorSecret", operator.getOperatorSecret()); |
| | |
| | | baseRequest.setOperator(operator); |
| | | baseRequest.setSig(buildSign(baseRequest)); |
| | | String request_json = JacksonUtils.toJson(baseRequest); |
| | | log.info("获取授权token请求:" + request_json); |
| | | log.info("获取授权token请求Data:" + jsonString); |
| | | log.info("获取三方平台授权token请求地址:" + post.getUrl()); |
| | | log.info("获取三方平台授权token请求参数:" + request_json); |
| | | log.info("获取三方平台授权token请求Data:" + jsonString); |
| | | post.body(request_json); |
| | | HttpResponse execute = post.execute(); |
| | | if(200 != execute.getStatus()){ |
| | | log.error("获取三方token失败:" + execute.body()); |
| | | log.error("获取三方平台授权token失败:" + execute.body()); |
| | | return null; |
| | | } |
| | | log.info("获取授权token响应:" + execute.body()); |
| | | log.info("获取三方平台授权token响应参数:" + execute.body()); |
| | | BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class); |
| | | Integer Ret = baseResult.getRet(); |
| | | if(0 != Ret){ |
| | | log.error("获取三方token失败:" + baseResult.getMsg()); |
| | | log.error("获取三方平台授权token失败:" + baseResult.getMsg()); |
| | | return null; |
| | | } |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | log.info("获取授权token请求Data:" + decrypt); |
| | | log.info("获取三方平台授权token响应Data:" + decrypt); |
| | | QueryTokenResult queryTokenResult = JSON.parseObject(decrypt, QueryTokenResult.class); |
| | | String token = queryTokenResult.getAccessToken(); |
| | | Long tokenAvailableTime = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) + queryTokenResult.getTokenAvailableTime(); |
| | | LocalDateTime localDateTime = Instant.ofEpochSecond(tokenAvailableTime).atOffset(ZoneOffset.UTC).toLocalDateTime(); |
| | | operator.setAccessToken(token); |
| | | operator.setTokenAvailableTime(localDateTime); |
| | | operator.setTokenAvailableTime(tokenAvailableTime); |
| | | operatorClient.editOperator(operator); |
| | | return token; |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | public static String getToken(Operator operator){ |
| | | if(null != operator.getTokenAvailableTime() && operator.getTokenAvailableTime().isBefore(LocalDateTime.now())){ |
| | | if(null != operator.getTokenAvailableTime() && operator.getTokenAvailableTime() > LocalDateTime.now().toEpochSecond(ZoneOffset.UTC)){ |
| | | return operator.getAccessToken(); |
| | | }else{ |
| | | return queryToken(operator); |
| | |
| | | * @param info |
| | | */ |
| | | public static NotificationStationStatusResult notificationStationStatus(Operator operator, ConnectorStatusInfo info) { |
| | | HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.NOTIFICATION_STATION_STATUS.getUrl()); |
| | | HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.NOTIFICATION_STATION_STATUS.getUrl()); |
| | | buildBody(post, info, operator); |
| | | HttpResponse execute = post.execute(); |
| | | if(200 != execute.getStatus()){ |
| | | log.error("推送三方设备状态变化失败:" + execute.body()); |
| | | log.error("推送三方平台设备状态失败:" + execute.body()); |
| | | return null; |
| | | } |
| | | return JSON.parseObject(execute.body(), NotificationStationStatusResult.class); |
| | | log.info("推送三方平台设备状态响应:" + execute.body()); |
| | | BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class); |
| | | Integer Ret = baseResult.getRet(); |
| | | if(0 != Ret){ |
| | | log.error("推送三方平台设备状态失败:" + baseResult.getMsg()); |
| | | return null; |
| | | } |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | log.info("推送三方平台设备状态Data:" + decrypt); |
| | | NotificationStationStatusResult notificationStationStatusResult = JSON.parseObject(decrypt, NotificationStationStatusResult.class); |
| | | return notificationStationStatusResult; |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public static NotificationStartChargeResult notificationStartChargeResult(Operator operator, NotificationStartCharge info){ |
| | | HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.NOTIFICATION_START_CHARGE_RESULT.getUrl()); |
| | | HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.NOTIFICATION_START_CHARGE_RESULT.getUrl()); |
| | | buildBody(post, info, operator); |
| | | HttpResponse execute = post.execute(); |
| | | if(200 != execute.getStatus()){ |
| | | log.error("推送三方启动充电结果失败:" + execute.body()); |
| | | log.error("推送三方平台启动充电结果失败:" + execute.body()); |
| | | return null; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.body()); |
| | | Integer ret = jsonObject.getInteger("Ret"); |
| | | if(0 != ret){ |
| | | log.error("推送三方启动充电结果失败:" + execute.body()); |
| | | log.info("推送三方平台启动充电结果响应:" + execute.body()); |
| | | BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class); |
| | | Integer Ret = baseResult.getRet(); |
| | | if(0 != Ret){ |
| | | log.error("推送三方平台启动充电结果失败:" + baseResult.getMsg()); |
| | | return null; |
| | | } |
| | | return jsonObject.getObject("Data", NotificationStartChargeResult.class); |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | log.info("推送三方平台启动充电结果Data:" + decrypt); |
| | | NotificationStartChargeResult notificationStartChargeResult = JSON.parseObject(decrypt, NotificationStartChargeResult.class); |
| | | return notificationStartChargeResult; |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public static NotificationEquipChargeStatusResult notificationEquipChargeStatus(Operator operator, QueryEquipChargeStatusResult info){ |
| | | HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.NOTIFICATION_EQUIP_CHARGE_STATUS.getUrl()); |
| | | HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.NOTIFICATION_EQUIP_CHARGE_STATUS.getUrl()); |
| | | buildBody(post, info, operator); |
| | | HttpResponse execute = post.execute(); |
| | | if(200 != execute.getStatus()){ |
| | | log.error("推送三方充电状态失败:" + execute.body()); |
| | | log.error("推送三方平台充电状态失败:" + execute.body()); |
| | | return null; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.body()); |
| | | Integer ret = jsonObject.getInteger("Ret"); |
| | | if(0 != ret){ |
| | | log.error("推送三方充电状态失败:" + execute.body()); |
| | | log.info("推送三方平台充电状态响应:" + execute.body()); |
| | | BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class); |
| | | Integer Ret = baseResult.getRet(); |
| | | if(0 != Ret){ |
| | | log.error("推送三方平台充电状态失败:" + baseResult.getMsg()); |
| | | return null; |
| | | } |
| | | return jsonObject.getObject("Data", NotificationEquipChargeStatusResult.class); |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | log.info("推送三方平台充电状态Data:" + decrypt); |
| | | NotificationEquipChargeStatusResult notificationEquipChargeStatusResult = JSON.parseObject(decrypt, NotificationEquipChargeStatusResult.class); |
| | | return notificationEquipChargeStatusResult; |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public static NotificationStopCharge notificationStopChargeResult(Operator operator, NotificationStopChargeResult info){ |
| | | HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.NOTIFICATION_STOP_CHARGE_RESULT.getUrl()); |
| | | HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.NOTIFICATION_STOP_CHARGE_RESULT.getUrl()); |
| | | buildBody(post, info, operator); |
| | | HttpResponse execute = post.execute(); |
| | | if(200 != execute.getStatus()){ |
| | | log.error("推送三方停止充电结果失败:" + execute.body()); |
| | | log.error("推送三方平台停止充电结果失败:" + execute.body()); |
| | | return null; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.body()); |
| | | Integer ret = jsonObject.getInteger("Ret"); |
| | | if(0 != ret){ |
| | | log.error("推送三方停止充电结果失败:" + execute.body()); |
| | | log.info("推送三方平台停止充电结果响应:" + execute.body()); |
| | | BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class); |
| | | Integer Ret = baseResult.getRet(); |
| | | if(0 != Ret){ |
| | | log.error("推送三方平台停止充电结果失败:" + baseResult.getMsg()); |
| | | return null; |
| | | } |
| | | return jsonObject.getObject("Data", NotificationStopCharge.class); |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | log.info("推送三方平台停止充电结果Data:" + decrypt); |
| | | NotificationStopCharge notificationStopCharge = JSON.parseObject(decrypt, NotificationStopCharge.class); |
| | | return notificationStopCharge; |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public static NotificationChargeOrderInfoResult notificationChargeOrderInfo(Operator operator, NotificationChargeOrderInfo info){ |
| | | HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.NOTIFICATION_CHARGE_ORDER_INFO.getUrl()); |
| | | HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.NOTIFICATION_CHARGE_ORDER_INFO.getUrl()); |
| | | buildBody(post, info, operator); |
| | | HttpResponse execute = post.execute(); |
| | | if(200 != execute.getStatus()){ |
| | | log.error("推送三方充电订单信息失败:" + execute.body()); |
| | | log.error("推送三方平台充电订单信息失败:" + execute.body()); |
| | | return null; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.body()); |
| | | Integer ret = jsonObject.getInteger("Ret"); |
| | | if(0 != ret){ |
| | | log.error("推送三方充电订单信息失败:" + execute.body()); |
| | | log.info("推送三方平台充电订单信息响应:" + execute.body()); |
| | | BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class); |
| | | Integer Ret = baseResult.getRet(); |
| | | if(0 != Ret){ |
| | | log.error("推送三方平台充电订单信息失败:" + baseResult.getMsg()); |
| | | return null; |
| | | } |
| | | return jsonObject.getObject("Data", NotificationChargeOrderInfoResult.class); |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | log.info("推送三方平台充电订单信息Data:" + decrypt); |
| | | NotificationChargeOrderInfoResult notificationChargeOrderInfoResult = JSON.parseObject(decrypt, NotificationChargeOrderInfoResult.class); |
| | | return notificationChargeOrderInfoResult; |
| | | } |
| | | |
| | | |
| | |
| | | baseRequest.setData(encrypt); |
| | | baseRequest.setOperator(operator); |
| | | baseRequest.setSig(buildSign(baseRequest)); |
| | | post.body(JacksonUtils.toJson(baseRequest)); |
| | | String request_json = JacksonUtils.toJson(baseRequest); |
| | | post.body(request_json); |
| | | log.info("推送三方平台请求地址:" + post.getUrl()); |
| | | log.info("推送三方平台请求参数:" + request_json); |
| | | log.info("推送三方平台请求Data:" + jsonString); |
| | | } |
| | | |
| | | |
| | |
| | | sign = SignUtil.bytesToHexString(hmacMd5); |
| | | break; |
| | | case "KuaiDian": |
| | | sign = SignUtil.hmacSign(model.getData(), key); |
| | | //进行字符串拼接、计算 |
| | | String m1 = new StringBuilder(model.getOperatorID()).append(model.getData()).append(model.getTimeStamp()).append(model.getSeq()).toString(); |
| | | // 打印计算得到的签名Sig |
| | | sign = SignUtil.hmacSign(m1, key); |
| | | break; |
| | | } |
| | | return sign; |
| | |
| | | sign = SignUtil.bytesToHexString(hmacMd5); |
| | | break; |
| | | case "KuaiDian": |
| | | sign = SignUtil.hmacSign(model.getData(), key); |
| | | //进行字符串拼接、计算 |
| | | String m1 = new StringBuilder(model.getOperatorID()).append(model.getData()).append(model.getTimeStamp()).append(model.getSeq()).toString(); |
| | | sign = SignUtil.hmacSign(m1, key); |
| | | break; |
| | | } |
| | | return sign; |
| | | } |
| | | public static String ourBuildSignJianGuan(BaseModel model){ |
| | | Operator operator = model.getOperator(); |
| | | if(null == operator){ |
| | | return ""; |
| | | } |
| | | //签名秘钥SigSecret |
| | | String key = operator.getOurSigSecret(); |
| | | String sign = ""; |
| | | //进行字符串拼接、计算 |
| | | String m1 = new StringBuilder(model.getOperatorID()).append(model.getData()).append(model.getTimeStamp()).append(model.getSeq()).toString(); |
| | | sign = SignUtil.hmacSign(m1, key); |
| | | return sign; |
| | | } |
| | | |
| | | |
| | | |
| | | |