|
|
@@ -0,0 +1,169 @@
|
|
|
+package org.dromara.util;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+
|
|
|
+import javax.crypto.Cipher;
|
|
|
+import java.security.Key;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+public class CabinetUtil {
|
|
|
+
|
|
|
+ private final static String appid = "bw_open_express_A8C848769E5C04E0";
|
|
|
+ private final static String appkey = "5AFC6E07CFCF4A359B775D1416A9799A";
|
|
|
+
|
|
|
+ private final static String hosts = "https://open.bestwond.com";
|
|
|
+
|
|
|
+
|
|
|
+ private static String byteArr2HexStr(byte[] arrB) throws Exception {
|
|
|
+ int iLen = arrB.length;
|
|
|
+ // 每个byte用两个字符才能表示,所以字符串的长度是数组长度的两倍
|
|
|
+ StringBuffer sb = new StringBuffer(iLen * 2);
|
|
|
+ for (int i = 0; i < iLen; i++) {
|
|
|
+ int intTmp = arrB[i];
|
|
|
+ // 把负数转换为正数
|
|
|
+ while (intTmp < 0) {
|
|
|
+ intTmp = intTmp + 256;
|
|
|
+ }
|
|
|
+ // 小于0F的数需要在前面补0
|
|
|
+ if (intTmp < 16) {
|
|
|
+ sb.append("0");
|
|
|
+ }
|
|
|
+ sb.append(Integer.toString(intTmp, 16));
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String encrypt(String strIn) throws Exception {
|
|
|
+ return byteArr2HexStr(encrypt(strIn.getBytes("UTF-8")));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static byte[] encrypt(byte[] arrB) throws Exception {
|
|
|
+ Key key = getKey(appkey.getBytes("UTF-8"));
|
|
|
+ Cipher encryptCipher = Cipher.getInstance("DES");
|
|
|
+ encryptCipher.init(Cipher.ENCRYPT_MODE, key);
|
|
|
+ return encryptCipher.doFinal(arrB);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Key getKey(byte[] arrBTmp) throws Exception {
|
|
|
+ // 创建一个空的8位字节数组(默认值为0)
|
|
|
+ byte[] arrB = new byte[8];
|
|
|
+ // 将原始字节数组转换为8位
|
|
|
+ for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
|
|
|
+ arrB[i] = arrBTmp[i];
|
|
|
+ }
|
|
|
+ // 生成密钥
|
|
|
+ Key key = new javax.crypto.spec.SecretKeySpec(arrB, "DES");
|
|
|
+ return key;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 获取柜子信息
|
|
|
+ public static String getCabinetInfo(String cabinetCode) throws Exception {
|
|
|
+ int times = (int) (DateUtil.date().getTime()/1000);
|
|
|
+ String str_sign = appid + "=" + times + "=" + appid;
|
|
|
+ str_sign = encrypt(str_sign);
|
|
|
+
|
|
|
+ String result3= HttpRequest.post(hosts+"/kd/api/v2/action/device_info/").body(JSON.toJSONString(Map.of("device_number",cabinetCode)))
|
|
|
+ .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
|
|
|
+ .execute().body();
|
|
|
+ return result3;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取柜子统计
|
|
|
+ public static String getCabinetStatistics(String cabinetCode,String startTime,String endTime) throws Exception {
|
|
|
+ int times = (int) (DateUtil.date().getTime()/1000);
|
|
|
+ String str_sign = appid + "=" + times + "=" + appid;
|
|
|
+ str_sign = encrypt(str_sign);
|
|
|
+
|
|
|
+ String result3= HttpRequest.post(hosts + "/kd/api/v2/action/deliver_statistics/").body(JSON.toJSONString(Map.of("device_number",cabinetCode,"strat_time",startTime,"end_time",endTime)))
|
|
|
+ .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
|
|
|
+ .execute().body();
|
|
|
+ return result3;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取柜子盒子
|
|
|
+ public static String getCabinetBoxs(String cabinetCode) throws Exception {
|
|
|
+ int times = (int) (DateUtil.date().getTime()/1000);
|
|
|
+ String str_sign = appid + "=" + times + "=" + appid;
|
|
|
+ str_sign = encrypt(str_sign);
|
|
|
+
|
|
|
+ String result3= HttpRequest.post(hosts + "/kd/api/v2/action/box_info_list/").body(JSON.toJSONString(Map.of("device_number",cabinetCode)))
|
|
|
+ .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
|
|
|
+ .execute().body();
|
|
|
+ return result3;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开柜
|
|
|
+ public static String openCabinetBoxs(String cabinetCode,String lookAddr) throws Exception {
|
|
|
+ int times = (int) (DateUtil.date().getTime()/1000);
|
|
|
+ String str_sign = appid + "=" + times + "=" + appid;
|
|
|
+ str_sign = encrypt(str_sign);
|
|
|
+
|
|
|
+ String result3= HttpRequest.post(hosts + "/kd/api/v2/action/open_box/").body(JSON.toJSONString(Map.of("device_number",cabinetCode,"lock_address",lookAddr)))
|
|
|
+ .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
|
|
|
+ .execute().body();
|
|
|
+ return result3;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开所有柜
|
|
|
+ public static String openCabinetBoxAll(String cabinetCode) throws Exception {
|
|
|
+ int times = (int) (DateUtil.date().getTime()/1000);
|
|
|
+ String str_sign = appid + "=" + times + "=" + appid;
|
|
|
+ str_sign = encrypt(str_sign);
|
|
|
+
|
|
|
+ String result3= HttpRequest.post(hosts + "/kd/api/v2/action/open_box_all/").body(JSON.toJSONString(Map.of("device_number",cabinetCode)))
|
|
|
+ .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
|
|
|
+ .execute().body();
|
|
|
+ return result3;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //清理格子(不开启)
|
|
|
+ public static String clearCabinetBox(String cabinetCode,String boxUUId) throws Exception {
|
|
|
+ int times = (int) (DateUtil.date().getTime()/1000);
|
|
|
+ String str_sign = appid + "=" + times + "=" + appid;
|
|
|
+ str_sign = encrypt(str_sign);
|
|
|
+
|
|
|
+ String result3= HttpRequest.post(hosts + "/kd/api/v2/action/clear_box/").body(JSON.toJSONString(Map.of("device_number",cabinetCode,"box_uid",boxUUId)))
|
|
|
+ .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
|
|
|
+ .execute().body();
|
|
|
+ return result3;
|
|
|
+ }
|
|
|
+
|
|
|
+ //清理格子(开启)
|
|
|
+ public static String clearCabinetBoxOpen(String cabinetCode,String boxUUId) throws Exception {
|
|
|
+ int times = (int) (DateUtil.date().getTime()/1000);
|
|
|
+ String str_sign = appid + "=" + times + "=" + appid;
|
|
|
+ str_sign = encrypt(str_sign);
|
|
|
+
|
|
|
+ String result3= HttpRequest.post(hosts + "/kd/api/v2/action/clear_box/").body(JSON.toJSONString(Map.of("device_number",cabinetCode,"box_uid",boxUUId)))
|
|
|
+ .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
|
|
|
+ .execute().body();
|
|
|
+ return result3;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取取件码
|
|
|
+ public static String getQJM(String phone) throws Exception {
|
|
|
+ int times = (int) (DateUtil.date().getTime()/1000);
|
|
|
+ String str_sign = appid + "=" + times + "=" + appid;
|
|
|
+ str_sign = encrypt(str_sign);
|
|
|
+
|
|
|
+ String result3= HttpRequest.post(hosts + "/kd/api/v2/query/pick_code_by_user_mobile/").body(JSON.toJSONString(Map.of("get_user_mobile",phone)))
|
|
|
+ .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
|
|
|
+ .execute().body();
|
|
|
+ return result3;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|