CpsController.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. namespace molilian.api.Controllers
  16. {
  17. [ApiController]
  18. [Route("[controller]/[action]")]
  19. public class CpsController : ControllerBase
  20. {
  21. protected IHttpContextAccessor _accessor;
  22. public CpsController(IHttpContextAccessor accessor)
  23. {
  24. _accessor = accessor;
  25. }
  26. /// <summary>
  27. /// oppo调用
  28. /// </summary>
  29. /// <param name="c">渠道。tb/jd</param>
  30. /// <param name="a">分配的客户端账号</param>
  31. /// <param name="t">11位时间戳</param>
  32. /// <param name="sign">签名</param>
  33. /// <param name="ip">客户的IP</param>
  34. /// <param name="oaid">客户的唯一ID</param>
  35. /// <returns></returns>
  36. [HttpPost]
  37. public async Task<ActionResult> getLink([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
  38. {
  39. var channel = form.Read("c", string.Empty);
  40. var ip = form.Read("ip", string.Empty);
  41. var oaid = form.Read("oaid", string.Empty);
  42. var style = form.Read("style", string.Empty);
  43. #if DEBUG
  44. #else
  45. //验证签名
  46. if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
  47. {
  48. return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
  49. }
  50. DateTime time1 = t.Convert2Datetime();
  51. if (time1 < DateTime.Now.AddMinutes(-10))
  52. {
  53. return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
  54. }
  55. var account = await ApiAccountCore.GetOneAsync(a);
  56. if (account == null)
  57. {
  58. return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
  59. }
  60. string app_sign = $"{account.api_secret}@{t}".MD5();
  61. if (sign != app_sign)
  62. {
  63. return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
  64. }
  65. #endif
  66. return await UnionCpsCore.UnionCpsAsync(channel, style, ip, oaid);
  67. }
  68. [HttpPost]
  69. public async Task<ActionResult> unsafeGetLink([FromBody] JsonElement form)
  70. {
  71. var channel = form.Read("c", string.Empty);
  72. var ip = form.Read("ip", string.Empty);
  73. var oaid = form.Read("oaid", string.Empty);
  74. var style = form.Read("style", string.Empty);
  75. #if DEBUG
  76. ip = "127.0.0.1";
  77. oaid = "test-oaid";
  78. #endif
  79. return await UnionCpsCore.UnionCpsAsync(channel, style, ip, oaid);
  80. }
  81. }
  82. }