diff --git a/Dockerfile b/Dockerfile index 2967b5c..3f950cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ FROM java:8 + MAINTAINER king <1609724385@qq.com> EXPOSE 8102 VOLUME /tmp diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/controller/IotController.java b/src/main/java/com/ssjl/zhaobiao/guizhou/controller/IotController.java index 47b4374..b2f2715 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/controller/IotController.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/controller/IotController.java @@ -98,13 +98,22 @@ public class IotController { byte[] nid = { 0x36, 0x14}; cdma.setNID(nid); + int power = 50; + GpsDeviceStatus gpsDeviceStatus = gpsDeviceStatusMapper.selectByImei(imei); + if(gpsDeviceStatus != null){ + String statusStr = gpsDeviceStatus.getDeviceStatus(); + IOTDeviceStatus status = IOTDeviceStatus.build(statusStr); + power = status.getBattery(); + } + GZDeviceStatus deviceStatus = new GZDeviceStatus(); deviceStatus.setOpenFirst(true); GZDevicePower devicePower = new GZDevicePower(); devicePower.setCharge(false); - devicePower.setPower(10); - GZAskLocation askLocation = new GZAskLocation(imei, 0,0,0,1,0,0, - 0,0,0,0, deviceStatus, devicePower, 0, 0, true, extend); + devicePower.setPower(power); + LocalDateTime time = LocalDateTime.now(); + GZAskLocation askLocation = new GZAskLocation(imei, time.getHour(),time.getMinute(),time.getSecond(),time.getDayOfMonth(),15976140,0, + 63968668,0,0,0, deviceStatus, devicePower, 0, 0, true, extend); GZRequest req = new GZRequest(); req.setImei(imei); @@ -113,6 +122,7 @@ public class IotController { req.setContent(askLocation); byte[] res = httpUtil.send(imei, "", req); System.out.println(ByteUtil.bytesToHexString(res)); + // 调用IOTAPI激活设备 log.info(imei + "激活设备"); IotApiActiveDevice active = new IotApiActiveDevice(); @@ -122,7 +132,7 @@ public class IotController { System.out.println(JSON.toJSONString(rs)); log.info(imei + "激活返回:" + JSON.toJSONString(rs)); // 处理电信返回数据 - res = (byte[]) responseHandle.process(res); + res = (byte[]) responseHandle.process(imei, res); System.out.println(ByteUtil.bytesToHexString(res)); log.info(imei + "电信返回:" + ByteUtil.bytesToHexString(res)); return "success"; @@ -299,4 +309,29 @@ public class IotController { List interval = GZLocationInterval.build(locationInterval); return GZLocationInterval.isIn(LocalDateTime.now(), interval); } + + + @RequestMapping("/call") + public String callHandle(@RequestBody IOTCall call, String imei) throws IOException { + + if(!checkImei(imei, "/call", JSON.toJSONString(call))){ + log.info(imei + ",wifi not in device"); + return "not in device"; + } + DianxinGzDeviceConfig gzDeviceConfig = dianxinGzDeviceConfigMapper.selectByImei(imei); + + log.info(imei + ",call ,v=" + JSON.toJSONString(call)); + GZUpCall calls=new GZUpCall(); + calls.setPhoneNumber(call.getPhoneNumber()); + calls.setDateTime(call.getDateTime()); + calls.setCallFlag(call.getCallFlag()); + call.setDuration(call.getDuration()); + byte[] res = httpUtil.send(imei, gzDeviceConfig.getPhone(), calls); + System.out.println(ByteUtil.bytesToHexString(res)); + log.info(imei + ",call 电信返回:" + ByteUtil.bytesToHexString(res)); + return "success"; + } + + + } diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/entity/GZMessage/GZUpCall.java b/src/main/java/com/ssjl/zhaobiao/guizhou/entity/GZMessage/GZUpCall.java new file mode 100644 index 0000000..2b43abb --- /dev/null +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/entity/GZMessage/GZUpCall.java @@ -0,0 +1,105 @@ +package com.ssjl.zhaobiao.guizhou.entity.GZMessage; + +import com.ssjl.zhaobiao.guizhou.entity.GZRequestStatus; +import com.ssjl.zhaobiao.guizhou.entity.IMessageContent; +import com.ssjl.zhaobiao.guizhou.utils.ByteUtil; +import com.ssjl.zhaobiao.guizhou.utils.GZUtil; + +public class GZUpCall implements IMessageContent { + + /** + * 手机号 + */ + private String phoneNumber; + /** + * 通话类型 1 CallOut 0 CallIn + */ + private int callFlag;// + /** + * 通话时间 + */ + private String dateTime; + /** + * 通话时长 + */ + private int duration; + + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public int getCallFlag() { + return callFlag; + } + + public void setCallFlag(int callFlag) { + this.callFlag = callFlag; + } + + public String getDateTime() { + return dateTime; + } + + public void setDateTime(String dateTime) { + this.dateTime = dateTime; + } + + public int getDuration() { + return duration; + } + + public void setDuration(int duration) { + this.duration = duration; + } + + @Override + public IMessageContent create(byte[] bytes) { + return null; + } + + @Override + public int getTag() { + return 0x21; + } + + @Override + public byte[] process(String deviceFlag, String flagType, byte msgIndex, GZRequestStatus requestStatus) { + return new byte[0]; + } + + @Override + public byte[] toBytes() { + byte[] list = new byte[18]; + int i=0; + list[i++] = (byte)getTag(); + byte[] phone=GZUtil.phoneToByte(phoneNumber); + System.arraycopy(phone, 0, list, i, phone.length); + i+=phone.length; + if(callFlag ==1&& duration >0){ + list[i++] = (byte)0x00; + } + else if(callFlag ==1&& duration ==0){ + list[i++] = (byte)0x01; + } + else if(callFlag ==0&& duration >0){ + list[i++] = (byte)0x02; + } + else if(callFlag ==0&& duration ==0){ + list[i++] = (byte)0x03; + } + else { + list[i++] = (byte)0x04; + } + byte[] duration= ByteUtil.toByte(this.duration, 2); + System.arraycopy(duration, 0, list, i, duration.length); + i+=duration.length; + byte[] time=ByteUtil.hexToByteArray(dateTime); + System.arraycopy(time, 0, list, i, time.length); + return list; + } +} diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/entity/GZResponse.java b/src/main/java/com/ssjl/zhaobiao/guizhou/entity/GZResponse.java index e135647..cd0fc8c 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/entity/GZResponse.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/entity/GZResponse.java @@ -1,5 +1,10 @@ package com.ssjl.zhaobiao.guizhou.entity; +import com.google.common.base.Strings; +import com.ssjl.zhaobiao.guizhou.utils.GZUtil; + +import java.util.Arrays; + public class GZResponse { private byte tag; @@ -14,11 +19,23 @@ public class GZResponse { private byte check; + private String phone; + + + public GZResponse(){ tag = (byte)0x7E; flag = (byte)0xFF; } + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + public String getImei() { return imei; } @@ -42,4 +59,25 @@ public class GZResponse { public void setErrorCode(GZResponseStatus errorCode) { this.errorCode = errorCode; } + + public byte[] toBytes(){ + byte[] list = new byte[14]; + int i = 0; + list[i++] = tag; + list[i++] = flag; + byte[] bytes; + if(Strings.isNullOrEmpty(imei)){ + bytes = GZUtil.imeiToByte(phone); + }else{ + bytes = GZUtil.imeiToByte(imei); + } + System.arraycopy(bytes, 0, list, i, bytes.length); + i += bytes.length; + list[i++] = (byte)index; + list[i++] = (byte)errorCode.getCode(); + list[i++] = GZUtil.check(Arrays.copyOfRange(list, 1, 12)); + list[i++] = tag; + return list; + } + } diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/entity/IOT/IOTCall.java b/src/main/java/com/ssjl/zhaobiao/guizhou/entity/IOT/IOTCall.java new file mode 100644 index 0000000..99c3f30 --- /dev/null +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/entity/IOT/IOTCall.java @@ -0,0 +1,40 @@ +package com.ssjl.zhaobiao.guizhou.entity.IOT; + +public class IOTCall { + private String phoneNumber; + private int callFlag;//1 CallOut 0 CallIn + private String dateTime; + private int duration; + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public int getCallFlag() { + return callFlag; + } + + public void setCallFlag(int callFlag) { + this.callFlag = callFlag; + } + + public String getDateTime() { + return dateTime; + } + + public void setDateTime(String dateTime) { + this.dateTime = dateTime; + } + + public int getDuration() { + return duration; + } + + public void setDuration(int duration) { + this.duration = duration; + } +} diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/handle/GZResponseHandle.java b/src/main/java/com/ssjl/zhaobiao/guizhou/handle/GZResponseHandle.java index c03aef9..0c7064a 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/handle/GZResponseHandle.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/handle/GZResponseHandle.java @@ -1,23 +1,26 @@ package com.ssjl.zhaobiao.guizhou.handle; -import com.ssjl.zhaobiao.guizhou.entity.GZDeviceFlagType; -import com.ssjl.zhaobiao.guizhou.entity.GZRequestStatus; -import com.ssjl.zhaobiao.guizhou.entity.IMessageContent; +import com.ssjl.zhaobiao.guizhou.entity.*; import com.ssjl.zhaobiao.guizhou.service.IGZPlatformService; import com.ssjl.zhaobiao.guizhou.utils.ByteUtil; +import com.ssjl.zhaobiao.guizhou.utils.GZHttpUtil; import com.ssjl.zhaobiao.guizhou.utils.GZUtil; +import lombok.extern.slf4j.Slf4j; import org.checkerframework.checker.units.qual.C; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.io.IOException; +@Slf4j @Component public class GZResponseHandle { @Autowired GZServiceFactory serviceFactory; + @Autowired + GZHttpUtil gzHttpUtil; - public Object process(byte[] res) throws IOException { + public Object process(String sourceImei, byte[] res) throws IOException { if(res[1] == 0xFF){ // 常规应答 @@ -36,9 +39,10 @@ public class GZResponseHandle { String deviceFlag = GZUtil.byteToDeviceFlag(imeiBytes); GZDeviceFlagType flagType = GZDeviceFlagType.IMEI; String[] flags = deviceFlag.split(","); - if(flags.length > 1){ + String phone = ""; + if(flags.length > 1 && flags[1].equals("phone")){ deviceFlag = flags[0]; - flagType = flags[1].equals("phone") ? GZDeviceFlagType.PHONE : GZDeviceFlagType.IMEI; + phone = flags[0]; } // 消息序列号 @@ -52,10 +56,20 @@ public class GZResponseHandle { System.arraycopy(res, 14, msgBytes, 0, msgBytes.length); IMessageContent content = GZMessageContentFactory.build(msgType, msgBytes); IGZPlatformService service = serviceFactory.getService(msgType); + Object serviceRs = new byte[0]; if(service != null){ - return service.process(content, deviceFlag, flagType, msgIndex, status); + serviceRs = service.process(content, sourceImei, phone, msgIndex, status); } - return new byte[0]; + // 应答 + GZResponse gzRs = new GZResponse(); + gzRs.setIndex(msgIndex); + gzRs.setPhone(phone); + gzRs.setImei(sourceImei); + gzRs.setErrorCode(GZResponseStatus.RECEIVE_SUCCESS); + log.info("应答报文:" + ByteUtil.bytesToHexString(gzRs.toBytes())); + byte[] responseRs = gzHttpUtil.send(gzRs.getImei(), gzRs.getPhone(), gzRs); + log.info("应答回复:" + ByteUtil.bytesToHexString(responseRs)); + return serviceRs; // byte[] result = content.process(deviceFlag, flagType, msgIndex, status); } diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZHeartJob.java b/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZHeartJob.java index a01aa45..d4105e0 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZHeartJob.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZHeartJob.java @@ -53,7 +53,7 @@ public class GZHeartJob extends QuartzJobBean { heart.setPower(power); GZDeviceStatus gzStatus = new GZDeviceStatus(); heart.setStatus(gzStatus); - heart.setSignalIntensity(50); + heart.setSignalIntensity(70); try { byte[] res = httpUtil.send(imei, phone, heart); // System.out.println(ByteUtil.bytesToHexString(res)); diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZSyncSetting.java b/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZSyncSetting.java index b90a6bf..572c20e 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZSyncSetting.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZSyncSetting.java @@ -39,7 +39,7 @@ public class GZSyncSetting extends QuartzJobBean { try { byte[] res = httpUtil.send(device.getImei(), device.getPhone(), askSetting); // System.out.println(ByteUtil.bytesToHexString(res)); - res = (byte[]) responseHandle.process(res); + res = (byte[]) responseHandle.process(device.getImei(), res); // System.out.println(ByteUtil.bytesToHexString(res)); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/service/IGZPlatformService.java b/src/main/java/com/ssjl/zhaobiao/guizhou/service/IGZPlatformService.java index 9992d95..b9c2ad3 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/service/IGZPlatformService.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/service/IGZPlatformService.java @@ -8,5 +8,5 @@ import java.io.IOException; public interface IGZPlatformService { - Object process(IMessageContent msg, String deviceFlag, GZDeviceFlagType flagType, byte msgIndex, GZRequestStatus requestStatus) throws IOException; + Object process(IMessageContent msg, String imei, String phone, byte msgIndex, GZRequestStatus requestStatus) throws IOException; } diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/service/impl/GZPlatformCmdService.java b/src/main/java/com/ssjl/zhaobiao/guizhou/service/impl/GZPlatformCmdService.java index 52a2940..1c6874b 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/service/impl/GZPlatformCmdService.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/service/impl/GZPlatformCmdService.java @@ -1,5 +1,6 @@ package com.ssjl.zhaobiao.guizhou.service.impl; +import com.google.common.base.Strings; import com.ssjl.zhaobiao.guizhou.entity.*; import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZPlatformCmd; import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZUpDeviceConfig; @@ -35,7 +36,7 @@ public class GZPlatformCmdService implements IGZPlatformCmdService { private GZHttpUtil httpUtil; @Override - public Object process(IMessageContent msg, String deviceFlag, GZDeviceFlagType flagType, byte msgIndex, GZRequestStatus requestStatus) throws IOException { + public Object process(IMessageContent msg, String imei, String phone, byte msgIndex, GZRequestStatus requestStatus) throws IOException { GZPlatformCmd cmd = (GZPlatformCmd) msg; if(cmd.getUpLocation() != null){ // 上报位置信息 @@ -44,17 +45,16 @@ public class GZPlatformCmdService implements IGZPlatformCmdService { if(cmd.getUpSetting() != null){ // 上报设置参数 // 先查询参数 - DianxinGzDeviceConfig gzConfig = null; - if(flagType == GZDeviceFlagType.IMEI){ - gzConfig = gzDeviceConfigMapper.selectByImei(deviceFlag); + if(Strings.isNullOrEmpty(phone)){ + gzConfig = gzDeviceConfigMapper.selectByImei(imei); }else{ - gzConfig = gzDeviceConfigMapper.selectByPhone(deviceFlag); + gzConfig = gzDeviceConfigMapper.selectByPhone(phone); } if(gzConfig == null){ gzConfig = new DianxinGzDeviceConfig(); - gzConfig.setDeviceImei(flagType == GZDeviceFlagType.IMEI ? deviceFlag : ""); - gzConfig.setPhone(flagType == GZDeviceFlagType.PHONE ? deviceFlag : ""); + gzConfig.setDeviceImei(imei); + gzConfig.setPhone(phone); } GpsDeviceConfig dbConfig = configMapper.selectByPrimaryKey(gzConfig.getDeviceImei()); diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/service/impl/GZPlatformSettingService.java b/src/main/java/com/ssjl/zhaobiao/guizhou/service/impl/GZPlatformSettingService.java index 3b687f5..5036161 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/service/impl/GZPlatformSettingService.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/service/impl/GZPlatformSettingService.java @@ -1,6 +1,7 @@ package com.ssjl.zhaobiao.guizhou.service.impl; import com.alibaba.fastjson.JSON; +import com.google.common.base.Strings; import com.ssjl.zhaobiao.guizhou.entity.DianxinGzDeviceConfig; import com.ssjl.zhaobiao.guizhou.entity.GZDeviceFlagType; import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocationInterval; @@ -27,24 +28,21 @@ public class GZPlatformSettingService implements IGZPlatformSettingService { IOTApiUtil iotApiUtil; @Override - public Object process(IMessageContent msg, String deviceFlag, GZDeviceFlagType flagType, byte msgIndex, GZRequestStatus requestStatus) throws IOException { + public Object process(IMessageContent msg, String imei, String phone, byte msgIndex, GZRequestStatus requestStatus) throws IOException { GZPlatformDeviceConfig config = (GZPlatformDeviceConfig)msg; DianxinGzDeviceConfig dbConfig = null; - String imei = ""; boolean isUpdate = true; - if(flagType == GZDeviceFlagType.PHONE){ - dbConfig = configMapper.selectByPhone(deviceFlag); - - }else{ - dbConfig = configMapper.selectByImei(deviceFlag); - imei = deviceFlag; - } + dbConfig = configMapper.selectByImei(imei); +// if(!Strings.isNullOrEmpty(phone)){ +// dbConfig = configMapper.selectByPhone(phone); +// }else{ +// dbConfig = configMapper.selectByImei(imei); +// } if(dbConfig == null){ dbConfig = new DianxinGzDeviceConfig(); dbConfig.setDeviceImei(imei); + dbConfig.setPhone(phone); isUpdate = false; - }else{ - imei = dbConfig.getDeviceImei(); } boolean allSuccess = true; // 下发给iot接口 @@ -114,30 +112,76 @@ public class GZPlatformSettingService implements IGZPlatformSettingService { } } // 亲情号码 - if(dbConfig.getAffectionPhone() == null || !dbConfig.getAffectionPhone().equals(config.getAffectionPhone())){ + IotApiWhiteList whiteList = new IotApiWhiteList(); + whiteList.setSerialNo(imei); + if(dbConfig.getAffectionPhone() == null || !dbConfig.getAffectionPhone().equals(config.getAffectionPhone()) || + dbConfig.getAddressBook() == null || !dbConfig.getAddressBook().equals(config.getAddressBook())){ // if(true){ + // SOS + String sos = config.getSosPhone(); + if(!Strings.isNullOrEmpty(sos)){ + if(sos.indexOf("/") > -1){ + sos = sos.substring(0, sos.indexOf("/")); + } + for (int i = 0; i < whiteList.getWhiteList().size(); i++) { + IotApiWhiteList.IotApiWhiteListItem item = whiteList.getWhiteList().get(i); + if(item.getPhone().equals(sos)){ + item.setSos(1); + } + } + } + boolean hadSos = false; + boolean isSos = false; + String[] phones = config.getAffectionPhone().split(","); - IotApiWhiteList whiteList = new IotApiWhiteList(); - whiteList.setSerialNo(imei); + for (int i = 0; i < phones.length; i++) { - String phone = phones[i]; + String aphone = phones[i]; String relationship = ""; - if(phone.indexOf("/") > -1){ - String[] pstrs = phone.split("/"); - phone = pstrs[0]; + if(aphone.indexOf("/") > -1){ + String[] pstrs = aphone.split("/"); + aphone = pstrs[0]; relationship = UnicodeUtil.unicodeToCn(pstrs[1]); } - whiteList.addPhone(phone, relationship, String.valueOf(i + 1), i == 0 ? 1 : 0); + isSos = aphone.equals(sos); + hadSos = hadSos ? hadSos : isSos; + whiteList.addPhone(aphone, relationship , String.valueOf(i + 1), (isSos? 1 : 0)); } - IotApiResponse phoneRs = iotApiUtil.setWhiteList(whiteList); - System.out.println(JSON.toJSONString(phoneRs)); - if(checkOffline(phoneRs.getMessage())){ - allSuccess = false; + // 通讯录 + phones = config.getAddressBook().split(","); + for (int i = 0; i < phones.length; i++) { + String aphone = phones[i]; + String relationship = ""; + if(aphone.indexOf("/") > -1){ + String[] pstrs = aphone.split("/"); + aphone = pstrs[0]; + relationship = UnicodeUtil.unicodeToCn(pstrs[1]); + } + isSos = aphone.equals(sos); + hadSos = hadSos ? hadSos : isSos; + whiteList.addPhone(aphone, relationship, "", (isSos? 1 : 0)); } - } + // sos不在通讯录或亲情号码中,则另外加入白名单 + if(!hadSos){ + whiteList.addPhone(sos, "", "", 1); + } + if(whiteList.getWhiteList().size() > 0){ + IotApiResponse phoneRs = iotApiUtil.setWhiteList(whiteList); + System.out.println(JSON.toJSONString(phoneRs)); + if(checkOffline(phoneRs.getMessage())){ + allSuccess = false; + } + } + } + + + + + if(allSuccess){ // 存入数据库 + dbConfig.setDeviceImei(imei); dbConfig.setPhone(config.getDevicePhone()); dbConfig.setHttpIp(config.getHttpIp()); dbConfig.setHttpUrl(config.getHttpUrl()); @@ -161,9 +205,10 @@ public class GZPlatformSettingService implements IGZPlatformSettingService { dbConfig.setRfid(config.getRfid()); if(isUpdate){ configMapper.updateByPrimaryKey(dbConfig); - }else{ - configMapper.insert(dbConfig); } +// else{ +// configMapper.insert(dbConfig); +// } } return new byte[0]; diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/utils/GZHttpUtil.java b/src/main/java/com/ssjl/zhaobiao/guizhou/utils/GZHttpUtil.java index a2a252c..d72b881 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/utils/GZHttpUtil.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/utils/GZHttpUtil.java @@ -2,6 +2,7 @@ package com.ssjl.zhaobiao.guizhou.utils; import com.ssjl.zhaobiao.guizhou.entity.GZRequest; import com.ssjl.zhaobiao.guizhou.entity.GZRequestStatus; +import com.ssjl.zhaobiao.guizhou.entity.GZResponse; import com.ssjl.zhaobiao.guizhou.entity.IMessageContent; import okhttp3.Headers; import org.springframework.beans.factory.annotation.Autowired; @@ -37,4 +38,16 @@ public class GZHttpUtil { req.setStatus(GZRequestStatus.RESPONSE_ALL); return send(imei, phone, req); } + + public byte[] send(String imei, String phone, GZResponse req) throws IOException { + Headers headers = new Headers.Builder().add("meid-id", imei).add("imsi-id", phone).build(); + byte[] b = req.toBytes(); + try { + byte[] res = httpUtil.postBytes(url, b, headers); + return res; + } catch (IOException e) { + e.printStackTrace(); + throw e; + } + } } diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/utils/GZUtil.java b/src/main/java/com/ssjl/zhaobiao/guizhou/utils/GZUtil.java index 19c2796..c8f8a19 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/utils/GZUtil.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/utils/GZUtil.java @@ -168,6 +168,24 @@ public class GZUtil { } return ByteUtil.hexToByteArray(hex); } + public static byte[] phoneToByte(String phone){ + String hex; + if(phone.length() <= 15){ + hex = phone + "F"; + while (hex .length() < 16){ + hex = hex + "F"; + } + }else{ + BigInteger num = new BigInteger(phone); + hex = num.toString(16); + hex += "E"; + while (hex .length() < 16){ + hex = "0" + hex; + } + } + + return ByteUtil.hexToByteArray(hex); + } /** * 获得终端号码,可能是手机号,也可能是IMEI diff --git a/src/main/resources/application-pro1.properties b/src/main/resources/application-pro1.properties index 3da7080..24fde57 100644 --- a/src/main/resources/application-pro1.properties +++ b/src/main/resources/application-pro1.properties @@ -49,7 +49,7 @@ guizhou.device.version=ACB_1001 #guizhou.device.model=TPE390 #guizhou.device.version=TPE_0056 guizhou.http.url=http://202.105.147.30:24183 -guizhou.device.testList= [{ "imei": "862622050253671","phone": "18664272743" },{ "imei": "862622050253358","phone": "" },{ "imei": "800115470000678","phone": "13500259054" }] +guizhou.device.testList= [{ "imei": "862622050253671","phone": "" },{ "imei": "862622050253358","phone": "" },{ "imei": "800115470000678","phone": "" }] guizhou.device.zhizhong=862622050654340,862622050317740 guizhou.device.zhanneng=862622050925104,862622050927027 guizhou.device.tianbo=862622050253671,862622050253358,800115470000678 diff --git a/src/main/resources/application-pro2.properties b/src/main/resources/application-pro2.properties index 99e0fea..9a9bbd8 100644 --- a/src/main/resources/application-pro2.properties +++ b/src/main/resources/application-pro2.properties @@ -49,7 +49,7 @@ guizhou.factory=zhanneng guizhou.device.model=TPE390 guizhou.device.version=TPE_0056 guizhou.http.url=http://202.105.147.30:24183 -guizhou.device.testList= [{ "imei": "862622050253671","phone": "18664272743" },{ "imei": "862622050253358","phone": "" },{ "imei": "800115470000678","phone": "13500259054" }] +guizhou.device.testList= [{ "imei": "862622050925104","phone": "" },{ "imei": "862622050927027","phone": "" }] guizhou.device.zhizhong=862622050654340,862622050317740 guizhou.device.zhanneng=862622050925104,862622050927027 guizhou.device.tianbo=862622050253671,862622050253358,800115470000678 diff --git a/src/main/resources/application-pro3.properties b/src/main/resources/application-pro3.properties index a3cb65b..d4785c3 100644 --- a/src/main/resources/application-pro3.properties +++ b/src/main/resources/application-pro3.properties @@ -49,7 +49,7 @@ guizhou.device.version=RZL_2021 #guizhou.device.model=TPE390 #guizhou.device.version=TPE_0056 guizhou.http.url=http://202.105.147.30:24183 -guizhou.device.testList= [{ "imei": "862622050253671","phone": "18664272743" },{ "imei": "862622050253358","phone": "" },{ "imei": "800115470000678","phone": "13500259054" }] +guizhou.device.testList= [{ "imei": "862622050654340","phone": "" },{ "imei": "862622050317740","phone": "" }] guizhou.device.zhizhong=862622050654340,862622050317740 guizhou.device.zhanneng=862622050925104,862622050927027 guizhou.device.tianbo=862622050253671,862622050253358,800115470000678 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 5d3bb55..c879574 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -39,17 +39,24 @@ netty.port=8888 4g.api.token = 123Te1p0Te1p0321 # \u8D35\u5DDE\u7535\u4FE1\u53C2\u6570 guizhou.protocol=T01.4 -#guizhou.factory=telpo -#guizhou.device.model=TPS401 -#guizhou.device.version=ACB_1001 -guizhou.factory=zhizhong -guizhou.device.model=RZL600 -guizhou.device.version=RZL_2021 +guizhou.factory=telpo +guizhou.device.model=TPS401 +guizhou.device.version=ACB_1001 +#guizhou.factory=zhizhong +#guizhou.device.model=RZL600 +#guizhou.device.version=RZL_2021 #guizhou.factory=zhanneng #guizhou.device.model=TPE390 #guizhou.device.version=TPE_0056 guizhou.http.url=http://202.105.147.30:24183 -guizhou.device.testList= [{ "imei": "862622050253671","phone": "18664272743" },{ "imei": "862622050253358","phone": "" },{ "imei": "800115470000678","phone": "13500259054" }] +#\u5929\u6CE2 +#guizhou.device.testList= [{ "imei": "862622050253671","phone": "" },{ "imei": "862622050253358","phone": "" },{ "imei": "800115470000678","phone": "" }] +guizhou.device.testList= [{ "imei": "862622050253671","phone": "" }] +#\u667A\u4E2D +#guizhou.device.testList= [{ "imei": "862622050654340","phone": "" },{ "imei": "862622050317740","phone": "" }] +#\u5C55\u80FD +#guizhou.device.testList= [{ "imei": "862622050927027","phone": "" },{ "imei": "862622050925104","phone": "" }] + guizhou.device.zhizhong=862622050654340,862622050317740 guizhou.device.zhanneng=862622050925104,862622050927027 guizhou.device.tianbo=862622050253671,862622050253358,800115470000678 diff --git a/src/test/java/com/ssjl/zhaobiao/guizhou/CenterApplicationTests.java b/src/test/java/com/ssjl/zhaobiao/guizhou/CenterApplicationTests.java index b4763e8..7dd4747 100644 --- a/src/test/java/com/ssjl/zhaobiao/guizhou/CenterApplicationTests.java +++ b/src/test/java/com/ssjl/zhaobiao/guizhou/CenterApplicationTests.java @@ -197,4 +197,43 @@ class CenterApplicationTests { System.out.println(in); } + @Test + public void test4(){ + int tag=0x21; + String PhoneNumber="13439301795"; + int CallFlag=1; + int Duration=30; + String DateTime="2101141805"; + + //1 CallOut 0 CallIn + + byte[] list = new byte[18]; + int i=0; + list[i++] = (byte)tag; + byte[] phone=GZUtil.phoneToByte(PhoneNumber); + System.arraycopy(phone, 0, list, i, phone.length); + i+=phone.length; + if(CallFlag==1&&Duration>0){ + list[i++] = (byte)0x00; + } + else if(CallFlag==1&&Duration==0){ + list[i++] = (byte)0x01; + } + else if(CallFlag==0&&Duration>0){ + list[i++] = (byte)0x02; + } + else if(CallFlag==0&&Duration==0){ + list[i++] = (byte)0x03; + } + else { + list[i++] = (byte)0x04; + } + byte[] duration= ByteUtil.toByte(Duration, 2); + System.arraycopy(duration, 0, list, i, duration.length); + i+=duration.length; + byte[] time=ByteUtil.hexToByteArray(DateTime); + System.arraycopy(time, 0, list, i, time.length); + System.out.println(ByteUtil.bytesToHexString(list)); + } + }