@@ -1,4 +1,5 @@ | |||||
FROM java:8 | FROM java:8 | ||||
MAINTAINER king <1609724385@qq.com> | MAINTAINER king <1609724385@qq.com> | ||||
EXPOSE 8102 | EXPOSE 8102 | ||||
VOLUME /tmp | VOLUME /tmp | ||||
@@ -98,13 +98,22 @@ public class IotController { | |||||
byte[] nid = { 0x36, 0x14}; | byte[] nid = { 0x36, 0x14}; | ||||
cdma.setNID(nid); | 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(); | GZDeviceStatus deviceStatus = new GZDeviceStatus(); | ||||
deviceStatus.setOpenFirst(true); | deviceStatus.setOpenFirst(true); | ||||
GZDevicePower devicePower = new GZDevicePower(); | GZDevicePower devicePower = new GZDevicePower(); | ||||
devicePower.setCharge(false); | 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(); | GZRequest req = new GZRequest(); | ||||
req.setImei(imei); | req.setImei(imei); | ||||
@@ -113,6 +122,7 @@ public class IotController { | |||||
req.setContent(askLocation); | req.setContent(askLocation); | ||||
byte[] res = httpUtil.send(imei, "", req); | byte[] res = httpUtil.send(imei, "", req); | ||||
System.out.println(ByteUtil.bytesToHexString(res)); | System.out.println(ByteUtil.bytesToHexString(res)); | ||||
// 调用IOTAPI激活设备 | // 调用IOTAPI激活设备 | ||||
log.info(imei + "激活设备"); | log.info(imei + "激活设备"); | ||||
IotApiActiveDevice active = new IotApiActiveDevice(); | IotApiActiveDevice active = new IotApiActiveDevice(); | ||||
@@ -122,7 +132,7 @@ public class IotController { | |||||
System.out.println(JSON.toJSONString(rs)); | System.out.println(JSON.toJSONString(rs)); | ||||
log.info(imei + "激活返回:" + 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)); | System.out.println(ByteUtil.bytesToHexString(res)); | ||||
log.info(imei + "电信返回:" + ByteUtil.bytesToHexString(res)); | log.info(imei + "电信返回:" + ByteUtil.bytesToHexString(res)); | ||||
return "success"; | return "success"; | ||||
@@ -299,4 +309,29 @@ public class IotController { | |||||
List<GZLocationInterval> interval = GZLocationInterval.build(locationInterval); | List<GZLocationInterval> interval = GZLocationInterval.build(locationInterval); | ||||
return GZLocationInterval.isIn(LocalDateTime.now(), interval); | 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"; | |||||
} | |||||
} | } |
@@ -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; | |||||
} | |||||
} |
@@ -1,5 +1,10 @@ | |||||
package com.ssjl.zhaobiao.guizhou.entity; | 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 { | public class GZResponse { | ||||
private byte tag; | private byte tag; | ||||
@@ -14,11 +19,23 @@ public class GZResponse { | |||||
private byte check; | private byte check; | ||||
private String phone; | |||||
public GZResponse(){ | public GZResponse(){ | ||||
tag = (byte)0x7E; | tag = (byte)0x7E; | ||||
flag = (byte)0xFF; | flag = (byte)0xFF; | ||||
} | } | ||||
public String getPhone() { | |||||
return phone; | |||||
} | |||||
public void setPhone(String phone) { | |||||
this.phone = phone; | |||||
} | |||||
public String getImei() { | public String getImei() { | ||||
return imei; | return imei; | ||||
} | } | ||||
@@ -42,4 +59,25 @@ public class GZResponse { | |||||
public void setErrorCode(GZResponseStatus errorCode) { | public void setErrorCode(GZResponseStatus errorCode) { | ||||
this.errorCode = 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; | |||||
} | |||||
} | } |
@@ -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; | |||||
} | |||||
} |
@@ -1,23 +1,26 @@ | |||||
package com.ssjl.zhaobiao.guizhou.handle; | 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.service.IGZPlatformService; | ||||
import com.ssjl.zhaobiao.guizhou.utils.ByteUtil; | import com.ssjl.zhaobiao.guizhou.utils.ByteUtil; | ||||
import com.ssjl.zhaobiao.guizhou.utils.GZHttpUtil; | |||||
import com.ssjl.zhaobiao.guizhou.utils.GZUtil; | import com.ssjl.zhaobiao.guizhou.utils.GZUtil; | ||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.checkerframework.checker.units.qual.C; | import org.checkerframework.checker.units.qual.C; | ||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
@Slf4j | |||||
@Component | @Component | ||||
public class GZResponseHandle { | public class GZResponseHandle { | ||||
@Autowired | @Autowired | ||||
GZServiceFactory serviceFactory; | 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){ | if(res[1] == 0xFF){ | ||||
// 常规应答 | // 常规应答 | ||||
@@ -36,9 +39,10 @@ public class GZResponseHandle { | |||||
String deviceFlag = GZUtil.byteToDeviceFlag(imeiBytes); | String deviceFlag = GZUtil.byteToDeviceFlag(imeiBytes); | ||||
GZDeviceFlagType flagType = GZDeviceFlagType.IMEI; | GZDeviceFlagType flagType = GZDeviceFlagType.IMEI; | ||||
String[] flags = deviceFlag.split(","); | String[] flags = deviceFlag.split(","); | ||||
if(flags.length > 1){ | |||||
String phone = ""; | |||||
if(flags.length > 1 && flags[1].equals("phone")){ | |||||
deviceFlag = flags[0]; | 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); | System.arraycopy(res, 14, msgBytes, 0, msgBytes.length); | ||||
IMessageContent content = GZMessageContentFactory.build(msgType, msgBytes); | IMessageContent content = GZMessageContentFactory.build(msgType, msgBytes); | ||||
IGZPlatformService service = serviceFactory.getService(msgType); | IGZPlatformService service = serviceFactory.getService(msgType); | ||||
Object serviceRs = new byte[0]; | |||||
if(service != null){ | 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); | // byte[] result = content.process(deviceFlag, flagType, msgIndex, status); | ||||
} | } | ||||
@@ -53,7 +53,7 @@ public class GZHeartJob extends QuartzJobBean { | |||||
heart.setPower(power); | heart.setPower(power); | ||||
GZDeviceStatus gzStatus = new GZDeviceStatus(); | GZDeviceStatus gzStatus = new GZDeviceStatus(); | ||||
heart.setStatus(gzStatus); | heart.setStatus(gzStatus); | ||||
heart.setSignalIntensity(50); | |||||
heart.setSignalIntensity(70); | |||||
try { | try { | ||||
byte[] res = httpUtil.send(imei, phone, heart); | byte[] res = httpUtil.send(imei, phone, heart); | ||||
// System.out.println(ByteUtil.bytesToHexString(res)); | // System.out.println(ByteUtil.bytesToHexString(res)); | ||||
@@ -39,7 +39,7 @@ public class GZSyncSetting extends QuartzJobBean { | |||||
try { | try { | ||||
byte[] res = httpUtil.send(device.getImei(), device.getPhone(), askSetting); | byte[] res = httpUtil.send(device.getImei(), device.getPhone(), askSetting); | ||||
// System.out.println(ByteUtil.bytesToHexString(res)); | // System.out.println(ByteUtil.bytesToHexString(res)); | ||||
res = (byte[]) responseHandle.process(res); | |||||
res = (byte[]) responseHandle.process(device.getImei(), res); | |||||
// System.out.println(ByteUtil.bytesToHexString(res)); | // System.out.println(ByteUtil.bytesToHexString(res)); | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
@@ -8,5 +8,5 @@ import java.io.IOException; | |||||
public interface IGZPlatformService { | 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; | |||||
} | } |
@@ -1,5 +1,6 @@ | |||||
package com.ssjl.zhaobiao.guizhou.service.impl; | 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.*; | ||||
import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZPlatformCmd; | import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZPlatformCmd; | ||||
import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZUpDeviceConfig; | import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZUpDeviceConfig; | ||||
@@ -35,7 +36,7 @@ public class GZPlatformCmdService implements IGZPlatformCmdService { | |||||
private GZHttpUtil httpUtil; | private GZHttpUtil httpUtil; | ||||
@Override | @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; | GZPlatformCmd cmd = (GZPlatformCmd) msg; | ||||
if(cmd.getUpLocation() != null){ | if(cmd.getUpLocation() != null){ | ||||
// 上报位置信息 | // 上报位置信息 | ||||
@@ -44,17 +45,16 @@ public class GZPlatformCmdService implements IGZPlatformCmdService { | |||||
if(cmd.getUpSetting() != null){ | if(cmd.getUpSetting() != null){ | ||||
// 上报设置参数 | // 上报设置参数 | ||||
// 先查询参数 | // 先查询参数 | ||||
DianxinGzDeviceConfig gzConfig = null; | DianxinGzDeviceConfig gzConfig = null; | ||||
if(flagType == GZDeviceFlagType.IMEI){ | |||||
gzConfig = gzDeviceConfigMapper.selectByImei(deviceFlag); | |||||
if(Strings.isNullOrEmpty(phone)){ | |||||
gzConfig = gzDeviceConfigMapper.selectByImei(imei); | |||||
}else{ | }else{ | ||||
gzConfig = gzDeviceConfigMapper.selectByPhone(deviceFlag); | |||||
gzConfig = gzDeviceConfigMapper.selectByPhone(phone); | |||||
} | } | ||||
if(gzConfig == null){ | if(gzConfig == null){ | ||||
gzConfig = new DianxinGzDeviceConfig(); | 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()); | GpsDeviceConfig dbConfig = configMapper.selectByPrimaryKey(gzConfig.getDeviceImei()); | ||||
@@ -1,6 +1,7 @@ | |||||
package com.ssjl.zhaobiao.guizhou.service.impl; | package com.ssjl.zhaobiao.guizhou.service.impl; | ||||
import com.alibaba.fastjson.JSON; | import com.alibaba.fastjson.JSON; | ||||
import com.google.common.base.Strings; | |||||
import com.ssjl.zhaobiao.guizhou.entity.DianxinGzDeviceConfig; | import com.ssjl.zhaobiao.guizhou.entity.DianxinGzDeviceConfig; | ||||
import com.ssjl.zhaobiao.guizhou.entity.GZDeviceFlagType; | import com.ssjl.zhaobiao.guizhou.entity.GZDeviceFlagType; | ||||
import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocationInterval; | import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocationInterval; | ||||
@@ -27,24 +28,21 @@ public class GZPlatformSettingService implements IGZPlatformSettingService { | |||||
IOTApiUtil iotApiUtil; | IOTApiUtil iotApiUtil; | ||||
@Override | @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; | GZPlatformDeviceConfig config = (GZPlatformDeviceConfig)msg; | ||||
DianxinGzDeviceConfig dbConfig = null; | DianxinGzDeviceConfig dbConfig = null; | ||||
String imei = ""; | |||||
boolean isUpdate = true; | 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){ | if(dbConfig == null){ | ||||
dbConfig = new DianxinGzDeviceConfig(); | dbConfig = new DianxinGzDeviceConfig(); | ||||
dbConfig.setDeviceImei(imei); | dbConfig.setDeviceImei(imei); | ||||
dbConfig.setPhone(phone); | |||||
isUpdate = false; | isUpdate = false; | ||||
}else{ | |||||
imei = dbConfig.getDeviceImei(); | |||||
} | } | ||||
boolean allSuccess = true; | boolean allSuccess = true; | ||||
// 下发给iot接口 | // 下发给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){ | // 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(","); | String[] phones = config.getAffectionPhone().split(","); | ||||
IotApiWhiteList whiteList = new IotApiWhiteList(); | |||||
whiteList.setSerialNo(imei); | |||||
for (int i = 0; i < phones.length; i++) { | for (int i = 0; i < phones.length; i++) { | ||||
String phone = phones[i]; | |||||
String aphone = phones[i]; | |||||
String relationship = ""; | 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]); | 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){ | if(allSuccess){ | ||||
// 存入数据库 | // 存入数据库 | ||||
dbConfig.setDeviceImei(imei); | |||||
dbConfig.setPhone(config.getDevicePhone()); | dbConfig.setPhone(config.getDevicePhone()); | ||||
dbConfig.setHttpIp(config.getHttpIp()); | dbConfig.setHttpIp(config.getHttpIp()); | ||||
dbConfig.setHttpUrl(config.getHttpUrl()); | dbConfig.setHttpUrl(config.getHttpUrl()); | ||||
@@ -161,9 +205,10 @@ public class GZPlatformSettingService implements IGZPlatformSettingService { | |||||
dbConfig.setRfid(config.getRfid()); | dbConfig.setRfid(config.getRfid()); | ||||
if(isUpdate){ | if(isUpdate){ | ||||
configMapper.updateByPrimaryKey(dbConfig); | configMapper.updateByPrimaryKey(dbConfig); | ||||
}else{ | |||||
configMapper.insert(dbConfig); | |||||
} | } | ||||
// else{ | |||||
// configMapper.insert(dbConfig); | |||||
// } | |||||
} | } | ||||
return new byte[0]; | return new byte[0]; | ||||
@@ -2,6 +2,7 @@ package com.ssjl.zhaobiao.guizhou.utils; | |||||
import com.ssjl.zhaobiao.guizhou.entity.GZRequest; | import com.ssjl.zhaobiao.guizhou.entity.GZRequest; | ||||
import com.ssjl.zhaobiao.guizhou.entity.GZRequestStatus; | import com.ssjl.zhaobiao.guizhou.entity.GZRequestStatus; | ||||
import com.ssjl.zhaobiao.guizhou.entity.GZResponse; | |||||
import com.ssjl.zhaobiao.guizhou.entity.IMessageContent; | import com.ssjl.zhaobiao.guizhou.entity.IMessageContent; | ||||
import okhttp3.Headers; | import okhttp3.Headers; | ||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
@@ -37,4 +38,16 @@ public class GZHttpUtil { | |||||
req.setStatus(GZRequestStatus.RESPONSE_ALL); | req.setStatus(GZRequestStatus.RESPONSE_ALL); | ||||
return send(imei, phone, req); | 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; | |||||
} | |||||
} | |||||
} | } |
@@ -168,6 +168,24 @@ public class GZUtil { | |||||
} | } | ||||
return ByteUtil.hexToByteArray(hex); | 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 | * 获得终端号码,可能是手机号,也可能是IMEI | ||||
@@ -49,7 +49,7 @@ guizhou.device.version=ACB_1001 | |||||
#guizhou.device.model=TPE390 | #guizhou.device.model=TPE390 | ||||
#guizhou.device.version=TPE_0056 | #guizhou.device.version=TPE_0056 | ||||
guizhou.http.url=http://202.105.147.30:24183 | 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.zhizhong=862622050654340,862622050317740 | ||||
guizhou.device.zhanneng=862622050925104,862622050927027 | guizhou.device.zhanneng=862622050925104,862622050927027 | ||||
guizhou.device.tianbo=862622050253671,862622050253358,800115470000678 | guizhou.device.tianbo=862622050253671,862622050253358,800115470000678 | ||||
@@ -49,7 +49,7 @@ guizhou.factory=zhanneng | |||||
guizhou.device.model=TPE390 | guizhou.device.model=TPE390 | ||||
guizhou.device.version=TPE_0056 | guizhou.device.version=TPE_0056 | ||||
guizhou.http.url=http://202.105.147.30:24183 | 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.zhizhong=862622050654340,862622050317740 | ||||
guizhou.device.zhanneng=862622050925104,862622050927027 | guizhou.device.zhanneng=862622050925104,862622050927027 | ||||
guizhou.device.tianbo=862622050253671,862622050253358,800115470000678 | guizhou.device.tianbo=862622050253671,862622050253358,800115470000678 | ||||
@@ -49,7 +49,7 @@ guizhou.device.version=RZL_2021 | |||||
#guizhou.device.model=TPE390 | #guizhou.device.model=TPE390 | ||||
#guizhou.device.version=TPE_0056 | #guizhou.device.version=TPE_0056 | ||||
guizhou.http.url=http://202.105.147.30:24183 | 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.zhizhong=862622050654340,862622050317740 | ||||
guizhou.device.zhanneng=862622050925104,862622050927027 | guizhou.device.zhanneng=862622050925104,862622050927027 | ||||
guizhou.device.tianbo=862622050253671,862622050253358,800115470000678 | guizhou.device.tianbo=862622050253671,862622050253358,800115470000678 | ||||
@@ -39,17 +39,24 @@ netty.port=8888 | |||||
4g.api.token = 123Te1p0Te1p0321 | 4g.api.token = 123Te1p0Te1p0321 | ||||
# \u8D35\u5DDE\u7535\u4FE1\u53C2\u6570 | # \u8D35\u5DDE\u7535\u4FE1\u53C2\u6570 | ||||
guizhou.protocol=T01.4 | 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.factory=zhanneng | ||||
#guizhou.device.model=TPE390 | #guizhou.device.model=TPE390 | ||||
#guizhou.device.version=TPE_0056 | #guizhou.device.version=TPE_0056 | ||||
guizhou.http.url=http://202.105.147.30:24183 | 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.zhizhong=862622050654340,862622050317740 | ||||
guizhou.device.zhanneng=862622050925104,862622050927027 | guizhou.device.zhanneng=862622050925104,862622050927027 | ||||
guizhou.device.tianbo=862622050253671,862622050253358,800115470000678 | guizhou.device.tianbo=862622050253671,862622050253358,800115470000678 | ||||
@@ -197,4 +197,43 @@ class CenterApplicationTests { | |||||
System.out.println(in); | 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)); | |||||
} | |||||
} | } |