ServiceErrorNoticeHelper.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Cksoft.Data;
  2. using Cksoft.Data.Repository;
  3. using Cksoft.Unity;
  4. using Cksoft.Unity.Log4NetConfig;
  5. using DllEapEntity;
  6. using DllEapEntity.OFILM;
  7. using Microsoft.Extensions.Configuration;
  8. using Newtonsoft.Json;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace DllEapCommon.Notice
  15. {
  16. public class ServiceErrorNoticeHelper
  17. {
  18. public static void Notice(string content, ref string errorinfo)
  19. {
  20. var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
  21. var configuration = builder.Build();
  22. var lanxinConfig = configuration.GetSection("LanXinConfig").Get<LanxinConfig>();
  23. if (lanxinConfig == null)
  24. {
  25. errorinfo = "配置文件中LanXin节点未找到或配置不正确";
  26. return;
  27. }
  28. var requestData = new LanxinRequestDto
  29. {
  30. Appid = lanxinConfig.Appid,
  31. Secret = lanxinConfig.Secret,
  32. Tousers = lanxinConfig.Tousers,
  33. Content = content
  34. };
  35. var json = JsonConvert.SerializeObject(requestData);
  36. var res = HttpRequestHelper<OfilmLanxinReponseDto>.Post(lanxinConfig.Url, json, ref errorinfo, "application/json");
  37. if (res == null || res.Code != 1)
  38. {
  39. errorinfo = $"推送机台[{content}]BI信息失败:{res.Message ?? "请求蓝信接口异常"}";
  40. }
  41. }
  42. /// <summary>
  43. /// WebApi接口调用失败预警
  44. /// </summary>
  45. /// <param name="content"></param>
  46. /// <param name="errorinfo"></param>
  47. public static void NoticeApiError(string content, ref string errorinfo)
  48. {
  49. var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
  50. var configuration = builder.Build();
  51. var lanxinConfig = configuration.GetSection("LanXinConfig").Get<LanxinConfig>();
  52. if (lanxinConfig == null)
  53. {
  54. errorinfo = "配置文件中LanXin节点未找到或配置不正确";
  55. return;
  56. }
  57. var requestData = new LanxinRequestDto
  58. {
  59. Appid = lanxinConfig.Appid,
  60. Secret = lanxinConfig.Secret,
  61. Tousers = lanxinConfig.Tousers,
  62. Content = content
  63. };
  64. var json = JsonConvert.SerializeObject(requestData);
  65. var res = HttpRequestHelper<OfilmLanxinReponseDto>.Post(lanxinConfig.Url, json, ref errorinfo, "application/json");
  66. if (res == null || res.Code != 1)
  67. {
  68. errorinfo = $"推送提醒失败:{res.Message ?? "请求蓝信接口异常"}";
  69. LogHelper<ServiceErrorNoticeHelper>.LogError(errorinfo,
  70. "接口调用", string.Empty);
  71. }
  72. }
  73. }
  74. }