|
@@ -149,8 +149,9 @@ namespace HiTeachCE.Controllers
|
|
|
[Authorize]
|
|
|
public BaseJosnRPCResponse JoinGroup(JosnRPCRequest<Dictionary<string, string>> request)
|
|
|
{
|
|
|
- List<string> ClientId = //new List<string>() { "fb564dde14df423cafac2085936e3b96" };
|
|
|
- GetLoginUser(JwtClaimTypes.ClientId);
|
|
|
+ List<string> ClientId = GetLoginUser(JwtClaimTypes.ClientId);
|
|
|
+ List<string> Unionid = GetLoginUser(JwtClaimTypes.Id);
|
|
|
+ List<string> Role = GetLoginUser(JwtClaimTypes.Role);
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
Dictionary<string, object> dict;
|
|
|
/**
|
|
@@ -166,7 +167,7 @@ namespace HiTeachCE.Controllers
|
|
|
{
|
|
|
if (RedisHelper.Exists("group:" + groupNum))
|
|
|
{
|
|
|
- dict = MqttInfo(ClientId, deviceId, groupNum);
|
|
|
+ dict = MqttInfo(ClientId, deviceId, groupNum, Unionid, Role);
|
|
|
}
|
|
|
else {
|
|
|
throw new BizException("教室不存在", 2);
|
|
@@ -180,38 +181,75 @@ namespace HiTeachCE.Controllers
|
|
|
return builder.Data(dict).build();
|
|
|
}
|
|
|
|
|
|
- private static Dictionary<string, object> MqttInfo(List<string> ClientId, string deviceId, string groupNum)
|
|
|
+ private static Dictionary<string, object> MqttInfo(List<string> ClientId, string deviceId, string groupNum,List<string> Unionid,List<string> Role)
|
|
|
{
|
|
|
+ string brokerHostName = BaseConfigModel.Configuration["brokerHostName"];
|
|
|
+
|
|
|
Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
- string password = "cdhabook.teammodel.cn/" + groupNum +"/"+ deviceId +"/"+ ClientId[0];
|
|
|
+ string password = brokerHostName + "/" + groupNum +"/"+ deviceId +"/"+ ClientId[0];
|
|
|
//发给前端使用的
|
|
|
string h1 = BCrypt.Net.BCrypt.HashPassword(password);
|
|
|
//后端存储使用的
|
|
|
string h2 = BCrypt.Net.BCrypt.HashPassword(h1);
|
|
|
bool validPassword = BCrypt.Net.BCrypt.Verify(h1, h2);
|
|
|
string uname = password;
|
|
|
- Dictionary<string, string> connectInfo = new Dictionary<string, string>() {
|
|
|
- { "brokerHostName", "cdhabook.teammodel.cn" },
|
|
|
- { "brokerHostNameWSS", "wss://cdhabook.teammodel.cn/mqtt" },
|
|
|
- { "clientID", deviceId },
|
|
|
- //使用BCrypt加密
|
|
|
- { "password",h1 },
|
|
|
- { "username",uname }
|
|
|
- };
|
|
|
- dynamic groupMember = new
|
|
|
+ Dictionary<string,string> connectInfo = new Dictionary<string, string>
|
|
|
{
|
|
|
- deviceId,
|
|
|
- username = uname,
|
|
|
- password = h2
|
|
|
+ { "brokerHostName", brokerHostName },
|
|
|
+ { "brokerHostNameWSS", "wss://" +brokerHostName+"/mqtt"} ,
|
|
|
+ { "clientID", deviceId },
|
|
|
+ //使用BCrypt加密
|
|
|
+ { "password",h1} ,
|
|
|
+ { "username",uname}
|
|
|
};
|
|
|
- RedisHelper.HSet("group:" + groupNum, deviceId, groupMember);
|
|
|
Dictionary<string, string> subscribeTopic = BaseConfigModel.Configuration.GetSection("SubscribeTopic").Get<Dictionary<string, string>>();
|
|
|
subscribeTopic["receiveMsg"] = subscribeTopic["receiveMsg"].Replace("{deviceId}", deviceId);
|
|
|
Dictionary<string, string> publishTopic = BaseConfigModel.Configuration.GetSection("PublishTopic").Get<Dictionary<string, string>>();
|
|
|
publishTopic["sendMsg"] = publishTopic["sendMsg"].Replace("{deviceId}", deviceId).Replace("{groupNum}", groupNum);
|
|
|
dict.Add("mqtt", new Dictionary<string, object>() { { "connectInfo", connectInfo },{ "publishTopic", publishTopic },{ "subscribeTopic", subscribeTopic } });
|
|
|
+ List<string> topic = new List<string>();
|
|
|
+ topic.AddRange(publishTopic.Values.ToList());
|
|
|
+ topic.AddRange(subscribeTopic.Values.ToList());
|
|
|
+ MQTTInfo mqtt = new MQTTInfo
|
|
|
+ {
|
|
|
+ brokerHostName = brokerHostName,
|
|
|
+ brokerHostNameWSS = "wss://" + brokerHostName + "/mqtt",
|
|
|
+ clientID = deviceId,
|
|
|
+ //使用BCrypt加密
|
|
|
+ password = h2,
|
|
|
+ username = uname,
|
|
|
+ topic=topic
|
|
|
+ };
|
|
|
+ var groupMember = new MQTTMember
|
|
|
+ {
|
|
|
+ clientId= ClientId[0],
|
|
|
+ deviceId=deviceId,
|
|
|
+ unionid=Unionid[0],
|
|
|
+ role=Role[0],
|
|
|
+ groupNum=groupNum
|
|
|
+ };
|
|
|
+ RedisHelper.HSet("group:" + groupNum, deviceId, groupMember);
|
|
|
+ RedisHelper.HSet("mqtt:" + deviceId, deviceId, mqtt);
|
|
|
+ RedisHelper.Expire("mqtt:" + deviceId, deviceTTL);
|
|
|
return dict;
|
|
|
}
|
|
|
+ public class MQTTMember {
|
|
|
+ public string groupNum { get; set; }
|
|
|
+ public string clientId { get; set; }
|
|
|
+ public string deviceId { get; set; }
|
|
|
+ public string unionid { get; set; }
|
|
|
+ public string role { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class MQTTInfo {
|
|
|
+ public string brokerHostName { get; set; }
|
|
|
+ public string brokerHostNameWSS { get; set; }
|
|
|
+ public string clientID { get; set; }
|
|
|
+ public string password { get; set; }
|
|
|
+ public string username { get; set; }
|
|
|
+ public List<string> topic { get;set;}
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 认证
|
|
@@ -415,7 +453,7 @@ namespace HiTeachCE.Controllers
|
|
|
{
|
|
|
request.@params.user.id = Guid.NewGuid().ToString();
|
|
|
request.@params.user.unionid = Guid.NewGuid().ToString("N");
|
|
|
- request.@params.user.unionid = "86";
|
|
|
+ request.@params.user.areaCode = "86";
|
|
|
if (request.@params.user.password == null)
|
|
|
{
|
|
|
request.@params.user.password = "";
|