TkActivityController.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. using MySqlX.XDevAPI;
  15. using TencentCloud.Ame.V20190916.Models;
  16. using YunhuiKit;
  17. namespace molilian.api.Controllers
  18. {
  19. /// <summary>
  20. /// 淘宝会场活动
  21. /// </summary>
  22. [ApiController]
  23. [Route("[controller]/[action]")]
  24. public class TkActivityController : ControllerBase
  25. {
  26. protected IHttpContextAccessor _accessor;
  27. public TkActivityController(IHttpContextAccessor accessor)
  28. {
  29. _accessor = accessor;
  30. }
  31. [HttpPost]
  32. public async Task<ActionResult> Parse([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
  33. {
  34. //正文
  35. var page_id = form.Read("page_id", string.Empty);
  36. var item_id = form.Read("item_id", string.Empty);
  37. var strategy_id = form.Read("strategy_id", "1");
  38. var ip = form.Read("ip", string.Empty);
  39. var oaid = form.Read("oaid", string.Empty);
  40. //验证签名
  41. if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
  42. {
  43. return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
  44. }
  45. DateTime time1 = t.Convert2Datetime();
  46. if (time1 < DateTime.Now.AddMinutes(-10))
  47. {
  48. return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
  49. }
  50. var account = await ApiAccountCore.GetOneAsync(a);
  51. if (account == null)
  52. {
  53. return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
  54. }
  55. string app_sign = $"{account.api_secret}@{t}".MD5();
  56. if (sign != app_sign)
  57. {
  58. return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
  59. }
  60. string prefix = page_id switch
  61. {
  62. "20150318020021983" or "20150318020010092" or "20150318020019405" => "rec",
  63. _ => "top",
  64. };
  65. return await TkActivityCore.ParseAsync(page_id, prefix, item_id, strategy_id, ip, oaid);
  66. }
  67. [HttpPost]
  68. public async Task<ActionResult> unsafeParse([FromBody] JsonElement form)
  69. {
  70. var page_id = form.Read("page_id", string.Empty);
  71. var item_id = form.Read("item_id", string.Empty);
  72. var ip = form.Read("ip", string.Empty);
  73. var oaid = form.Read("oaid", string.Empty);
  74. var strategy_id = form.Read("strategy_id", string.Empty);
  75. string prefix = page_id switch
  76. {
  77. "20150318020021983" or "20150318020010092" or "20150318020019405" => "rec",
  78. _ => "top",
  79. };
  80. return await TkActivityCore.ParseAsync(page_id, prefix, item_id, strategy_id, ip, oaid);
  81. }
  82. }
  83. }