Просмотр исходного кода

加入公安天创接口对接

wuxw лет назад: 4
Родитель
Сommit
641d2ccddf

+ 57 - 0
java110-core/src/main/java/com/java110/core/factory/AuthenticationFactory.java

@@ -19,16 +19,20 @@ import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.constant.MappingConstant;
 import com.java110.utils.constant.ResponseConstant;
 import com.java110.utils.exception.NoAuthorityException;
+import com.java110.utils.util.Base64Convert;
 import com.java110.utils.util.StringUtil;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.logging.log4j.util.Base64Util;
 
 import javax.crypto.Cipher;
 import javax.crypto.SecretKeyFactory;
 import javax.crypto.spec.DESKeySpec;
 import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.security.InvalidParameterException;
 import java.security.Key;
 import java.security.KeyFactory;
@@ -69,6 +73,59 @@ public class AuthenticationFactory {
     private static final String CHARSET = "utf-8";
 
 
+        // 加密
+        public static String AesEncrypt(String sSrc, String sKey) throws Exception {
+            if (sKey == null) {
+                System.out.print("Key为空null");
+                return null;
+            }
+            // 判断Key是否为16位
+            if (sKey.length() != 16) {
+                System.out.print("Key长度不是16位");
+                return null;
+            }
+            byte[] raw = sKey.getBytes("utf-8");
+            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
+            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");//"算法/模式/补码方式"
+            cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
+            byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
+
+            return Base64Convert.byteToBase64(encrypted);//此处使用BASE64做转码功能,同时能起到2次加密的作用。
+        }
+
+        // 解密
+        public static String AesDecrypt(String sSrc, String sKey) throws Exception {
+            try {
+                // 判断Key是否正确
+                if (sKey == null) {
+                    System.out.print("Key为空null");
+                    return null;
+                }
+                // 判断Key是否为16位
+                if (sKey.length() != 16) {
+                    System.out.print("Key长度不是16位");
+                    return null;
+                }
+                byte[] raw = sKey.getBytes("utf-8");
+                SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
+                Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+                cipher.init(Cipher.DECRYPT_MODE, skeySpec);
+                byte[] encrypted1 = Base64Convert.base64ToByte(sSrc);//先用base64解密
+                try {
+                    byte[] original = cipher.doFinal(encrypted1);
+                    String originalString = new String(original,"utf-8");
+                    return originalString;
+                } catch (Exception e) {
+                    System.out.println(e.toString());
+                    return null;
+                }
+            } catch (Exception ex) {
+                System.out.println(ex.toString());
+                return null;
+            }
+        }
+
+
     /**
      * 生成key
      *

+ 63 - 0
service-job/src/main/java/com/java110/job/adapt/hcToTianchuang/GetTianChuangToken.java

@@ -0,0 +1,63 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.job.adapt.hcToTianchuang;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Synchronized;
+import com.java110.core.client.RestTemplate;
+import com.java110.core.factory.AuthenticationFactory;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.job.adapt.hcIot.IotConstant;
+import com.java110.utils.cache.CommonCache;
+import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.StringUtil;
+import com.java110.vo.ResultVo;
+import org.springframework.http.*;
+
+/**
+ * 获取token
+ * <p>
+ * 接口协议地址: https://gitee.com/java110/MicroCommunityThings/blob/master/back/docs/api.md
+ *
+ * @desc add by 吴学文 9:46
+ */
+
+public class GetTianChuangToken {
+
+
+    public static String get(String data) {
+        String tokenStr = TianChuangConstant.getAppId()+TianChuangConstant.getAppSecret()+ DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_H);
+        tokenStr += data;
+
+        return AuthenticationFactory.md5(tokenStr);
+    }
+
+    /**
+     * 封装头信息
+     *
+     * @return
+     */
+    private HttpHeaders getHeaders(String serviceId,String data) {
+        HttpHeaders httpHeaders = new HttpHeaders();
+        httpHeaders.add("appId", TianChuangConstant.getAppId());
+        httpHeaders.add("token", get(data));
+        httpHeaders.add("tranId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_tranId));
+        httpHeaders.add("serviceId", serviceId);
+        httpHeaders.add("serviceValue", serviceId);
+        //httpHeaders.add("Content-Type", "application/x-www-form-urlencoded");
+        return httpHeaders;
+    }
+}

+ 150 - 0
service-job/src/main/java/com/java110/job/adapt/hcToTianchuang/TianChuangConstant.java

@@ -0,0 +1,150 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.job.adapt.hcToTianchuang;
+
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.util.StringUtil;
+
+/**
+ * 天创常量类
+ * 接口协议地址: https://gitee.com/java110/MicroCommunityThings/blob/master/back/docs/api.md
+ *
+ * @desc add by 吴学文 9:49
+ */
+public class TianChuangConstant {
+
+    public static final String TC_DOMAIN = "TC"; // 公安天创
+    public static final String TC_URL = "TC_URL"; // 天创地址
+    public static final String TC_APP_ID = "TC_APP_ID"; // 物联网域
+    public static final String TC_APP_SECRET = "TC_APP_SECRET"; // 物联网域
+
+    private static final String DEFAULT_TC_URL = "http://112.51.96.125:9080/ywxzservice/dbClient.do";
+    //122350112432
+    private static final String DEFAULT_APP_ID = "26810B9FE0532D03";
+    private static final String DEFAULT_APP_SECRET = "CAD3218426800B9FE0532D03A8C0310E";
+
+    public static final String GET_TOKEN_URL = "/extApi/auth/getAccessToken?appId=APP_ID&appSecret=APP_SECRET";
+
+    //添加小区
+    public static final String ADD_COMMUNITY_URL = "/extApi/community/addCommunity";
+    //修改小区
+    public static final String UPDATE_COMMUNITY_URL = "/extApi/community/updateCommunity";
+    //删除小区
+    public static final String DELETE_COMMUNITY_URL = "/extApi/community/deleteCommunity";
+
+    //添加设备
+    public static final String ADD_MACHINE_URL = "/extApi/machine/addMachine";
+    //修改设备
+    public static final String UPDATE_MACHINE_URL = "/extApi/machine/updateMachine";
+    //删除设备
+    public static final String DELETE_MACHINE_URL = "/extApi/machine/deleteMachine";
+
+    //添加停车场
+    public static final String ADD_PARKING_AREA_URL = "/extApi/parkingArea/addParkingArea";
+    //修改停车场
+    public static final String UPDATE_PARKING_AREA_URL = "/extApi/parkingArea/updateParkingArea";
+    //删除停车场
+    public static final String DELETE_PARKING_AREA_URL = "/extApi/parkingArea/deleteParkingArea";
+
+    //添加车辆
+    public static final String ADD_OWNER_CAR_URL = "/extApi/car/addCar";
+    //修改车辆
+    public static final String UPDATE_OWNER_CAR_URL = "/extApi/car/updateCar";
+    //删除车辆
+    public static final String DELETE_OWNER_CAR_URL = "/extApi/car/deleteCar";
+
+    //添加车辆
+    public static final String ADD_CAR_BLACK_WHITE_URL = "/extApi/car/addBlackWhite";
+
+    //删除车辆
+    public static final String DELETE_CAR_BLACK_WHITE_URL = "/extApi/car/deleteBlackWhite";
+
+    //开门接口
+    public static final String OPEN_DOOR = "/extApi/machine/openDoor";
+
+    //获取二维码
+    public static final String GET_QRCODE = "/extApi/machine/getQRcode";
+    //重启接口
+    public static final String RESTART_MACHINE = "/extApi/machine/restartMachine";
+
+    //查询临时停车费订单
+    public static final String GET_TEMP_CAR_FEE_ORDER = "/extApi/fee/getTempCarFeeOrder";
+
+    //查询临时停车费订单
+    public static final String NOTIFY_TEMP_CAR_FEE_ORDER = "/extApi/fee/notifyTempCarFeeOrder";
+
+    //添加车辆
+    public static final String ADD_TEAM_CAR_FEE_CONFIG = "/extApi/fee/addTempCarFee";
+    //修改车辆
+    public static final String UPDATE_TEAM_CAR_FEE_CONFIG = "/extApi/fee/updateTempCarFee";
+    //删除车辆
+    public static final String DELETE_TEAM_CAR_FEE_CONFIG = "/extApi/fee/deleteTempCarFee";
+
+    //添加考勤班次
+    public static final String ADD_ATTENDANCE_CLASSES_STAFFS = "/extApi/attendance/addAttendanceClassStaffs";
+
+
+    //删除考勤班次
+    public static final String DELETE_ATTENDANCE_CLASSES_STAFFS = "/extApi/attendance/deleteAttendanceClassStaff";
+
+    //添加考勤班次
+    public static final String ADD_ATTENDANCE_CLASSES = "/extApi/attendance/addAttendanceClass";
+    //修改考勤班次
+    public static final String UPDATE_ATTENDANCE_CLASSES = "/extApi/attendance/updateAttendanceClass";
+    //删除考勤班次
+    public static final String DELETE_ATTENDANCE_CLASSES = "/extApi/attendance/deleteAttendanceClass";
+
+    public static final String HC_TOKEN = "HC_ACCESS_TOKEN";
+
+    //单位为秒
+    public static final int DEFAULT_LOG_TIME = 5 * 60;
+
+    //添加业主
+    public static final String ADD_OWNER = "/extApi/user/addUser";
+    public static final String EDIT_OWNER = "/extApi/user/updateUser";
+    public static final String DELETE_OWNER = "/extApi/user/deleteUser";
+
+
+    public static String getUrl(String param) {
+        String url = MappingCache.getValue(TC_DOMAIN, TianChuangConstant.TC_URL);
+
+        if (StringUtil.isEmpty(url)) {
+            return DEFAULT_TC_URL + param;
+        }
+
+        return url + param;
+    }
+
+    public static String getAppId() {
+        String appId = MappingCache.getValue(TC_DOMAIN, TianChuangConstant.TC_APP_ID);
+
+        if (StringUtil.isEmpty(appId)) {
+            return DEFAULT_APP_ID;
+        }
+
+        return appId;
+    }
+
+    public static String getAppSecret() {
+        String appSecret = MappingCache.getValue(TC_DOMAIN, TianChuangConstant.TC_APP_SECRET);
+
+        if (StringUtil.isEmpty(appSecret)) {
+            return DEFAULT_APP_SECRET;
+        }
+
+        return appSecret;
+    }
+}