|
@@ -3,10 +3,12 @@ using HiTeachCE.Helpers;
|
|
|
using HiTeachCE.Models;
|
|
|
using HiTeachCE.Services;
|
|
|
using IdentityModel;
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using OpenXmlPowerTools;
|
|
|
+using Org.BouncyCastle.Ocsp;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
@@ -56,10 +58,12 @@ namespace HiTeachCE.Controllers
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("regist")]
|
|
|
+ [Authorize]
|
|
|
public BaseJosnRPCResponse Regist(JosnRPCRequest<Dictionary<string, string>> request)
|
|
|
{
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
- List<string> ClientId = new List<string>() { "fb564dde14df423cafac2085936e3b96" };/// GetLoginUser(JwtClaimTypes.ClientId);
|
|
|
+ List<string> ClientId = //new List<string>() { "fb564dde14df423cafac2085936e3b96" };
|
|
|
+ GetLoginUser(JwtClaimTypes.ClientId);
|
|
|
/**
|
|
|
"params": {
|
|
|
"deviceId": "f67fb5dd-ee1b-d3b7-9b95-61022d7e8acd",
|
|
@@ -90,6 +94,7 @@ namespace HiTeachCE.Controllers
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("createGroup")]
|
|
|
+ [Authorize]
|
|
|
public BaseJosnRPCResponse CreateGroup(JosnRPCRequest<Dictionary<string, string>> request)
|
|
|
{
|
|
|
/**
|
|
@@ -101,9 +106,9 @@ namespace HiTeachCE.Controllers
|
|
|
*/
|
|
|
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
- List<string> ClientId = new List<string>() { "fb564dde14df423cafac2085936e3b96" };
|
|
|
- // GetLoginUser(JwtClaimTypes.ClientId);
|
|
|
- string groupNum = "";
|
|
|
+ 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))
|
|
@@ -141,10 +146,13 @@ namespace HiTeachCE.Controllers
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("joinGroup")]
|
|
|
+ [Authorize]
|
|
|
public BaseJosnRPCResponse JoinGroup(JosnRPCRequest<Dictionary<string, string>> request)
|
|
|
{
|
|
|
+ List<string> ClientId = //new List<string>() { "fb564dde14df423cafac2085936e3b96" };
|
|
|
+ GetLoginUser(JwtClaimTypes.ClientId);
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
- Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
+ Dictionary<string, object> dict;
|
|
|
/**
|
|
|
"params": {
|
|
|
"deviceId": "f67fb5dd-ee1b-d3b7-9b95-61022d7e8acd",
|
|
@@ -158,24 +166,7 @@ namespace HiTeachCE.Controllers
|
|
|
{
|
|
|
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 } });
|
|
|
+ dict = MqttInfo(ClientId, deviceId, groupNum);
|
|
|
}
|
|
|
else {
|
|
|
throw new BizException("教室不存在", 2);
|
|
@@ -188,6 +179,40 @@ namespace HiTeachCE.Controllers
|
|
|
|
|
|
return builder.Data(dict).build();
|
|
|
}
|
|
|
+
|
|
|
+ private static Dictionary<string, object> MqttInfo(List<string> ClientId, string deviceId, string groupNum)
|
|
|
+ {
|
|
|
+ Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
+ string password = "cdhabook.teammodel.cn/" + 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
|
|
|
+ {
|
|
|
+ deviceId,
|
|
|
+ username = uname,
|
|
|
+ password = h2
|
|
|
+ };
|
|
|
+ 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 } });
|
|
|
+ return dict;
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 认证
|
|
|
/// </summary>
|
|
@@ -361,8 +386,67 @@ namespace HiTeachCE.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //register user
|
|
|
+ [HttpPost("register")]
|
|
|
+ public BaseJosnRPCResponse Register(JosnRPCRequest<RegisterDto> request) {
|
|
|
+ JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
+ if (RedisHelper.Exists("ticket:" + request.@params.ticket))
|
|
|
+ {
|
|
|
+ if (request.@params.user != null)
|
|
|
+ {
|
|
|
+ string[] phone= RedisHelper.HVals("ticket:" + request.@params.ticket);
|
|
|
+ if (phone.IsNotEmpty())
|
|
|
+ {
|
|
|
+ if (!request.@params.user.cellphone.Equals(phone[0])) {
|
|
|
+ throw new BizException("手机号与凭证不匹配!", 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ throw new BizException("凭证无效!", 2);
|
|
|
+ }
|
|
|
+ Expression<Func<Lecturer, bool>> linq = null;
|
|
|
+ linq = m => m.cellphone == request.@params.user.cellphone || m.account == request.@params.user.account;
|
|
|
+ List<Lecturer> lecturers = lecturerService.GetList(linq);
|
|
|
+ if (lecturers.IsNotEmpty())
|
|
|
+ {
|
|
|
+ throw new BizException("手机号或账号已经存在!", 2);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ request.@params.user.id = Guid.NewGuid().ToString();
|
|
|
+ request.@params.user.unionid = Guid.NewGuid().ToString("N");
|
|
|
+ request.@params.user.unionid = "86";
|
|
|
+ if (request.@params.user.password == null)
|
|
|
+ {
|
|
|
+ request.@params.user.password = "";
|
|
|
+ }
|
|
|
+ bool ib = lecturerService.Insert(request.@params.user);
|
|
|
+ if (ib)
|
|
|
+ {
|
|
|
+ return builder.Data(ib).build();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new BizException("注册失败!", 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new BizException("参数错误!", 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ throw new BizException("短信验证过期!", 2);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ }
|
|
|
|
|
|
+ public class RegisterDto {
|
|
|
+ public Lecturer user { get; set; }
|
|
|
+ public string ticket { get; set; }
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 登录
|
|
|
/// </summary>
|
|
@@ -471,7 +555,9 @@ namespace HiTeachCE.Controllers
|
|
|
else
|
|
|
{
|
|
|
//测试组织机构
|
|
|
- return new Dictionary<string, object> { { "status", 3 }, { "org", organizationService.GetByIds(new string[] { freeOrg }) } };
|
|
|
+ Expression<Func<Organization, bool>> olinq = null;
|
|
|
+ olinq = o =>o.code==freeOrg && o.status == 1;
|
|
|
+ return new Dictionary<string, object> { { "status", 3 }, { "org", organizationService.GetList(olinq) } };
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -498,7 +584,8 @@ namespace HiTeachCE.Controllers
|
|
|
areaCode="86",
|
|
|
registerTime=new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(),
|
|
|
status=1,
|
|
|
- setaccount=0
|
|
|
+ setaccount=0,
|
|
|
+ cellphone=cellphone
|
|
|
}
|
|
|
}
|
|
|
};
|