H5Controller.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. var api = DataokeCore.GetOne();
  28. if (api == null)
  29. {
  30. return new APIResult(new
  31. {
  32. success = false,
  33. message = "没有可用签名账户"
  34. });
  35. }
  36. int nonce;
  37. string timer;
  38. DtkApp app = new(api.app_key, api.app_secret);
  39. string sign = app.MakeSign(out nonce, out timer);
  40. string sign_url = $"appKey={api.app_key}&nonce={nonce}&signRan={sign}&timer={timer}";
  41. 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=
  42. return new APIResult(new
  43. {
  44. success = true,
  45. message = "ok",
  46. sign_url
  47. });
  48. }
  49. [HttpPost]
  50. public ActionResult ddsign([FromBody] JsonElement form)
  51. {
  52. var api = PddPoolCore.GetOne();
  53. if (api == null)
  54. {
  55. return new APIResult(new
  56. {
  57. success = false,
  58. message = "没有可用签名账户"
  59. });
  60. }
  61. string ts = DateTime.Now.Convert2UnixTimestamp().ToString();
  62. string url = $"https://gw-api.pinduoduo.com/api/router";
  63. Dictionary<string, string> args = new Dictionary<string, string>
  64. {
  65. { "client_id", api.app_key },
  66. { "timestamp", ts }
  67. };
  68. // 提取客户端的业务参数并排除 "client_id" 和 "timestamp"
  69. foreach (JsonProperty prop in form.EnumerateObject())
  70. {
  71. if (prop.Name != "client_id" && prop.Name != "timestamp")
  72. {
  73. args.Add(prop.Name, prop.Value.GetString());
  74. }
  75. }
  76. ////其他业务参数接收客户端的form,记得排除client_id 和 timestamp
  77. //args.Add("type", "pdd.ddk.goods.recommend.get");
  78. //args.Add("data_type", "JSON");
  79. //args.Add("custom_parameters", "5");
  80. args = PddPoolCore.GenerateSignature(api, args);
  81. string queryString = string.Join("&", args.Select(kv => $"{HttpUtility.UrlEncode(kv.Key)}={HttpUtility.UrlEncode(kv.Value)}"));
  82. string sign_url = $"{url}?{queryString}";
  83. return new APIResult(new
  84. {
  85. success = true,
  86. message = "ok",
  87. sign_url
  88. });
  89. //WebClientUtility client = new WebClientUtility();
  90. //var response = client.Request(url);
  91. //var body = response.Body();
  92. //return Content(body);
  93. }
  94. }
  95. }