ForwardController.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.AspNetCore.Mvc;
  4. using System.Text.Json;
  5. namespace molilian.api.Controllers
  6. {
  7. [ApiController]
  8. [Route("[controller]/[action]")]
  9. public class ForwardController : ControllerBase
  10. {
  11. protected IHttpContextAccessor _accessor;
  12. public ForwardController(IHttpContextAccessor accessor)
  13. {
  14. _accessor = accessor;
  15. }
  16. //https://api.molilian.vip/forward/qyapi2ntfy/5Sq9BytXXM5WDY3G
  17. [HttpPost]
  18. public ActionResult qyapi2ntfy(string url, [FromBody] JsonElement form)
  19. {
  20. int errcode = 0;
  21. string errmsg = "ok";
  22. string publish_url = string.Empty, topic = string.Empty;
  23. if (string.IsNullOrEmpty(url))
  24. {
  25. errcode = 93000;
  26. errmsg = "Invalid ntfy server or topic";
  27. return new APIResult(new { errmsg, errcode });
  28. }
  29. string msgtype = form.Read("msgtype", string.Empty);
  30. switch (msgtype)
  31. {
  32. case "text":
  33. {
  34. string content = form.PathRead("text.content", string.Empty);
  35. NifyPlus.Send(url, new NifyMessage
  36. {
  37. message = content,
  38. });
  39. break;
  40. }
  41. case "markdown":
  42. {
  43. string content = form.PathRead("markdown.content", string.Empty);
  44. NifyPlus.Send(url, new NifyMessage
  45. {
  46. markdown = true,
  47. message = content,
  48. });
  49. /*
  50. {
  51. "topic": "sTXE2kwKp9u8tgnM",
  52. "message": "#### \u6D88\u606F\u901A\u9053\u914D\u7F6E\u63D0\u9192\n \u003E\u670D\u52A1\u5668\uFF1A\u5B9D\u5854Linux\u9762\u677F\n \u003EIP\u5730\u5740\uFF1A127.0.0.1(\u5916) 89.58.28.154(\u5185)\n \u003E\u53D1\u9001\u65F6\u95F4\uFF1A2024-04-07 12:58:42\n \u003E\u914D\u7F6E\u72B6\u6001\uFF1A\u003Cfont color=#20a53a\u003E\u6210\u529F\u003C/font\u003E",
  53. "title": "",
  54. "tags": [],
  55. "priority": 3,
  56. "click": "",
  57. "attach": "",
  58. "markdown": true,
  59. "icon": ""
  60. }
  61. */
  62. break;
  63. }
  64. }
  65. _ = new LoggerLibrary("forward", "qyapi2ntfy").Info(form.Convert2Json()).SaveAsync();
  66. return new APIResult(new { errmsg, errcode });
  67. }
  68. }
  69. }