ApiController.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 ApiController : ControllerBase
  19. {
  20. protected IHttpContextAccessor _accessor;
  21. TaokeOpenCore core;
  22. public ApiController(IHttpContextAccessor accessor)
  23. {
  24. _accessor = accessor;
  25. core = new TaokeOpenCore();
  26. }
  27. [HttpPost]
  28. public async Task<ActionResult> PromotionQuery([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
  29. {
  30. var img = form.Read("img", string.Empty);
  31. var url = form.Read("url", string.Empty);
  32. var ip = form.Read("ip", string.Empty);
  33. var oaid = form.Read("oaid", string.Empty);
  34. //验证签名
  35. if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
  36. {
  37. return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
  38. }
  39. DateTime time1 = t.Convert2Datetime();
  40. if (time1 < DateTime.Now.AddMinutes(-10))
  41. {
  42. return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
  43. }
  44. var account = ApiAccountCore.GetOne(a);
  45. if (account == null)
  46. {
  47. return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
  48. }
  49. string app_sign = $"{account.api_secret}@{t}".MD5();
  50. if (sign != app_sign)
  51. {
  52. return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
  53. }
  54. if (!string.IsNullOrEmpty(url))
  55. {
  56. var bytes = new WebClientUtility().Request(url).ResponseBody;
  57. img = Convert.ToBase64String(bytes);
  58. }
  59. return await core.PromotionQueryAsync(img, oaid, ip);
  60. }
  61. [HttpPost]
  62. public async Task<ActionResult> unsafePromotionQuery([FromBody] JsonElement form)
  63. {
  64. var img = form.Read("img", string.Empty);
  65. var url = form.Read("url", string.Empty);
  66. var ip = form.Read("ip", string.Empty);
  67. var oaid = form.Read("oaid", string.Empty);
  68. if (!string.IsNullOrEmpty(url))
  69. {
  70. var bytes = new WebClientUtility().Request(url).ResponseBody;
  71. img = Convert.ToBase64String(bytes);
  72. }
  73. return await core.PromotionQueryAsync(img, oaid, ip);
  74. }
  75. }
  76. }