Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. //using System.Text;
  5. using System.Threading.Tasks;
  6. //using Kingdee.API.SDK;
  7. using System.Net;
  8. using System.Net.Http;
  9. //using System.Text;
  10. using Newtonsoft.Json;
  11. using Newtonsoft.Json.Linq;
  12. namespace LrGetToken
  13. {
  14. public class clsGetToken
  15. {
  16. public async void GetAppSecret(string clientId, string clientSecret, string app_key, string outerInstanceId)
  17. {
  18. //var client = new APIClient("288026", "67ff1c3e744bed59c32c0dbc44a65648");
  19. //var apiRequest = new APIRequest();
  20. //apiRequest.Method = HttpMethod.Post;
  21. //apiRequest.Params.Add("outerInstanceId", "308290503223414784");
  22. //apiRequest.Path = "jdyconnector/app_management/push_app_authorize";
  23. //string strJson = client.HttpPost(apiRequest, clientId, "308290503223414784");
  24. //Console.WriteLine(strJson);
  25. //return strJson;
  26. var apiclient = new APIClient(clientId, clientSecret);
  27. APIRequest request = new APIRequest();
  28. request.Method = HttpMethod.Post;
  29. request.Params.Add("outerInstanceId", outerInstanceId);
  30. request.Path = "jdyconnector/app_management/push_app_authorize";
  31. var api_nonce = new Random().Next(100000000, 999999999);
  32. var timeStamp = (int)(DateTime.Now.ToLocalTime() - DateTime.Parse("1970-01-01").ToLocalTime()).TotalSeconds;
  33. var responseMessage = await apiclient.Execute(request, api_nonce.ToString(), timeStamp.ToString());
  34. Console.WriteLine(responseMessage.Content.ReadAsStringAsync().Result);
  35. }
  36. public string GetAppSecretB(string clientId, string clientSecret, string app_key, string outerInstanceId)
  37. {
  38. var client = new APIClient(clientId, clientSecret);
  39. var apiRequest = new APIRequest();
  40. apiRequest.Method = HttpMethod.Post;
  41. apiRequest.Path = "jdyconnector/app_management/push_app_authorize";
  42. apiRequest.Params.Add("outerInstanceId", outerInstanceId);
  43. var api_nonce = new Random().Next(100000000, 999999999);
  44. var timeStamp = (int)(DateTime.Now.ToLocalTime() - DateTime.Parse("1970-01-01").ToLocalTime()).TotalSeconds;
  45. string strJson = client.HttpPost(apiRequest, clientId, outerInstanceId, api_nonce.ToString(), timeStamp.ToString());
  46. Console.WriteLine(strJson);
  47. return strJson;
  48. }
  49. public string GetToken(string clientId, string clientSecret, string app_key, string appsecret)
  50. {
  51. try
  52. {
  53. var client = new APIClient(clientId, clientSecret);
  54. var apiRequest = new APIRequest();
  55. apiRequest.Method = HttpMethod.Get;
  56. apiRequest.Params.Add("app_key", app_key);
  57. apiRequest.Params.Add("app_signature", SHAHelper.HmacSHA256(appsecret, app_key));
  58. apiRequest.Path = "jdyconnector/app_management/kingdee_auth_token";
  59. //var token = await client.Execute(apiRequest);
  60. //Console.WriteLine(token.Content.ReadAsStringAsync().Result);
  61. var api_nonce = new Random().Next(100000000, 999999999);
  62. var timeStamp = (int)(DateTime.Now.ToLocalTime() - DateTime.Parse("1970-01-01").ToLocalTime()).TotalSeconds;
  63. string strJson = client.HttpGet(apiRequest, api_nonce.ToString(), timeStamp.ToString());
  64. Console.WriteLine(strJson);
  65. return strJson;
  66. }
  67. catch (Exception ex)
  68. {
  69. Console.WriteLine(ex.Message);
  70. return "";
  71. }
  72. }
  73. public string SaveBusiBill(string clientId, string clientSecret, string appToken, string strPath, string strX)
  74. {
  75. try
  76. {
  77. var client = new APIClient(clientId, clientSecret);
  78. var apiRequest = new APIRequest();
  79. apiRequest.Method = HttpMethod.Post;
  80. apiRequest.Path = strPath;
  81. var api_nonce = new Random().Next(100000000, 999999999);
  82. var timeStamp = (int)(DateTime.Now.ToLocalTime() - DateTime.Parse("1970-01-01").ToLocalTime()).TotalSeconds;
  83. string strJson = client.SaveBill(apiRequest, clientId, appToken, api_nonce.ToString(), timeStamp.ToString(), strX);
  84. Console.WriteLine(strJson);
  85. return strJson;
  86. }
  87. catch (Exception ex)
  88. {
  89. Console.WriteLine(ex.Message);
  90. return ex.Message;
  91. }
  92. }
  93. public string SaveBill(string clientId, string clientSecret, string appToken)
  94. {
  95. try
  96. {
  97. var client = new APIClient(clientId, clientSecret);
  98. var apiRequest = new APIRequest();
  99. apiRequest.Method = HttpMethod.Post;
  100. apiRequest.Path = "jdy/v2/scm/inv_product";
  101. JObject jsonRoot = new JObject();
  102. jsonRoot.Add("bill_date", DateTime.Today.ToString("yyyy-MM-dd"));
  103. jsonRoot.Add("operation_key", "submit");
  104. JArray EntryRows = new JArray();
  105. jsonRoot.Add("material_entity", EntryRows);
  106. JObject LstRow = new JObject();
  107. //EntryRows.Add(LstRow);
  108. //LstRow.Add("material_id", "2005881943043876864");
  109. //LstRow.Add("qty", "1");
  110. //LstRow.Add("stock_id", "2012264939519019008");
  111. //LstRow.Add("sp_id", "2012265084121842688");
  112. //LstRow.Add("batch_no", "2022332131");
  113. //LstRow.Add("unit_id", "2012274958041940992");
  114. //LstRow.Add("unit_cost", "1200");
  115. LstRow = new JObject();
  116. EntryRows.Add(LstRow);
  117. LstRow.Add("material_id", "2021039527732250624");
  118. LstRow.Add("qty", "1000");
  119. LstRow.Add("stock_id", "2021047289283366912");
  120. LstRow.Add("batch_no", "20240820");
  121. LstRow.Add("kf_period", "1");
  122. LstRow.Add("kf_date", "2024-08-20");
  123. LstRow.Add("kf_type", "3");
  124. LstRow.Add("valid_date", "2025-08-19");
  125. LstRow.Add("unit_id", "6");
  126. LstRow.Add("src_bill_type_id", "mo_task_bill");
  127. LstRow.Add("src_entry_id", "2021125909288894465");
  128. LstRow.Add("src_inter_id", "2021125909288894464");
  129. string strTmp = JsonConvert.SerializeObject(jsonRoot);
  130. string strX = jsonRoot.ToString();
  131. var api_nonce = new Random().Next(100000000, 999999999);
  132. var timeStamp = (int)(DateTime.Now.ToLocalTime() - DateTime.Parse("1970-01-01").ToLocalTime()).TotalSeconds;
  133. string strJson = client.SaveBill(apiRequest, clientId, appToken, api_nonce.ToString(), timeStamp.ToString(), strTmp);
  134. Console.WriteLine(strJson);
  135. return strJson;
  136. }
  137. catch (Exception ex)
  138. {
  139. Console.WriteLine(ex.Message);
  140. return "";
  141. }
  142. }
  143. }
  144. }