RootController.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Org.BouncyCastle.Ocsp;
  5. using System.Text.Json;
  6. using System.Runtime.InteropServices;
  7. using System.Net;
  8. using System.Security.Cryptography;
  9. using Microsoft.AspNetCore.Authentication;
  10. using TencentCloud.Ecm.V20190719.Models;
  11. using COSXML.Network;
  12. using System.Linq;
  13. using static dodohold.core.ZTOExpress.CreateOrderArgs;
  14. namespace molilian.api.Controllers
  15. {
  16. [ApiController]
  17. [Route("api/[action]")]
  18. public class RootController : ControllerBase
  19. {
  20. protected IHttpContextAccessor _accessor;
  21. public RootController(IHttpContextAccessor accessor)
  22. {
  23. _accessor = accessor;
  24. }
  25. [HttpPost]
  26. public async Task<ActionResult> PromotionQuery([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
  27. {
  28. var img = form.Read("img", string.Empty);
  29. var url = form.Read("url", string.Empty);
  30. var ip = form.Read("ip", string.Empty);
  31. var oaid = form.Read("oaid", string.Empty);
  32. //验证签名
  33. if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
  34. {
  35. return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
  36. }
  37. DateTime time1 = t.Convert2Datetime();
  38. if (time1 < DateTime.Now.AddMinutes(-10))
  39. {
  40. return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
  41. }
  42. var account = ApiAccountCore.GetOne(a);
  43. if (account == null)
  44. {
  45. return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
  46. }
  47. string app_sign = $"{account.api_secret}@{t}".MD5();
  48. if (sign != app_sign)
  49. {
  50. return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
  51. }
  52. if (!string.IsNullOrEmpty(url))
  53. {
  54. var bytes = new WebClientUtility().Request(url).ResponseBody;
  55. img = Convert.ToBase64String(bytes);
  56. }
  57. return await TaokeOpenCore.PromotionQueryAsync(img, oaid, ip);
  58. }
  59. [HttpPost]
  60. public async Task<ActionResult> unsafePromotionQuery([FromBody] JsonElement form)
  61. {
  62. var img = form.Read("img", string.Empty);
  63. var url = form.Read("url", string.Empty);
  64. var ip = form.Read("ip", string.Empty);
  65. var oaid = form.Read("oaid", string.Empty);
  66. if (!string.IsNullOrEmpty(url))
  67. {
  68. var bytes = new WebClientUtility().Request(url).ResponseBody;
  69. img = Convert.ToBase64String(bytes);
  70. }
  71. return await TaokeOpenCore.PromotionQueryAsync(img, oaid, ip);
  72. }
  73. }
  74. }