From 09e9877b1d2e5fb588da8c5427229cea8f904c99 Mon Sep 17 00:00:00 2001 From: liujiaqiang <1448951783@qq.com> Date: Mon, 11 Dec 2023 11:20:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E8=A1=A8?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=8F=B7=E6=A8=A1=E6=9D=BF=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/LawyerservicesController.cs | 13 ++ .../Controllers/Common/WebSocketController.cs | 38 +++--- 24Hour/Controllers/LoginController.cs | 51 +++++++- .../system/SystemControllerController.cs | 53 +++++++- 24Hour/WechatMessagerClient.cs | 117 +++++++++++++++++- 24Hour/appsettings.json | 4 + .../net6.0/Dto.csproj.CoreCompileInputs.cache | 2 +- Elight.Entity/SystemDto/App_Sys_UserDto.cs | 5 + .../SystemModel/App_Sys_UserModel.cs | 5 + 9 files changed, 264 insertions(+), 24 deletions(-) diff --git a/24Hour/Controllers/Common/LawyerservicesController.cs b/24Hour/Controllers/Common/LawyerservicesController.cs index 8da81de..4202411 100644 --- a/24Hour/Controllers/Common/LawyerservicesController.cs +++ b/24Hour/Controllers/Common/LawyerservicesController.cs @@ -128,6 +128,19 @@ namespace _24Hour.Controllers.Common _db.CommitTran(); if (num > 0) { + var jcguserdata = await _db.Queryable() + .Where(q => q.usertype == 0 && q.messages ==true && q.unitCode == Lawyerdata.unitCode).ToListAsync(); + if (jcguserdata != null) + { + foreach (var item in jcguserdata) + { + if (!string.IsNullOrEmpty(item.wechatId)) + { + //给检察官发送审核消息 + _wechatMessagerClient.gzhwxts(item.wechatId, Lawyerdata?.name, Lawyerdata?.phone, Lawyerdata?.objectstr + "-" + Lawyerdata?.matter, Lawyerdata?.reason); + } + } + } result.IsSucceed = true; result.result = "添加成功"; } diff --git a/24Hour/Controllers/Common/WebSocketController.cs b/24Hour/Controllers/Common/WebSocketController.cs index 8bc02d9..694bd88 100644 --- a/24Hour/Controllers/Common/WebSocketController.cs +++ b/24Hour/Controllers/Common/WebSocketController.cs @@ -546,24 +546,26 @@ namespace _24Hour.Controllers.Common return true; } - ///// - ///// 微信推送 - ///// - ///// - ///// - //[HttpGet] - //[Route("wxts")] - //public async Task wxts() - //{ - // try - // { - // _wechatMessagerClient.wxts(); - // } - // catch (Exception) - // { - // } - // return true; - //} + /// + /// 微信推送 + /// + /// + /// + [HttpGet] + [Route("gzhwxts")] + [AllowAnonymous] + public async Task gzhwxts(string openId) + { + try + { + //ozRTw0uB1w-Puu73araMIHrdKlSQ + _wechatMessagerClient.gzhwxts(openId, "律师","19536521444","查阅xxx人卷宗",""); + } + catch (Exception) + { + } + return true; + } } diff --git a/24Hour/Controllers/LoginController.cs b/24Hour/Controllers/LoginController.cs index 3d731a6..7cf2681 100644 --- a/24Hour/Controllers/LoginController.cs +++ b/24Hour/Controllers/LoginController.cs @@ -309,7 +309,7 @@ namespace _24Hour.Controllers } /// - /// ΢Code ½ + /// ΢СCode ½ /// /// /// @@ -327,7 +327,45 @@ namespace _24Hour.Controllers return opendata; } } - + /// + /// ΢ŹںCode ½ + /// + /// + /// + [HttpGet] + [Route("WeChatLoginByGzhCode")] + public async Task WeChatLoginByGzhCode(string code) + { + var opendata = await GetGzhOpenId(code); + if (opendata.IsSucceed == true) + { + return await WeChatLogin(opendata.result); + } + else + { + return opendata; + } + } + + ///// + ///// ȡ΢ŹںCode + ///// + ///// + ///// + //[HttpGet] + //[Route("GetCode")] + //public async Task GetCode(string code,string state) + //{ + // var opendata = await GetGzhOpenId(code); + // if (opendata.IsSucceed == true) + // { + // return await WeChatLogin(opendata.result); + // } + // else + // { + // return opendata; + // } + //} /// /// ΢Ȩ¼ @@ -677,12 +715,19 @@ namespace _24Hour.Controllers /// private const string secid = "e752e4fba67526eca21313a18c96a58f"; /// - /// ȡ΢openid + /// ȡ΢Сopenid /// /// /// [HttpGet("getOpenid")] public Task GetOpenId(string code) => wechatMessagerClient.GetOpenId(code); + /// + /// ȡ΢Źںopenid + /// + /// + /// + [HttpGet("GetGzhOpenId")] + public Task GetGzhOpenId(string code) => wechatMessagerClient.GetGzhOpenId(code); } diff --git a/24Hour/Controllers/system/SystemControllerController.cs b/24Hour/Controllers/system/SystemControllerController.cs index be5ef01..1c55225 100644 --- a/24Hour/Controllers/system/SystemControllerController.cs +++ b/24Hour/Controllers/system/SystemControllerController.cs @@ -367,7 +367,7 @@ namespace _24Hour.Controllers.system } /// - /// 用户绑定微信openid + /// 用户绑定微信小程序openid /// /// /// @@ -417,6 +417,57 @@ namespace _24Hour.Controllers.system return result; } + /// + /// 用户绑定微信公众号openid + /// + /// + /// + [HttpGet] + [Route("UserBindGzhWechat")] + public async Task UserBindGzhWechat(string code) + { + try + { + var getopenid = await wechatMessagerClient.GetGzhOpenId(code); + if (getopenid.IsSucceed == false) + { + return getopenid; + } + string openid = getopenid.result; + + if (await _db.Queryable().AnyAsync(x => x.wechatId == openid && x.IsDeleted == 0)) + { + result.IsSucceed = false; + result.Message = "当前微信已与其他账号绑定"; + return result; + } + + + var model = await _db.Queryable().Where(x => x.Id == _userdata.Id && x.IsDeleted == 0).FirstAsync(); + if (model != null) + { + model.wechatId = getopenid.result; + } + _db.BeginTran(); + var num = await _db.Updateable(model).UpdateColumns(it => new { it.wechatId }).ExecuteCommandAsync(); + //var num = await _db.Updateable(UserModel).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); + _db.CommitTran(); + if (num > 0) + { + result.IsSucceed = true; + result.result = getopenid.result; + } + } + catch (System.Exception ex) + { + _db.RollbackTran(); + result.IsSucceed = false; + result.Message = ex.Message; + } + _logs.WriteSysLogadd("用户管理", "修改人员信息", result, _db); + return result; + } + /// /// 删除用户 /// diff --git a/24Hour/WechatMessagerClient.cs b/24Hour/WechatMessagerClient.cs index 2650006..3a5f02f 100644 --- a/24Hour/WechatMessagerClient.cs +++ b/24Hour/WechatMessagerClient.cs @@ -28,6 +28,14 @@ namespace _24Hour /// private string secret = "wx48108a0c98a3dab0"; /// + /// 微信公众号AppID + /// + private string Gzhappid = "wx48108a0c98a3dab0"; + /// + /// 微信公众号密码 + /// + private string Gzhsecret = "wx48108a0c98a3dab0"; + /// /// 小程序secretID /// private string secid = "e752e4fba67526eca21313a18c96a58f"; @@ -43,7 +51,10 @@ namespace _24Hour appid = $"{configuration.GetSection("Wechat:appid").Value}"; secret = $"{configuration.GetSection("Wechat:secret").Value}"; secid = $"{configuration.GetSection("Wechat:secid").Value}"; + Gzhappid = $"{configuration.GetSection("WechatGzh:appid").Value}"; + Gzhsecret = $"{configuration.GetSection("WechatGzh:secret").Value}"; } + //小程序获取openId public async Task GetOpenId(string code) { var ret = new Result(); @@ -69,6 +80,36 @@ namespace _24Hour } return ret; } + /// + /// 微信公众号获取openId + /// + /// + /// + public async Task GetGzhOpenId(string code) + { + var ret = new Result(); + var reponse = HttpHelper.Get($" https://api.weixin.qq.com/sns/oauth2/access_token?appid={Gzhappid}&secret={Gzhsecret}&code={code}&grant_type=authorization_code"); + var opendata = reponse; + var data = JsonConvert.DeserializeAnonymousType(opendata, new + { + openid = default(string), + session_key = default(string), + unionid = default(string), + errcode = default(int), + errmsg = default(string), + }); + if (data.errcode == 0) + { + ret.IsSucceed = true; + ret.result = data.openid; + } + else + { + ret.IsSucceed = false; + ret.Message = data.errmsg; + } + return ret; + } /// /// 律师预约微信消息提醒,成功 @@ -156,7 +197,7 @@ namespace _24Hour if (string.IsNullOrEmpty(token)) { - string geturl = $"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx48108a0c98a3dab0&secret=e752e4fba67526eca21313a18c96a58f"; + string geturl = $"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={appid}&secret={secret}"; var re1 = HttpHelper.Get(geturl); if (re1.Jsonstr("errcode") == null) { @@ -211,5 +252,79 @@ namespace _24Hour return false; } + + + /// + /// 微信公众号消息提醒,推送检察官 + /// + /// + public bool gzhwxts(string? useropenId, string? name,string? phone, string? matter, string? attention) + { + try + { + var token = ""; + + // 获取缓存 + token = cache.Get("gzhtoken")?.ToString(); + + if (string.IsNullOrEmpty(token)) + { + string geturl = $"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={Gzhappid}&secret={Gzhsecret}"; + var re1 = HttpHelper.Get(geturl); + if (re1.Jsonstr("errcode") == null) + { + token = re1.Jsonstr("access_token"); + + // 移除缓存 + cache.Remove("gzhtoken"); + // 添加缓存 + cache.Add("gzhtoken", token, new CacheItemPolicy { AbsoluteExpiration = DateTime.Now.AddMinutes(120) }); + } + } + string url = $"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";//发送地址 + try + { + object msg = null; + string posturl = $"{url}{token}";//发送地址 + var thing4 = matter; + var thing5 = attention; + if (!string.IsNullOrEmpty(matter) && matter.Length > 20) + thing4 = matter.Substring(0, 17) + "..."; + if (!string.IsNullOrEmpty(attention) && attention.Length > 20) + thing5 = attention.Substring(0, 17) + "..."; + msg = new + { + touser = useropenId, + template_id = "SmCAFFqHSnGC4FnRBFgkmuBvTBWkPnWi4zkjshrpz_8", + //miniprogram =new{ + // appid= appid, + // pagepath= "pages/selfService/reception/reception" + //}, + //miniprogram_state = $"{_configuration.GetSection("Wechat:miniprogram_state").Value}", + //lang = "zh_CN", + data = new + { + //name1 = new { value = $"{name}"},// + thing1 = new { value = $"{name}" },// + phone_number4 = new { value = $"{phone}" },// + thing5 = new { value = $"{thing4}" },// + }, + }; + var re = HttpHelper.Post(posturl, msg); + if (re.Jsonstr("errcode") == "0") + return true; + return false; + } + catch (Exception ex) + { + } + return true; + } + catch (Exception ex) + { + } + return false; + } + } } diff --git a/24Hour/appsettings.json b/24Hour/appsettings.json index 63a1bc6..0ab9ad9 100644 --- a/24Hour/appsettings.json +++ b/24Hour/appsettings.json @@ -51,6 +51,10 @@ "secid": "e752e4fba67526eca21313a18c96a58f", "miniprogram_state": "trial" }, + "WechatGzh": { //微信公众号 + "appid": "wx1f5c662edbe3b627", + "secret": "a892658a8d21f4e97cbb1ec1880b78fd", + }, "CaseTwenty": { "SysAddress": "http://127.0.0.1:5194", "UseOfflineData": "true", diff --git a/Dto/obj/Debug/net6.0/Dto.csproj.CoreCompileInputs.cache b/Dto/obj/Debug/net6.0/Dto.csproj.CoreCompileInputs.cache index 1585df8..f324ba8 100644 --- a/Dto/obj/Debug/net6.0/Dto.csproj.CoreCompileInputs.cache +++ b/Dto/obj/Debug/net6.0/Dto.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -6045bad44ea6ca22bfa9bf856af27786e542aa85 +cc7e514c4ce4ef06a7f82aece20a70c7d8114bfe diff --git a/Elight.Entity/SystemDto/App_Sys_UserDto.cs b/Elight.Entity/SystemDto/App_Sys_UserDto.cs index c8740cc..e988440 100644 --- a/Elight.Entity/SystemDto/App_Sys_UserDto.cs +++ b/Elight.Entity/SystemDto/App_Sys_UserDto.cs @@ -142,6 +142,11 @@ namespace Elight.Entity /// [DataMember] public DateTime? createtime { get; set; } = DateTime.Now; + /// + /// 是否接收消息 + /// + [DataMember] + public bool? messages { get; set; } = false; } } diff --git a/Elight.Entity/SystemModel/App_Sys_UserModel.cs b/Elight.Entity/SystemModel/App_Sys_UserModel.cs index f9dfab6..c5fd23d 100644 --- a/Elight.Entity/SystemModel/App_Sys_UserModel.cs +++ b/Elight.Entity/SystemModel/App_Sys_UserModel.cs @@ -162,6 +162,11 @@ namespace Elight.Entity /// [DataMember] public DateTime? createtime { get; set; } = DateTime.Now; + /// + /// 是否接收消息 + /// + [DataMember] + public bool? messages { get; set; } = false; } }