similarController.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 SimilarController : ControllerBase
  19. {
  20. protected IHttpContextAccessor _accessor;
  21. public SimilarController(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 DEBUG
  67. ip = "127.0.0.1";
  68. oaid = "test-oaid";
  69. #endif
  70. if (!string.IsNullOrEmpty(url))
  71. {
  72. var bytes = new WebClientUtility().Request(url).ResponseBody;
  73. img = Convert.ToBase64String(bytes);
  74. }
  75. return await TaokeOpenCore.PromotionQueryAsync(img, oaid, ip);
  76. }
  77. }
  78. }