From 0674e66df915656e53ece1ae366872aeb5ddd127 Mon Sep 17 00:00:00 2001 From: yangl <284428564@QQ.com> Date: Thu, 14 Jan 2021 17:13:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guizhou/entity/GZMessage/GZUpCall.java | 82 +++++++++++++++++++ .../zhaobiao/guizhou/entity/IOT/IOTCall.java | 40 +++++++++ 2 files changed, 122 insertions(+) create mode 100644 src/main/java/com/ssjl/zhaobiao/guizhou/entity/GZMessage/GZUpCall.java create mode 100644 src/main/java/com/ssjl/zhaobiao/guizhou/entity/IOT/IOTCall.java 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..bac19db --- /dev/null +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/entity/GZMessage/GZUpCall.java @@ -0,0 +1,82 @@ +package com.ssjl.zhaobiao.guizhou.entity.GZMessage; + +import com.ssjl.zhaobiao.guizhou.entity.GZRequestStatus; +import com.ssjl.zhaobiao.guizhou.entity.IMessageContent; + +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) { + PhoneNumber = phoneNumber; + } + + public int getCallFlag() { + return CallFlag; + } + + public void setCallFlag(int callFlag) { + CallFlag = callFlag; + } + + public String getDateTime() { + return DateTime; + } + + public void setDateTime(String dateTime) { + DateTime = dateTime; + } + + public int getDuration() { + return Duration; + } + + public void setDuration(int duration) { + 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() { + + + + return new byte[0]; + } +} 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..98ce5d3 --- /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) { + PhoneNumber = phoneNumber; + } + + public int getCallFlag() { + return CallFlag; + } + + public void setCallFlag(int callFlag) { + CallFlag = callFlag; + } + + public String getDateTime() { + return DateTime; + } + + public void setDateTime(String dateTime) { + DateTime = dateTime; + } + + public int getDuration() { + return Duration; + } + + public void setDuration(int duration) { + Duration = duration; + } +} From dfe3beb25d0ca6402282012dafa98639476ac139 Mon Sep 17 00:00:00 2001 From: yangl <284428564@QQ.com> Date: Thu, 14 Jan 2021 19:18:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=AF=9D=E5=8D=95=E7=AC=AC=E4=BA=8C?= =?UTF-8?q?=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guizhou/controller/IotController.java | 28 +++++++++++++ .../guizhou/entity/GZMessage/GZUpCall.java | 35 ++++++++++++++--- .../guizhou/CenterApplicationTests.java | 39 +++++++++++++++++++ 3 files changed, 96 insertions(+), 6 deletions(-) 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 173df35..5766a6d 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/controller/IotController.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/controller/IotController.java @@ -300,4 +300,32 @@ 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); + if(!isAtLocationTime(gzDeviceConfig.getLocationInterval())){ + log.info(imei + ",wifi not in time"); + return "not in time"; + } + 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 index bac19db..837f068 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/entity/GZMessage/GZUpCall.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/entity/GZMessage/GZUpCall.java @@ -2,6 +2,8 @@ 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 { @@ -67,16 +69,37 @@ public class GZUpCall implements IMessageContent { @Override public byte[] process(String deviceFlag, String flagType, byte msgIndex, GZRequestStatus requestStatus) { - - return new byte[0]; } @Override public byte[] toBytes() { - - - - return new byte[0]; + 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(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/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)); + } + }