HomeController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Data;
  6. using System.Threading.Tasks;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.Extensions.Logging;
  9. using MySystem.Models;
  10. using System.Threading;
  11. using Library;
  12. using LitJson;
  13. namespace MySystem.Controllers
  14. {
  15. public class HomeController : Controller
  16. {
  17. private readonly ILogger<HomeController> _logger;
  18. public HomeController(ILogger<HomeController> logger)
  19. {
  20. _logger = logger;
  21. }
  22. public IActionResult Index()
  23. {
  24. return View();
  25. }
  26. public IActionResult Error()
  27. {
  28. string isapi = Request.Headers["Api"].ToString();
  29. if (isapi != "1")
  30. {
  31. if (Response.StatusCode == 500)
  32. {
  33. return Redirect("/public/errpage/pc/500.html");
  34. }
  35. else if (Response.StatusCode == 502)
  36. {
  37. return Redirect("/public/errpage/pc/502.html");
  38. }
  39. else if (Response.StatusCode == 404)
  40. {
  41. return Redirect("/public/errpage/pc/404.html");
  42. }
  43. }
  44. return View();
  45. }
  46. public string test(int id = 0)
  47. {
  48. string txt = "ok";
  49. // txt = WeChatFunction.Instance.QueryProfitShare("1646405429","4200001807202306098649105270","2023060910241258564572510");
  50. // ProfitHelper.Instance.ReturnStat(Id, 2);
  51. WebCMSEntities db = new WebCMSEntities();
  52. List<int> oids = new List<int>();
  53. if(id > 0)
  54. {
  55. oids.Add(id);
  56. }
  57. else
  58. {
  59. oids.Add(15);
  60. oids.Add(16);
  61. oids.Add(17);
  62. oids.Add(18);
  63. oids.Add(19);
  64. oids.Add(20);
  65. }
  66. foreach(int oid in oids)
  67. {
  68. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == oid);
  69. if(order != null)
  70. {
  71. RedisDbconn.Instance.AddList("ConsumerOrders:Divi:2:List", order.Id.ToString());
  72. // RedisDbconn.Instance.AddList("ConsumerOrders:Divi:2:" + order.MerchantId, order);
  73. }
  74. }
  75. db.Dispose();
  76. return txt;
  77. }
  78. public string testAlipay()
  79. {
  80. // string content = AlipayFunction.Instance.QuerySignStatus("2023061317351531100060045");
  81. // List<RoyaltyParameters> Parameters = new List<RoyaltyParameters>();
  82. // Parameters.Add(new RoyaltyParameters()
  83. // {
  84. // Account = "2088141704579033",
  85. // Amount = "0.01",
  86. // });
  87. // string content = AlipayFunction.Instance.Settle("2023061615441556447868073", "2023061622001451251436120885", Parameters);
  88. // string content = AlipayFunction.Instance.BindSettleRelation(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), "2088141704579033");
  89. // string content = AlipayFunction.Instance.Refund("2023061622001451251436120885", "0.01", "门店分红");
  90. // string content = AlipayFunction.Instance.QuerySettle("2023071214274372011988068", "2023071222001457121457238496", "202307BB6d61386d17104395831e3ea6309f0X57");
  91. // MerchantConfirmService.Instance.StartDo(68, 2);
  92. // string content = AlipayFunction.Instance.BindSettleRelation(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), AlipayFunction.Instance.Pid, "202307BB6d61386d17104395831e3ea6309f0X57");
  93. List<string> ordernos = new List<string>();
  94. ordernos.Add("2023083018185453946193409");
  95. ordernos.Add("2023083020130453429050364");
  96. ordernos.Add("2023083020120518590325447");
  97. ordernos.Add("2023083018145549174540449");
  98. ordernos.Add("2023083018233529291795428");
  99. ordernos.Add("2023083019384237451076842");
  100. ordernos.Add("2023091220063534056177559");
  101. ordernos.Add("2023083019193537632563171");
  102. ordernos.Add("2023083019152337193420395");
  103. ordernos.Add("2023083018121967866866300");
  104. ordernos.Add("2023081715193607722249986");
  105. WebCMSEntities db = new WebCMSEntities();
  106. List<ConsumerOrders> orders = db.ConsumerOrders.Where(m => ordernos.Contains(m.OrderNo)).OrderBy(m => m.Id).ToList();
  107. foreach(ConsumerOrders order in orders)
  108. {
  109. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantInfo();
  110. MerchantParamSet set = db.MerchantParamSet.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantParamSet();
  111. if(order.IsAct == 1 && order.PayMoney >= set.MinPayMoney)
  112. {
  113. MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
  114. // //添加分账接收方
  115. // if(merchantAdd.Sort == 0)
  116. // {
  117. // string content = AlipayFunction.Instance.BindSettleRelation(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), AlipayFunction.Instance.Pid, merchantAdd.AlipayAuthToken);
  118. // LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + content, "支付宝添加分账方");
  119. // merchantAdd.Sort = 1;
  120. // db.SaveChanges();
  121. // }
  122. // //发起分账
  123. // decimal fee = order.PayMoney * 0.01M;
  124. // if(fee >= 0.01M)
  125. // {
  126. // string TradeNo = order.SeoTitle;
  127. // string OrderNo = order.OrderNo;
  128. // List<RoyaltyParameters> Parameters = new List<RoyaltyParameters>();
  129. // Parameters.Add(new RoyaltyParameters()
  130. // {
  131. // Account = AlipayFunction.Instance.Pid,
  132. // Amount = fee.ToString("f2"),
  133. // });
  134. // AlipayFunction.Instance.Settle(OrderNo, TradeNo, Parameters, merchantAdd.AlipayAuthToken);
  135. // //开始监听分账状态
  136. // Dictionary<string, object> req = new Dictionary<string, object>();
  137. // req.Add("TradeNo", TradeNo); //支付宝订单号
  138. // req.Add("OrderNo", OrderNo); //商户订单号
  139. // req.Add("AuthToken", merchantAdd.AlipayAuthToken);
  140. // RedisDbconn.Instance.AddList("AlipayShareQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req));
  141. // }
  142. //添加分账接收方
  143. if(merchant.Version == 0)
  144. {
  145. WeChatFunction.Instance.AddReceive(merchantAdd.SubMchid, "MERCHANT_ID", WeChatFunction.Instance.MchId, WeChatFunction.Instance.MchName, "PARTNER");
  146. merchant.Version = 1;
  147. db.SaveChanges();
  148. }
  149. //发起分账
  150. decimal fee = order.PayMoney; //单位:分
  151. if(fee >= 1)
  152. {
  153. string TradeNo = order.SeoTitle;
  154. string OrderNo = order.OrderNo;
  155. List<ReceiverList> Receivers = new List<ReceiverList>();
  156. Receivers.Add(new ReceiverList()
  157. {
  158. type = "MERCHANT_ID", //分账接收方类型
  159. account = WeChatFunction.Instance.MchId, //分账接收方账号
  160. amount = int.Parse(fee.ToString("f0")), //分账金额
  161. description = "服务费", //分账描述
  162. });
  163. WeChatFunction.Instance.ProfitShare(merchantAdd.SubMchid, TradeNo, OrderNo, Receivers);
  164. //开始监听分账状态
  165. Dictionary<string, object> req = new Dictionary<string, object>();
  166. req.Add("SubMchid", merchantAdd.SubMchid); //子商户号
  167. req.Add("TradeNo", TradeNo); //微信订单号
  168. req.Add("OrderNo", OrderNo); //商户订单号
  169. RedisDbconn.Instance.AddList("ProfitShareQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req));
  170. }
  171. }
  172. }
  173. db.Dispose();
  174. return "ok";
  175. }
  176. public string test1(string money)
  177. {
  178. // WebCMSEntities db = new WebCMSEntities();
  179. // MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == 2) ?? new MerchantAddInfo();
  180. // string result = WeChatFunctionForHD.Instance.MerchantApply(info);
  181. // string result = AlipayFunctionForHD.Instance.AuthOrderCreate(info, info.AlipayAuthToken);
  182. // string result = AlipayFunctionForHD.Instance.AuthOrderQuery("202308011033330180");
  183. // db.Dispose();
  184. // string result = AliIotFunction.Instance.IotBind("2088720723136476", "018271007948");
  185. // string result = AliIotFunction.Instance.IotUnBind("2088720723136476", "018271007948");
  186. // string result = AliIotFunction.Instance.IotDeviceQuery("018271007948");
  187. //{"alipay_commerce_iot_device_baseinfo_query_response":{"code":"10000","msg":"Success","device_id":"01010VO0cD5XzXQdca5i38e2I4wLHskg23hiuvEBASuHHvGKq982oko"},"sign":"hlGINohkf2g/ZqLNMH5FjVAXXxZYIHpOy8qSLBf3LJhTF1IH11oFsBPlNq5CWfI351tsoewB9aQ1CnqI0CwIeWV3fk+Bxc+n0GqJ0ePlvumdUJDwcMFUyE6xzmO0iepHbTE3akQVvHEsnwxOVJ4TD/NEwfacJi5WaoQKJnZcOzbVJmpmb5q67QObQTjsGdeV89/B+xK2JDcIBulorL+oUIALH0I8wrarJI8PpSATtZr6PEXjRzLaoYrTVnRVLj62DlSDhAlbrKx8924O8iW+j5rs16XZbdLk9kej884vCntks+6WwUaymM1YDS2xXhxTZPxrQow9h0WJ8R9EBavQFw=="}
  188. string result = AliIotFunction.Instance.IotTradeVoice("01010VO0cD5XzXQdca5i38e2I4wLHskg23hiuvEBASuHHvGKq982oko", "2088720723136476", "55555", money, "OTHER");
  189. return result;
  190. //{"alipay_merchant_indirect_authorder_create_response":{"code":"10000","msg":"Success","order_no":"202308011033330180","order_status":"AUDITING"},"sign":"FINNZ7lw92Igku4KfNp5+ETLLyBKgR0faoGU4mceiiAwe85jbslbwAuxqgewGxmrPys7iGkwTNkgK7D7mx+sjF1mHtPXBszb1WAeD5kF764/qQ7r1ziXI252D8+qN/GfUxtnaR1mFRHbXpeh9z3Hjiey0xtThPCRZO63rgNICa9oJ/kRTQ5AZpn1Ih+hWaSFVDHDhBTBJ/j1uzs4PedrVZqqUUXtFf+o0XI0mctdHjaXomSr5bx9wsc8asEveXDSP4s1JksqJy0Gi0x/Oqc9aq03eV1cwO+Hk5YMwML9Rm+mZDUrIDwUK5gsioM0wGVqJy19o2O2wAecOYtCFRNXnA=="}
  191. //{"alipay_merchant_indirect_authorder_querystatus_response":{"code":"10000","msg":"Success","order_no":"202308011033330180","order_status":"CONTACT_CONFIRM","qr_code":"https:\/\/mobilecodec.alipay.com\/show.htm?code=2ie16321tmy5uxwph8qze93"},"sign":"acEG5SvoUwjNgF8Ge/pGFTnLbbFCodyoVYrNV2WiKoGs81509JEPtLdZYl05ck+UI9qZ4GqWGqMBKP6hjk8GsVaQ53NvRTdvxmHFdEx6iskI5+WohM0m6HZMZgvDPvrqivqyQIkylX/uM/GKhQVK0/wMiRcfRuTQ/17OKJqd6fSA0mSgE27NI1K0JuIiJulL4V447RVIOVb5rW7QFFqf+7+vAu5/XaeUbboGPq68GvUUAOjIj3RMdHo+NiHRUcRaH5ajP+fkDrjMP5MjBwpCU6WOhv5pVi1cdEMO3kG0ga3pZQr1YWqWgW1HH/p8wAUJhmNsh8+eHeOi+6a6mkraQg=="}
  192. // WeChatFunctionForHD.Instance.QueryMerchant("2000002411850331");
  193. // return WeChatFunctionForHD.Instance.GetPlatCert();
  194. // string content = "7SSGOSPOFnkMRxLbxv9eHbw6+kAUbCr2wOfz3FKWpGbMoCWRgUsr92LEyfp/YeOAEptnfSmOgGuvlIEzEUUwiK1xnm3JKoIwbqnhutX66lU3oPycQ5H71RS9sdV6KQQ4eX5OuOoyJY5K3LCE6tXOtcfa9Lnlh4gh4dkf8Pny/EkfzQmYs5CEwVVSbX0rQl73fkFa7zMmjNy3TLj1ybZ3by4KEvOP7OnBp3Ff+Bcw7vGvTwycTXFWdLvuIDG36VEVhLbKOCOBT5rykdkw/nex/AK+T5DB9cae6FlBX1IJbQI4hJtxhsdU1exxxoG1Fyz0Sh0kPlmPyj6dR4bYl+FhVL+y1JlBEnfl3ilGz9LEWIwbH2AyOLK/6ltxLshgQCQAPRXATv3jCOe5hvXUeuzvxt0MrHoe1dJJRTVI+ZolEp45Mb/gsrY3gEC58BSOX7QfyPxZPyBsQkan1ZqLr7140oTXaT1av9pMZ1WCwY29x3+8p1fTitpJvM1nw4bSCcPKFVGr3gNX8637Z+EcIqNJEF4m0X6DPEkN3nOAcEDoJte+jkjizomFCcXTcFHzrBrIEmvfuKh+yEievuziGFgCYj/qUtT9FZdR0e55l6VRyBnxo8pO3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20y+ap11vVMiF/2tGlH3oN0W4OW3Glr11iIxdVtrpaLacsddW1J9MFZ/KCqvaFWVykoH9hO9u3IrA5HjaJDuRcrJl3Vl3cIrnPOF7JwtLI/vQVAM4MRS8EbX2qeZGYk+EWsy4N1dvjLrrMxjY4qCbgsi+DnDiHVaj+7BSMVKL04Ja2c8Tn0ysYEyyjoCHfMiohvQiaC5BqyJdvKT1GkEOFxPx78XCDWQYrpkz03Oj8qP/DX/zsQy9U09/J+2wcrB/CYXQfhe8CVNuD3O8QoguHAVEHt8O";
  195. // return WeChatFunctionForHD.Instance.AesGcmDecrypt("certificate", "fdc941b6d56c", content);
  196. // return "ok";
  197. }
  198. }
  199. }