CpsController.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #if DEBUG
  43. #else
  44. //验证签名
  45. if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
  46. {
  47. return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
  48. }
  49. DateTime time1 = t.Convert2Datetime();
  50. if (time1 < DateTime.Now.AddMinutes(-10))
  51. {
  52. return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
  53. }
  54. var account = await ApiAccountCore.GetOneAsync(a);
  55. if (account == null)
  56. {
  57. return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
  58. }
  59. string app_sign = $"{account.api_secret}@{t}".MD5();
  60. if (sign != app_sign)
  61. {
  62. return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
  63. }
  64. #endif
  65. return await UnionCpsCore.UnionCpsAsync(channel, ip, oaid);
  66. }
  67. [HttpPost]
  68. public async Task<ActionResult> unsafeGetLink([FromBody] JsonElement form)
  69. {
  70. var channel = form.Read("c", string.Empty);
  71. var ip = form.Read("ip", string.Empty);
  72. var oaid = form.Read("oaid", string.Empty);
  73. #if DEBUG
  74. ip = "127.0.0.1";
  75. oaid = "test-oaid";
  76. #endif
  77. return await UnionCpsCore.UnionCpsAsync(channel, ip, oaid);
  78. }
  79. }
  80. }