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] =?UTF-8?q?=E8=AF=9D=E5=8D=95=E7=AC=AC=E4=BA=8C=E6=AC=A1?= =?UTF-8?q?=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)); + } + }