| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.core.utils.SpringUtils; |
| | | import com.ruoyi.integration.drainage.kuaidian.model.NotificationStationChangeResult; |
| | | import com.ruoyi.integration.drainage.kuaidian.model.StationChange; |
| | | import com.ruoyi.integration.drainage.model.*; |
| | | import com.ruoyi.integration.drainage.model.enu.InterfaceUrlEnum; |
| | | import com.ruoyi.other.api.domain.Operator; |
| | |
| | | import java.time.ZoneOffset; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 中电联TCEC标准 |
| | |
| | | |
| | | private static OperatorClient operatorClient = SpringUtils.getBean(OperatorClient.class); |
| | | |
| | | private static Map<Long, Integer> map = new HashMap<>(); |
| | | public static Map<Long, Integer> map = new HashMap<>(); |
| | | |
| | | |
| | | /** |
| | | * 获取token |
| | | */ |
| | | public static String queryToken(Operator operator){ |
| | | HttpRequest post = HttpUtil.createPost(""); |
| | | HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.QUERY_TOKEN.getUrl()); |
| | | post.contentType("application/json;charset=utf-8"); |
| | | JSONObject body = new JSONObject(); |
| | | body.put("OperatorID", OperatorID); |
| | | body.put("OperatorID", operator.getOurOperatorId()); |
| | | body.put("OperatorSecret", operator.getOurOperatorSecret()); |
| | | post.body(body.toJSONString()); |
| | | HttpResponse execute = post.execute(); |
| | |
| | | } |
| | | return JSON.parseObject(execute.body(), NotificationStationStatusResult.class); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 站点变更通知 |
| | | * @param operator |
| | | * @param type |
| | | * @param siteIds |
| | | * @return |
| | | */ |
| | | public static NotificationStationChangeResult notificationStationChange(Operator operator, Integer type, List<Integer> siteIds) { |
| | | StationChange stationChange = new StationChange(); |
| | | stationChange.setOperatorId(OperatorID); |
| | | stationChange.setType(type); |
| | | List<String> collect = siteIds.stream().map(String::valueOf).collect(Collectors.toList()); |
| | | stationChange.setStationIds(collect); |
| | | HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.NOTIFICATION_STATION_CHANGE.getUrl()); |
| | | buildBody(post, stationChange, operator); |
| | | HttpResponse execute = post.execute(); |
| | | if(200 != execute.getStatus()){ |
| | | log.error("推送站点变更通知失败:" + execute.body()); |
| | | return null; |
| | | } |
| | | return JSON.parseObject(execute.body(), NotificationStationChangeResult.class); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | post.contentType("application/json;charset=utf-8"); |
| | | post.header("Authorization", "Bearer " + getToken(operator)); |
| | | BaseRequest baseRequest = new BaseRequest(); |
| | | baseRequest.setOperatorID(OperatorID); |
| | | baseRequest.setOperatorID(operator.getOurOperatorId()); |
| | | baseRequest.setTimeStamp(timeStamp); |
| | | baseRequest.setSeq(String.format("%04d", integer)); |
| | | String jsonString = JSON.toJSONString(o); |
| | | String encrypt = AESUtil.encrypt(jsonString, operator.getDataSecret(), operator.getDataSecretIv()); |
| | | String encrypt = AESUtil.encrypt(jsonString, operator.getOurDataSecret(), operator.getOurDataSecretIv()); |
| | | baseRequest.setData(encrypt); |
| | | baseRequest.setOperator(operator); |
| | | baseRequest.setSig(buildSign(baseRequest)); |
| | | baseRequest.setSig(ourBuildSign(baseRequest)); |
| | | post.body(JSON.toJSONString(baseRequest)); |
| | | //清空小于当前时间的map中的无效数据 |
| | | for (Long k : map.keySet()) { |
| | |
| | | return sign; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 构建签名字符串 |
| | | * @param model |
| | | * @return |
| | | */ |
| | | public static String ourBuildSign(BaseModel model){ |
| | | Operator operator = model.getOperator(); |
| | | //签名秘钥SigSecret |
| | | String key = operator.getOurSigSecret(); |
| | | String sign = ""; |
| | | switch (operator.getName()){ |
| | | case "XinDianTu": |
| | | //进行字符串拼接、计算 |
| | | String m = new StringBuilder(operator.getOurOperatorId()).append(model.getData()).append(model.getTimeStamp()).append(model.getSeq()).toString(); |
| | | byte[] hmacMd5 = SignUtil.getHMacMD5Bytes(key.getBytes(), m.getBytes()); |
| | | // 打印计算得到的签名Sig |
| | | sign = SignUtil.bytesToHexString(hmacMd5); |
| | | break; |
| | | case "KuaiDian": |
| | | sign = SignUtil.hmacSign(model.getData(), key); |
| | | break; |
| | | } |
| | | return sign; |
| | | } |
| | | |
| | | |
| | | } |