diff --git a/broker/config/hazelcast.xml b/broker/config/hazelcast.xml index de68a680..d7e02dff 100755 --- a/broker/config/hazelcast.xml +++ b/broker/config/hazelcast.xml @@ -108,13 +108,22 @@ - + + + 604800 + LRU + 1000000 + 10 + + io.moquette.persistence.DeviceLoader + 0 + - + diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index 3386e59d..84347258 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -187,3 +187,6 @@ sensitive.filter.type 0 #********************************************************************* ##消息转发地址 #message.forward.url http://localhost:8087/message/forward + +##设备信息转发地址 +#things_message.forward.url http://localhost:8087/device/forward diff --git a/broker/migrate/h2/V27__create_device_table.sql b/broker/migrate/h2/V27__create_device_table.sql new file mode 100755 index 00000000..a98e0f35 --- /dev/null +++ b/broker/migrate/h2/V27__create_device_table.sql @@ -0,0 +1,15 @@ + +DROP TABLE IF EXISTS `t_thing`; + +DROP TABLE IF EXISTS `t_device`; +CREATE TABLE `t_device` ( + `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `_uid` varchar(64) NOT NULL, + `_owner` varchar(64) DEFAULT '', + `_token` varchar(64) DEFAULT '', + `_state` tinyint DEFAULT 0, + `_extra` TEXT DEFAULT NULL, + `_dt` bigint(20) NOT NULL, + UNIQUE INDEX `device_uid_index` (`_uid` ASC), + INDEX `device_owner_index` (`_owner` ASC) +) diff --git a/broker/migrate/h2/V28__add_session_user_type.sql b/broker/migrate/h2/V28__add_session_user_type.sql new file mode 100755 index 00000000..9a73a5f7 --- /dev/null +++ b/broker/migrate/h2/V28__add_session_user_type.sql @@ -0,0 +1 @@ +alter table t_user_session add column `_user_type` tinyint DEFAULT 0; diff --git a/broker/migrate/mysql/V32__create_device_table.sql b/broker/migrate/mysql/V32__create_device_table.sql new file mode 100755 index 00000000..738f4757 --- /dev/null +++ b/broker/migrate/mysql/V32__create_device_table.sql @@ -0,0 +1,19 @@ + +DROP TABLE IF EXISTS `t_thing`; + +DROP TABLE IF EXISTS `t_device`; +CREATE TABLE `t_device` ( + `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `_uid` varchar(64) NOT NULL, + `_owner` varchar(64) DEFAULT '', + `_token` varchar(64) DEFAULT '', + `_state` tinyint DEFAULT 0, + `_extra` TEXT DEFAULT NULL, + `_dt` bigint(20) NOT NULL, + UNIQUE INDEX `device_uid_index` (`_uid` ASC), + INDEX `device_owner_index` (`_owner` ASC) +) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8mb4 +COLLATE = utf8mb4_unicode_ci; + diff --git a/broker/migrate/mysql/V33__add_session_user_type.sql b/broker/migrate/mysql/V33__add_session_user_type.sql new file mode 100755 index 00000000..886a4196 --- /dev/null +++ b/broker/migrate/mysql/V33__add_session_user_type.sql @@ -0,0 +1 @@ +alter table t_user_session add column `_user_type` tinyint DEFAULT 0 COMMENT "0, normal user; 1, robot; 2, device;"; diff --git a/common/src/main/java/cn/wildfirechat/common/APIPath.java b/common/src/main/java/cn/wildfirechat/common/APIPath.java index 2428ea65..4ab50c91 100644 --- a/common/src/main/java/cn/wildfirechat/common/APIPath.java +++ b/common/src/main/java/cn/wildfirechat/common/APIPath.java @@ -19,6 +19,8 @@ public interface APIPath { String Create_User = "/admin/user/create"; String Destroy_User = "/admin/user/destroy"; String Create_Robot = "/admin/robot/create"; + String CreateOrUpdate_Device = "/admin/device/create"; + String Get_Device = "/admin/device/get"; String User_Get_Token = "/admin/user/get_token"; String User_Update_Block_Status = "/admin/user/update_block_status"; String User_Get_Info = "/admin/user/get_info"; diff --git a/common/src/main/java/cn/wildfirechat/pojos/ForwardDeviceMessageData.java b/common/src/main/java/cn/wildfirechat/pojos/ForwardDeviceMessageData.java new file mode 100644 index 00000000..d3cca6df --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/ForwardDeviceMessageData.java @@ -0,0 +1,60 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package cn.wildfirechat.pojos; + +import cn.wildfirechat.proto.WFCMessage; +import io.netty.util.internal.StringUtil; + +import java.util.List; + +public class ForwardDeviceMessageData { + private String deviceId; + private String owner; + private int type; + private byte[] data; + + public ForwardDeviceMessageData(String deviceId, String owner, int type, byte[] data) { + this.deviceId = deviceId; + this.owner = owner; + this.type = type; + this.data = data; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public byte[] getData() { + return data; + } + + public void setData(byte[] data) { + this.data = data; + } +} diff --git a/common/src/main/java/cn/wildfirechat/pojos/InputCreateDevice.java b/common/src/main/java/cn/wildfirechat/pojos/InputCreateDevice.java new file mode 100755 index 00000000..89da7067 --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/InputCreateDevice.java @@ -0,0 +1,56 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package cn.wildfirechat.pojos; + + +import cn.wildfirechat.proto.WFCMessage; +import io.netty.util.internal.StringUtil; + +public class InputCreateDevice { + private String deviceId; + private String owner; + private String extra; + + public WFCMessage.Device toDevice() { + WFCMessage.Device.Builder builder = WFCMessage.Device.newBuilder(); + if (!StringUtil.isNullOrEmpty(deviceId)) + builder.setUid(deviceId); + if (!StringUtil.isNullOrEmpty(owner)) + builder.setOwner(owner); + if (!StringUtil.isNullOrEmpty(extra)) + builder.setExtra(extra); + builder.setState(0); + return builder.build(); + } + + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getExtra() { + return extra; + } + + public void setExtra(String extra) { + this.extra = extra; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } +} diff --git a/common/src/main/java/cn/wildfirechat/pojos/InputDeviceId.java b/common/src/main/java/cn/wildfirechat/pojos/InputDeviceId.java new file mode 100755 index 00000000..872782c9 --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/InputDeviceId.java @@ -0,0 +1,21 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package cn.wildfirechat.pojos; + +public class InputDeviceId { + private String deviceId; + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } +} diff --git a/common/src/main/java/cn/wildfirechat/pojos/OutputCreateDevice.java b/common/src/main/java/cn/wildfirechat/pojos/OutputCreateDevice.java new file mode 100755 index 00000000..b5590055 --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/OutputCreateDevice.java @@ -0,0 +1,45 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package cn.wildfirechat.pojos; + +public class OutputCreateDevice { + private String deviceId; + private String token; + private String secret; + + public OutputCreateDevice(String userId, String token, String secret) { + this.deviceId = userId; + this.token = token; + this.secret = secret; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String getSecret() { + return secret; + } + + public void setSecret(String secret) { + this.secret = secret; + } +} diff --git a/common/src/main/java/cn/wildfirechat/pojos/OutputDevice.java b/common/src/main/java/cn/wildfirechat/pojos/OutputDevice.java new file mode 100755 index 00000000..db39868e --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/OutputDevice.java @@ -0,0 +1,74 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package cn.wildfirechat.pojos; + +import cn.wildfirechat.proto.WFCMessage; + +public class OutputDevice { + private int state; + private String deviceId; + private String token; + private String secret; + private String owner; + private String extra; + + public OutputDevice(String deviceId, String token, String secret) { + this.deviceId = deviceId; + this.token = token; + this.secret = secret; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String getSecret() { + return secret; + } + + public void setSecret(String secret) { + this.secret = secret; + } + + public int getState() { + return state; + } + + public void setState(int state) { + this.state = state; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getExtra() { + return extra; + } + + public void setExtra(String extra) { + this.extra = extra; + } +} diff --git a/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java b/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java index 078d5e95..8f169e02 100644 --- a/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java +++ b/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java @@ -8,7 +8,7 @@ public class ProtoConstants { int ConversationType_Group = 1; int ConversationType_ChatRoom = 2; int ConversationType_Channel = 3; - int ConversationType_Thing = 4; + int ConversationType_Things = 4; } //message GroupInfo -> type diff --git a/distribution/src/main/resources/hazelcast.xml b/distribution/src/main/resources/hazelcast.xml index aa8341e7..29659d4f 100755 --- a/distribution/src/main/resources/hazelcast.xml +++ b/distribution/src/main/resources/hazelcast.xml @@ -102,13 +102,23 @@ - + + + 604800 + LRU + 1000000 + 10 + + io.moquette.persistence.DeviceLoader + 0 + + - + diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index a76c8e08..01e8670d 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -193,3 +193,6 @@ sensitive.filter.type 0 #********************************************************************* ##消息转发地址 #message.forward.url http://localhost:8087/message/forward + +##设备信息转发地址 +#device.forward.url http://localhost:8087/device/forward diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java index 345a2e0d..2a4ccf93 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java @@ -73,6 +73,25 @@ public class Main { System.exit(-1); } + InputCreateDevice createDevice = new InputCreateDevice(); + createDevice.setDeviceId("deviceId1"); + createDevice.setOwner("userId1"); + IMResult resultCreateDevice = UserAdmin.createOrUpdateDevice(createDevice); + if (resultCreateDevice != null && resultCreateDevice.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { + System.out.println("Create device " + resultCreateDevice.getResult().getDeviceId() + " success"); + } else { + System.out.println("Create device failure"); + System.exit(-1); + } + + IMResult getDevice = UserAdmin.getDevice("deviceId1"); + if (getDevice != null && getDevice.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && getDevice.getResult().getDeviceId().equals("deviceId1") && getDevice.getResult().getOwner().equals("userId1")) { + System.out.println("Get device " + resultCreateDevice.getResult().getDeviceId() + " success"); + } else { + System.out.println("Get device failure"); + System.exit(-1); + } + IMResult resultGetUserInfo1 = UserAdmin.getUserByName(userInfo.getName()); if (resultGetUserInfo1 != null && resultGetUserInfo1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { if (userInfo.getUserId().equals(resultGetUserInfo1.getResult().getUserId()) diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java b/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java index 4012ec5b..789336fe 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java @@ -2,7 +2,6 @@ package cn.wildfirechat.sdk; import cn.wildfirechat.common.APIPath; import cn.wildfirechat.pojos.*; -import cn.wildfirechat.proto.ProtoConstants; import cn.wildfirechat.sdk.model.IMResult; import cn.wildfirechat.sdk.utilities.AdminHttpUtils; @@ -71,14 +70,18 @@ public class UserAdmin { return AdminHttpUtils.httpJsonPost(path, inputDestroyUser, Void.class); } - //not implement -// public static IMResult getUserOnlineStatus(String userId) throws Exception { -// String path = APIPath.User_Get_Online_Status; -// InputGetUserInfo inputGetUserInfo = new InputGetUserInfo(userId, null); -// return AdminHttpUtils.httpJsonPost(path, null, OutputUserBlockStatusList.class); -// } - - + //仅专业版支持 + public static IMResult createOrUpdateDevice(InputCreateDevice device) throws Exception { + String path = APIPath.CreateOrUpdate_Device; + return AdminHttpUtils.httpJsonPost(path, device, OutputCreateDevice.class); + } + //仅专业版支持 + public static IMResult getDevice(String deviceId) throws Exception { + String path = APIPath.Get_Device; + InputDeviceId inputDeviceId = new InputDeviceId(); + inputDeviceId.setDeviceId(deviceId); + return AdminHttpUtils.httpJsonPost(path, inputDeviceId, OutputDevice.class); + } }