Browse Source

新增公众号消息推送接口(律师注册完成后提醒检察官进行账号审核)

develop
liujiaqiang 2 years ago
parent
commit
e5d6ace7bb
  1. 30
      24Hour/Controllers/LoginController.cs
  2. 21
      24Hour/Controllers/system/SystemControllerController.cs
  3. 161
      24Hour/WechatMessagerClient.cs
  4. 5
      24Hour/appsettings.json

30
24Hour/Controllers/LoginController.cs

@ -523,6 +523,21 @@ namespace _24Hour.Controllers
_db.CommitTran();
if (num > 0)
{
#region ×¢²áÉêÇëÉóºË֪ͨ
var jcguserdata = await _db.Queryable<App_Sys_UserModel>()
.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<App_Sys_UserModel>()
.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 = "添加成功";
}

21
24Hour/Controllers/system/SystemControllerController.cs

@ -894,6 +894,17 @@ namespace _24Hour.Controllers.system
{
_db.BeginTran();
var userlist = await _db.Queryable<App_Sys_UserModel>().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 ? "认证通过" : "认证不通过";
}

161
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<Result> GetOpenId(string code)
@ -344,5 +346,164 @@ namespace _24Hour
return "失败";
}
/// <summary>
/// 微信公众号消息提醒,推送检察官(律师注册后提醒检察官审核)
/// </summary>
/// <returns></returns>
public async Task<string> 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 "失败";
}
/// <summary>
/// 微信公众号消息提醒,推送律师用户(检察官审核结果提醒)
/// </summary>
/// <returns></returns>
public async Task<string> 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 "失败";
}
}
}

5
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",

Loading…
Cancel
Save