H5Controller.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 Dataoke;
  12. using System.Web;
  13. namespace molilian.api.Controllers
  14. {
  15. [ApiController]
  16. [Route("[controller]/[action]")]
  17. public class H5Controller : ControllerBase
  18. {
  19. protected IHttpContextAccessor _accessor;
  20. public H5Controller(IHttpContextAccessor accessor)
  21. {
  22. _accessor = accessor;
  23. }
  24. [HttpGet]
  25. public ActionResult sign()
  26. {
  27. string referer = _accessor.HttpContext.Request.Referer();
  28. var api = DataokeCore.GetOne(referer);
  29. if (api == null)
  30. {
  31. return new APIResult(new
  32. {
  33. success = false,
  34. message = "没有可用签名账户"
  35. });
  36. }
  37. int nonce;
  38. string timer;
  39. DtkApp app = new(api.app_key, api.app_secret);
  40. string sign = app.MakeSign(out nonce, out timer);
  41. string sign_url = $"appKey={api.app_key}&nonce={nonce}&signRan={sign}&timer={timer}";
  42. https://openapi.dataoke.com/api/tb-service/get-privilege-link?appKey=663dc44dcb55f&nonce=955350&signRan=9FFB668FD91AD897C238C536899C92EC&timer=1716116967528&version=v1.3.1&pid=236e3aa943d948339732430b74737328&goodsId=jyn335Ds0tJYG9g9g0IN6PCJte-GPgAyeRIqOVrK3W0HnY&coupon_id=
  43. return new APIResult(new
  44. {
  45. success = true,
  46. message = "ok",
  47. sign_url
  48. });
  49. }
  50. [HttpPost]
  51. public ActionResult ddsign([FromBody] JsonElement form)
  52. {
  53. var api = PddPoolCore.GetOne();
  54. if (api == null)
  55. {
  56. return new APIResult(new
  57. {
  58. success = false,
  59. message = "没有可用签名账户"
  60. });
  61. }
  62. string ts = DateTime.Now.Convert2UnixTimestamp().ToString();
  63. string url = $"https://gw-api.pinduoduo.com/api/router";
  64. Dictionary<string, string> args = new Dictionary<string, string>
  65. {
  66. { "client_id", api.app_key },
  67. { "timestamp", ts }
  68. };
  69. // 提取客户端的业务参数并排除 "client_id" 和 "timestamp"
  70. foreach (JsonProperty prop in form.EnumerateObject())
  71. {
  72. if (prop.Name != "client_id" && prop.Name != "timestamp")
  73. {
  74. args.Add(prop.Name, prop.Value.GetString());
  75. }
  76. }
  77. ////其他业务参数接收客户端的form,记得排除client_id 和 timestamp
  78. //args.Add("type", "pdd.ddk.goods.recommend.get");
  79. //args.Add("data_type", "JSON");
  80. //args.Add("custom_parameters", "5");
  81. args = PddPoolCore.GenerateSignature(api, args);
  82. string queryString = string.Join("&", args.Select(kv => $"{HttpUtility.UrlEncode(kv.Key)}={HttpUtility.UrlEncode(kv.Value)}"));
  83. string sign_url = $"{url}?{queryString}";
  84. return new APIResult(new
  85. {
  86. success = true,
  87. message = "ok",
  88. sign_url
  89. });
  90. //WebClientUtility client = new WebClientUtility();
  91. //var response = client.Request(url);
  92. //var body = response.Body();
  93. //return Content(body);
  94. }
  95. }
  96. }