|
@@ -27,12 +27,13 @@ namespace HiTeachCE.Controllers
|
|
{
|
|
{
|
|
[Route("api/[controller]")]
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
[ApiController]
|
|
- public class LoginController : Controller
|
|
|
|
|
|
+ public class LoginController : BaseController
|
|
{
|
|
{
|
|
|
|
|
|
public static int smsTTL = 4 * 60;
|
|
public static int smsTTL = 4 * 60;
|
|
public static int ticketTTL = 10 * 60;
|
|
public static int ticketTTL = 10 * 60;
|
|
public static int freeTTL = 7 * 24 * 60 * 60;
|
|
public static int freeTTL = 7 * 24 * 60 * 60;
|
|
|
|
+ public static int deviceTTL=1 * 24 * 60 * 60;
|
|
public static string freeOrg = "7f847a9f05224184a5d01ee69a6b00d6";
|
|
public static string freeOrg = "7f847a9f05224184a5d01ee69a6b00d6";
|
|
public static string model_teach = "teach";
|
|
public static string model_teach = "teach";
|
|
public static string model_prepare = "prepare";
|
|
public static string model_prepare = "prepare";
|
|
@@ -57,14 +58,30 @@ namespace HiTeachCE.Controllers
|
|
[HttpPost("regist")]
|
|
[HttpPost("regist")]
|
|
public BaseJosnRPCResponse Regist(JosnRPCRequest<Dictionary<string, string>> request)
|
|
public BaseJosnRPCResponse Regist(JosnRPCRequest<Dictionary<string, string>> request)
|
|
{
|
|
{
|
|
|
|
+ JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
|
+ List<string> ClientId = new List<string>() { "fb564dde14df423cafac2085936e3b96" };/// GetLoginUser(JwtClaimTypes.ClientId);
|
|
/**
|
|
/**
|
|
"params": {
|
|
"params": {
|
|
- "deviceId": "f67fb5dd-ee1b-d3b7-9b95-61022d7e8acd",
|
|
|
|
- "clientId": "931dee8c-74be-4c9b-a602-c74583b0e985",
|
|
|
|
- }
|
|
|
|
|
|
+ "deviceId": "f67fb5dd-ee1b-d3b7-9b95-61022d7e8acd",
|
|
|
|
+ "clientId": "931dee8c-74be-4c9b-a602-c74583b0e985",
|
|
|
|
+ }
|
|
*/
|
|
*/
|
|
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
|
- return builder.build();
|
|
|
|
|
|
+ if (request.@params.TryGetValue("deviceId", out string deviceId) && ClientId.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ if (RedisHelper.HExists("device:" + ClientId[0], deviceId))
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ RedisHelper.HSet("device:" + ClientId[0], deviceId, null);
|
|
|
|
+ RedisHelper.Expire("device:" + ClientId[0], deviceTTL);
|
|
|
|
+ }
|
|
|
|
+ return builder.Data(new Dictionary<string, object> { { "deviceId", deviceId } }).build();
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ throw new BizException("参数错误", 2);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -82,10 +99,42 @@ namespace HiTeachCE.Controllers
|
|
"extraInfo": {}
|
|
"extraInfo": {}
|
|
}
|
|
}
|
|
*/
|
|
*/
|
|
|
|
+
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
- return builder.build();
|
|
|
|
|
|
+ List<string> ClientId = new List<string>() { "fb564dde14df423cafac2085936e3b96" };
|
|
|
|
+ // GetLoginUser(JwtClaimTypes.ClientId);
|
|
|
|
+ string groupNum = "";
|
|
|
|
+ if (request.@params.TryGetValue("deviceId", out string deviceId) && ClientId.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ if (RedisHelper.HExists("device:" + ClientId[0], deviceId))
|
|
|
|
+ {
|
|
|
|
+ groupNum= RedisHelper.HGet<string>("device:" + ClientId[0], deviceId);
|
|
|
|
+ if (string.IsNullOrEmpty(groupNum)) {
|
|
|
|
+ do
|
|
|
|
+ {
|
|
|
|
+ groupNum = RandGroupNum();
|
|
|
|
+ } while (RedisHelper.Exists("group:" + groupNum));
|
|
|
|
+ RedisHelper.HSet("group:" + groupNum, deviceId, null);
|
|
|
|
+ RedisHelper.Expire("group:" + groupNum, deviceTTL);
|
|
|
|
+ RedisHelper.HSet("device:" + ClientId[0], deviceId, groupNum);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else { throw new BizException("装置未注册", 2); }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ throw new BizException("参数错误", 2);
|
|
|
|
+ }
|
|
|
|
+ return builder.Data(groupNum).build();
|
|
|
|
+ }
|
|
|
|
+ public string RandGroupNum() {
|
|
|
|
+ Random random = new Random();
|
|
|
|
+ String result = "";
|
|
|
|
+ for (int i = 0; i < 6; i++)
|
|
|
|
+ {
|
|
|
|
+ result += random.Next(0,10);
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 加入教室
|
|
/// 加入教室
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -94,14 +143,50 @@ namespace HiTeachCE.Controllers
|
|
[HttpPost("joinGroup")]
|
|
[HttpPost("joinGroup")]
|
|
public BaseJosnRPCResponse JoinGroup(JosnRPCRequest<Dictionary<string, string>> request)
|
|
public BaseJosnRPCResponse JoinGroup(JosnRPCRequest<Dictionary<string, string>> request)
|
|
{
|
|
{
|
|
|
|
+ JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
|
+ Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
/**
|
|
/**
|
|
"params": {
|
|
"params": {
|
|
"deviceId": "f67fb5dd-ee1b-d3b7-9b95-61022d7e8acd",
|
|
"deviceId": "f67fb5dd-ee1b-d3b7-9b95-61022d7e8acd",
|
|
"groupNum": "818288"
|
|
"groupNum": "818288"
|
|
}
|
|
}
|
|
*/
|
|
*/
|
|
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
|
- return builder.build();
|
|
|
|
|
|
+ if (request.@params.TryGetValue("deviceId", out string deviceId) &&
|
|
|
|
+ request.@params.TryGetValue("groupNum", out string groupNum)&&
|
|
|
|
+ !string.IsNullOrEmpty(deviceId) && !string.IsNullOrEmpty(groupNum)
|
|
|
|
+ )
|
|
|
|
+ {
|
|
|
|
+ if (RedisHelper.Exists("group:" + groupNum))
|
|
|
|
+ {
|
|
|
|
+ dynamic groupMember = new {
|
|
|
|
+ deviceId,
|
|
|
|
+ name= "🌱菁華浮梦",
|
|
|
|
+ unionid= "b180ca87fea84c908a688c005b3f487e",
|
|
|
|
+ role= "lecturer",
|
|
|
|
+ org= "7f847a9f05224184a5d01ee69a6b00d6",
|
|
|
|
+ phone_number="15283771540"
|
|
|
|
+ };
|
|
|
|
+ Dictionary<string, string> connectInfo = new Dictionary<string, string>() {
|
|
|
|
+ { "brokerHostName", "cdhabook.teammodel.cn" },
|
|
|
|
+ { "brokerHostNameWSS", "wss://cdhabook.teammodel.cn/mqtt" },
|
|
|
|
+ { "clientID", deviceId },
|
|
|
|
+ //使用BCrypt加密
|
|
|
|
+ { "password", "cdhabook.teammodel.cn" },
|
|
|
|
+ { "username", "cdhabook.teammodel.cn/"+deviceId }
|
|
|
|
+ };
|
|
|
|
+ RedisHelper.HSet("group:" + groupNum, deviceId, groupMember) ;
|
|
|
|
+ dict.Add("mqtt", new Dictionary<string,object>() { { "connectInfo", connectInfo },{ "groupMember", groupMember } });
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ throw new BizException("教室不存在", 2);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ throw new BizException("参数错误", 2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return builder.Data(dict).build();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 认证
|
|
/// 认证
|
|
@@ -114,8 +199,8 @@ namespace HiTeachCE.Controllers
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
if (request.@params.TryGetValue("ticket", out string ticket) &&
|
|
if (request.@params.TryGetValue("ticket", out string ticket) &&
|
|
//上课模式 备课模式
|
|
//上课模式 备课模式
|
|
- request.@params.TryGetValue("model", out string model)&&
|
|
|
|
- (model.Equals(model_teach )||model.Equals(model_prepare)) &&
|
|
|
|
|
|
+ //request.@params.TryGetValue("model", out string model)&&
|
|
|
|
+ // (model.Equals(model_teach )||model.Equals(model_prepare)) &&
|
|
request.@params.TryGetValue("orgCode", out string orgCode)
|
|
request.@params.TryGetValue("orgCode", out string orgCode)
|
|
)
|
|
)
|
|
{
|
|
{
|