diff --git a/24Hour/Controllers/LoginController.cs b/24Hour/Controllers/LoginController.cs index bf6ce2d..baa45c2 100644 --- a/24Hour/Controllers/LoginController.cs +++ b/24Hour/Controllers/LoginController.cs @@ -523,6 +523,21 @@ namespace _24Hour.Controllers _db.CommitTran(); if (num > 0) { + #region ע֪ͨ + var jcguserdata = await _db.Queryable() + .Where(q => q.usertype == 0 && q.messages == true).ToListAsync(); + if (jcguserdata.Count > 0) + { + foreach (var item in jcguserdata) + { + if (!string.IsNullOrEmpty(item.wechatId)) + { + //ʦע֪ͨ + await wechatMessagerClient.gzhwxtsshtx(item.wechatId, UserModel.name, UserModel.phone, UserModel.departmentName, DateTime.Now); + } + } + } + #endregion ret.IsSucceed = true; ret.result = "ӳɹ,У"; } @@ -543,6 +558,21 @@ namespace _24Hour.Controllers _db.CommitTran(); if (num > 0) { + #region ע֪ͨ + var jcguserdata = await _db.Queryable() + .Where(q => q.usertype == 0 && q.messages == true).ToListAsync(); + if (jcguserdata.Count > 0) + { + foreach (var item in jcguserdata) + { + if (!string.IsNullOrEmpty(item.wechatId)) + { + //ʦע֪ͨ + await wechatMessagerClient.gzhwxtsshtx(item.wechatId, UserModel.name, UserModel.phone, UserModel.departmentName, DateTime.Now); + } + } + } + #endregion ret.IsSucceed = true; ret.result = "ӳɹ"; } diff --git a/24Hour/Controllers/system/SystemControllerController.cs b/24Hour/Controllers/system/SystemControllerController.cs index ed5ba13..237a0a0 100644 --- a/24Hour/Controllers/system/SystemControllerController.cs +++ b/24Hour/Controllers/system/SystemControllerController.cs @@ -893,7 +893,18 @@ namespace _24Hour.Controllers.system try { _db.BeginTran(); - var userlist = await _db.Queryable().Where(q => q.IsDeleted == 0 && q.Id == Id).ToListAsync(); + var userlist = await _db.Queryable().Where(q => q.IsDeleted == 0 && q.Id == Id).ToListAsync(); + if (userlist.Count > 0) + { + var data = userlist.FirstOrDefault(); + if (data.audit != 0) + { + result.IsSucceed = false; + result.result = "已审核处理!"; + result.Message = "已审核处理!"; + return result; + } + } userlist.ForEach(q => { q.audit = status; @@ -902,7 +913,15 @@ namespace _24Hour.Controllers.system var num = await _db.Updateable(userlist).ExecuteCommandAsync(); _db.CommitTran(); if (num > 0) - { + { //认证结果消息通知 + if (userlist.Count > 0) + { + var str = status == 0 ? "认证通过" : "认证不通过"; + if (!string.IsNullOrEmpty(userlist.FirstOrDefault().wechatId)) + { + await wechatMessagerClient.gzhwxtsshtxjg(userlist.FirstOrDefault().wechatId, str, "", userlist.FirstOrDefault()?.createtime, DateTime.Now); + } + } result.IsSucceed = true; result.result = status == 0 ? "认证通过" : "认证不通过"; } diff --git a/24Hour/WechatMessagerClient.cs b/24Hour/WechatMessagerClient.cs index bd55eda..b559baf 100644 --- a/24Hour/WechatMessagerClient.cs +++ b/24Hour/WechatMessagerClient.cs @@ -4,6 +4,7 @@ using Elight.Utility; using Elight.Utility.Code; using Elight.Utility.Extensions; using java.lang.annotation; +using java.util; using Microsoft.IdentityModel.Logging; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -63,6 +64,7 @@ namespace _24Hour GzhtemplateId = $"{configuration.GetSection("WechatGzh:templateId").Value}"; TemplateIdSuccess = $"{configuration.GetSection("Wechat:templateIdSuccess").Value}"; TemplateIdFail = $"{configuration.GetSection("Wechat:templateIdFail").Value}"; + TemplateIdFail = $"{configuration.GetSection("Wechat:templateIdFail").Value}"; } //小程序获取openId public async Task GetOpenId(string code) @@ -344,5 +346,164 @@ namespace _24Hour return "失败"; } + + /// + /// 微信公众号消息提醒,推送检察官(律师注册后提醒检察官审核) + /// + /// + public async Task gzhwxtsshtx(string? useropenId, string? name, string? phone, string? company, DateTime? time) + { + 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 = name; + var thing5 = company; + if (!string.IsNullOrEmpty(name) && name.Length > 20) + thing4 = name.Substring(0, 17) + "..."; + if (!string.IsNullOrEmpty(company) && company.Length > 20) + thing5 = company.Substring(0, 17) + "..."; + msg = new + { + touser = useropenId, + template_id = $"{_configuration.GetSection("WechatGzh:templateId1").Value}", + //miniprogram =new{ + // appid= appid, + // pagepath= "pages/selfService/reception/reception" + //}, + //miniprogram_state = $"{_configuration.GetSection("Wechat:miniprogram_state").Value}", + //lang = "zh_CN", + //data = new + //{ + // thing3 = new { value = $"{thing5}"}, + // thing1 = new { value = $"{thing4}" }, + // phone_number5 = new { value = $"{phone}" }, + // time4 = new { value = $"{time.Value.ToString("yyyy-MM-dd HH:mm")}" }, + //}, + data = new + { + thing1 = new { value = $"{thing4}" }, + thing2 = new { value = $"{thing5}" }, + time3 = new { value = $"{time.Value.ToString("yyyy-MM-dd HH:mm")}" }, + }, + }; + var re = HttpHelper.Post(posturl, msg); + if (re.Jsonstr("errcode") == "0") + return "成功"; + return $"失败:{re}"; + } + catch (Exception ex) + { + return $"{ex.Message}"; + } + return "成功"; + } + catch (Exception ex) + { + return $"{ex.Message}"; + } + return "失败"; + } + + + /// + /// 微信公众号消息提醒,推送律师用户(检察官审核结果提醒) + /// + /// + public async Task gzhwxtsshtxjg(string useropenId, string name, string? phone, DateTime? time1, DateTime time2) + { + 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 = name; + if (!string.IsNullOrEmpty(name) && name.Length > 20) + thing4 = name.Substring(0, 17) + "..."; + msg = new + { + touser = useropenId, + template_id = $"{_configuration.GetSection("WechatGzh:templateId2").Value}", + //miniprogram =new{ + // appid= appid, + // pagepath= "pages/selfService/reception/reception" + //}, + //miniprogram_state = $"{_configuration.GetSection("Wechat:miniprogram_state").Value}", + //lang = "zh_CN", + //data = new + //{ + // thing3 = new { value = $"{thing5}"}, + // thing1 = new { value = $"{thing4}" }, + // phone_number5 = new { value = $"{phone}" }, + // time4 = new { value = $"{time.Value.ToString("yyyy-MM-dd HH:mm")}" }, + //}, + data = new + { + thing3 = new { value = $"{name}" }, + time4 = new { value = $"{time1.Value.ToString("yyyy-MM-dd HH:mm")}" }, + time5 = new { value = $"{time2.ToString("yyyy-MM-dd HH:mm")}" }, + }, + }; + var re = HttpHelper.Post(posturl, msg); + if (re.Jsonstr("errcode") == "0") + return "成功"; + return $"失败:{re}"; + } + catch (Exception ex) + { + return $"{ex.Message}"; + } + return "成功"; + } + catch (Exception ex) + { + return $"{ex.Message}"; + } + return "失败"; + } + } } diff --git a/24Hour/appsettings.json b/24Hour/appsettings.json index 3ac2acd..baed712 100644 --- a/24Hour/appsettings.json +++ b/24Hour/appsettings.json @@ -73,7 +73,12 @@ //赞皇微信公众号 //"appid": "wxe06040af55282ee8", //"secret": "8ffcdb30277eba9f4861f39a66990237", + //预约消息提醒 //"templateId": "2OIGzOuT1Xobi7xQV9AVH-A286HZ0FsayW6ON2n5_30" + //律师注册审核消息提醒 + //"templateId1": "cCIkyiWffdAJEX4QQyxsmdaPt-JKib5I4rhCflwcebU" + //律师注册审核结果提醒 + //"templateId2": "68FkacsufQ5klTZTM4qFcZHfQrsDrAQeiu6R0Chb6B8" }, "CaseTwenty": { "SysAddress": "http://127.0.0.1:5194",