things db config and sdk
This commit is contained in:
@@ -108,13 +108,22 @@
|
|||||||
</map-store>
|
</map-store>
|
||||||
</map>
|
</map>
|
||||||
|
|
||||||
<map name="things">
|
<map name="device">
|
||||||
|
<!-- 7 days -->
|
||||||
|
<time-to-live-seconds>604800</time-to-live-seconds>
|
||||||
|
<eviction-policy>LRU</eviction-policy>
|
||||||
|
<max-size policy="PER_NODE">1000000</max-size>
|
||||||
|
<eviction-percentage>10</eviction-percentage>
|
||||||
|
<map-store enabled="true">
|
||||||
|
<class-name>io.moquette.persistence.DeviceLoader</class-name>
|
||||||
|
<write-delay-seconds>0</write-delay-seconds>
|
||||||
|
</map-store>
|
||||||
</map>
|
</map>
|
||||||
|
|
||||||
<multimap name="user_robots">
|
<multimap name="user_robots">
|
||||||
</multimap>
|
</multimap>
|
||||||
|
|
||||||
<multimap name="user_things">
|
<multimap name="user_devices">
|
||||||
</multimap>
|
</multimap>
|
||||||
|
|
||||||
<multimap name="chatroom_members">
|
<multimap name="chatroom_members">
|
||||||
|
|||||||
@@ -187,3 +187,6 @@ sensitive.filter.type 0
|
|||||||
#*********************************************************************
|
#*********************************************************************
|
||||||
##消息转发地址
|
##消息转发地址
|
||||||
#message.forward.url http://localhost:8087/message/forward
|
#message.forward.url http://localhost:8087/message/forward
|
||||||
|
|
||||||
|
##设备信息转发地址
|
||||||
|
#things_message.forward.url http://localhost:8087/device/forward
|
||||||
|
|||||||
+15
@@ -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)
|
||||||
|
)
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
alter table t_user_session add column `_user_type` tinyint DEFAULT 0;
|
||||||
+19
@@ -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;
|
||||||
|
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
alter table t_user_session add column `_user_type` tinyint DEFAULT 0 COMMENT "0, normal user; 1, robot; 2, device;";
|
||||||
@@ -19,6 +19,8 @@ public interface APIPath {
|
|||||||
String Create_User = "/admin/user/create";
|
String Create_User = "/admin/user/create";
|
||||||
String Destroy_User = "/admin/user/destroy";
|
String Destroy_User = "/admin/user/destroy";
|
||||||
String Create_Robot = "/admin/robot/create";
|
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_Get_Token = "/admin/user/get_token";
|
||||||
String User_Update_Block_Status = "/admin/user/update_block_status";
|
String User_Update_Block_Status = "/admin/user/update_block_status";
|
||||||
String User_Get_Info = "/admin/user/get_info";
|
String User_Get_Info = "/admin/user/get_info";
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <[email protected]>
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <[email protected]>
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <[email protected]>
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <[email protected]>
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <[email protected]>
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ public class ProtoConstants {
|
|||||||
int ConversationType_Group = 1;
|
int ConversationType_Group = 1;
|
||||||
int ConversationType_ChatRoom = 2;
|
int ConversationType_ChatRoom = 2;
|
||||||
int ConversationType_Channel = 3;
|
int ConversationType_Channel = 3;
|
||||||
int ConversationType_Thing = 4;
|
int ConversationType_Things = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
//message GroupInfo -> type
|
//message GroupInfo -> type
|
||||||
|
|||||||
@@ -102,13 +102,23 @@
|
|||||||
</map-store>
|
</map-store>
|
||||||
</map>
|
</map>
|
||||||
|
|
||||||
<map name="things">
|
<map name="device">
|
||||||
|
<!-- 7 days -->
|
||||||
|
<time-to-live-seconds>604800</time-to-live-seconds>
|
||||||
|
<eviction-policy>LRU</eviction-policy>
|
||||||
|
<max-size policy="PER_NODE">1000000</max-size>
|
||||||
|
<eviction-percentage>10</eviction-percentage>
|
||||||
|
<map-store enabled="true">
|
||||||
|
<class-name>io.moquette.persistence.DeviceLoader</class-name>
|
||||||
|
<write-delay-seconds>0</write-delay-seconds>
|
||||||
|
</map-store>
|
||||||
</map>
|
</map>
|
||||||
|
|
||||||
|
|
||||||
<multimap name="user_robots">
|
<multimap name="user_robots">
|
||||||
</multimap>
|
</multimap>
|
||||||
|
|
||||||
<multimap name="user_things">
|
<multimap name="user_devices">
|
||||||
</multimap>
|
</multimap>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -193,3 +193,6 @@ sensitive.filter.type 0
|
|||||||
#*********************************************************************
|
#*********************************************************************
|
||||||
##消息转发地址
|
##消息转发地址
|
||||||
#message.forward.url http://localhost:8087/message/forward
|
#message.forward.url http://localhost:8087/message/forward
|
||||||
|
|
||||||
|
##设备信息转发地址
|
||||||
|
#device.forward.url http://localhost:8087/device/forward
|
||||||
|
|||||||
@@ -73,6 +73,25 @@ public class Main {
|
|||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InputCreateDevice createDevice = new InputCreateDevice();
|
||||||
|
createDevice.setDeviceId("deviceId1");
|
||||||
|
createDevice.setOwner("userId1");
|
||||||
|
IMResult<OutputCreateDevice> 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<OutputDevice> 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<InputOutputUserInfo> resultGetUserInfo1 = UserAdmin.getUserByName(userInfo.getName());
|
IMResult<InputOutputUserInfo> resultGetUserInfo1 = UserAdmin.getUserByName(userInfo.getName());
|
||||||
if (resultGetUserInfo1 != null && resultGetUserInfo1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
if (resultGetUserInfo1 != null && resultGetUserInfo1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
if (userInfo.getUserId().equals(resultGetUserInfo1.getResult().getUserId())
|
if (userInfo.getUserId().equals(resultGetUserInfo1.getResult().getUserId())
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package cn.wildfirechat.sdk;
|
|||||||
|
|
||||||
import cn.wildfirechat.common.APIPath;
|
import cn.wildfirechat.common.APIPath;
|
||||||
import cn.wildfirechat.pojos.*;
|
import cn.wildfirechat.pojos.*;
|
||||||
import cn.wildfirechat.proto.ProtoConstants;
|
|
||||||
import cn.wildfirechat.sdk.model.IMResult;
|
import cn.wildfirechat.sdk.model.IMResult;
|
||||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||||
|
|
||||||
@@ -71,14 +70,18 @@ public class UserAdmin {
|
|||||||
return AdminHttpUtils.httpJsonPost(path, inputDestroyUser, Void.class);
|
return AdminHttpUtils.httpJsonPost(path, inputDestroyUser, Void.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
//not implement
|
//仅专业版支持
|
||||||
// public static IMResult<OutputUserBlockStatusList> getUserOnlineStatus(String userId) throws Exception {
|
public static IMResult<OutputCreateDevice> createOrUpdateDevice(InputCreateDevice device) throws Exception {
|
||||||
// String path = APIPath.User_Get_Online_Status;
|
String path = APIPath.CreateOrUpdate_Device;
|
||||||
// InputGetUserInfo inputGetUserInfo = new InputGetUserInfo(userId, null);
|
return AdminHttpUtils.httpJsonPost(path, device, OutputCreateDevice.class);
|
||||||
// return AdminHttpUtils.httpJsonPost(path, null, OutputUserBlockStatusList.class);
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//仅专业版支持
|
||||||
|
public static IMResult<OutputDevice> getDevice(String deviceId) throws Exception {
|
||||||
|
String path = APIPath.Get_Device;
|
||||||
|
InputDeviceId inputDeviceId = new InputDeviceId();
|
||||||
|
inputDeviceId.setDeviceId(deviceId);
|
||||||
|
return AdminHttpUtils.httpJsonPost(path, inputDeviceId, OutputDevice.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user