钉钉相关提醒接口

xyController.cs 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using ddAlter.DB;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.EntityFrameworkCore;
  5. using Newtonsoft.Json;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Net.Http;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace ddAlter.Controllers
  13. {
  14. [Route("api/[controller]")]
  15. [ApiController]
  16. public class xyController : ControllerBase
  17. {
  18. public readonly xyDBContext _context;
  19. public readonly IHttpClientFactory _httpClientFactory;
  20. public xyController(xyDBContext context, IHttpClientFactory httpClientFactory)
  21. {
  22. _context = context;
  23. _httpClientFactory = httpClientFactory;
  24. }
  25. [HttpGet]
  26. [Route("missing-call-record-alter")]
  27. async public Task<ActionResult> MissingCallRecordAlter()
  28. {
  29. var data = _context.RecordCount.FromSqlRaw(@"select COUNT(1) as num from T_Call_CallRecords where CallType=0 and BeginTime>DATEADD(MINUTE,-10,GETDATE()) and (CallState=1 or WaitStartTime is not null)
  30. and BusinessType not in (select F_Key from T_Sys_DHKeys with(nolock) where F_Type = 2 or F_Type = 3)").ToList();
  31. if (data == null || data.Count <= 0 || data[0].num < 1)
  32. {
  33. // 发送报警
  34. var msg = new
  35. {
  36. msgtype = "text",
  37. text = new
  38. {
  39. content = "【信阳-报警】连续10分钟内没有录音生成,请检查服务状态!"
  40. },
  41. at = new
  42. {
  43. isAtAll = true
  44. }
  45. };
  46. // https://oapi.dingtalk.com/robot/send?access_token=d4efe5b71f2e92a11ff89bb8ad704319e2d874ef5e590e8a78247405542bf637
  47. var sendMessage = JsonConvert.SerializeObject(msg);
  48. var request = new HttpRequestMessage(HttpMethod.Post, "/robot/send?access_token=d4efe5b71f2e92a11ff89bb8ad704319e2d874ef5e590e8a78247405542bf637")
  49. {
  50. Content = new StringContent(sendMessage, Encoding.UTF8, "application/json")
  51. };
  52. var client = _httpClientFactory.CreateClient("client_dd");
  53. client.Timeout = TimeSpan.FromSeconds(10);
  54. var response = await client.SendAsync(request);
  55. var result = response.Content.ReadAsStringAsync();
  56. return Ok(new
  57. {
  58. msg = result,
  59. num = data[0].num
  60. }) ;
  61. }
  62. return Ok(new
  63. {
  64. num = data[0].num
  65. });
  66. }
  67. }
  68. }