TestHaoDaService.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using MySystem.Models.Main;
  6. using Library;
  7. using LitJson;
  8. using System.Threading;
  9. namespace MySystem
  10. {
  11. /// <summary>
  12. /// 好哒测试服务
  13. /// </summary>
  14. public class TestHaoDaService
  15. {
  16. public readonly static TestHaoDaService Instance = new TestHaoDaService();
  17. private TestHaoDaService()
  18. { }
  19. public void Start()
  20. {
  21. Thread th = new Thread(StartListen);
  22. th.IsBackground = true;
  23. th.Start();
  24. }
  25. public void StartListen()
  26. {
  27. //开户意愿申请
  28. // RedisDbconn.Instance.AddList("AlipayForHaoDaQueue",824);
  29. // RedisDbconn.Instance.AddList("WeChatForHaoDaQueue",824);
  30. // AlipayAddInfo(826);//提交支付宝开户意愿申请单
  31. // AlipayAddInfo(828,"202309011037906510");//查询支付宝开户意愿申请状态
  32. // WeChatAddInfo(826);//提交微信开户意愿申请单
  33. // WeChatAddInfo(825,"2000002424428809");//查询微信开户意愿申请状态
  34. // QueryMerchantStatus(867);//新建商户查询状态
  35. // ConfiemMer(808);//新建商户
  36. // ChangeMerchantCard(1);//商户修改银行卡
  37. // AddOpenDivideAccounts(832); //添加分账方
  38. QueryAuthStatus(1845);//查询实名认证状态
  39. // WeChatFunctionForHD.Instance.QueryAuthMerchant("600955391");
  40. // AlipayFunctionForHD.Instance.AuthOrderAuthQuery("2088820718243322");
  41. // StartProfitShareListen();
  42. // HaoDaHelper.Instance.BindWeChatAppId("1490230", "21622558", AppConfig.Haoda.SubAppId);
  43. // HaoDaHelper.Instance.OrderDivideAccountsQuery("FZ2023110315225748140470708", "1492500"); //查询分账结果
  44. // WebCMSEntities db = new WebCMSEntities();
  45. // List<int> ids = new List<int>();
  46. // foreach(int id in ids)
  47. // {
  48. // ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == id) ?? new ConsumerOrders();
  49. // MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
  50. // string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
  51. // string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
  52. // string orderNo = order.SeoTitle; //交易订单号(好哒平台订单号,G开头)
  53. // string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
  54. // string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
  55. // string acctType = "0"; //账户类型(0:商户收款账户(大B),1:分账接收方账户(小B))
  56. // // decimal hdfee = 0.0038M * order.PayMoney;
  57. // // hdfee = decimal.Parse(hdfee.ToString("f2"));
  58. // // decimal servicefee = 0.01M * order.PayMoney;
  59. // // servicefee = decimal.Parse(servicefee.ToString("f2"));
  60. // // decimal amount = order.PayMoney - hdfee - servicefee;
  61. // // amount = amount * 100; //金额(分)
  62. // // servicefee = servicefee * 100;
  63. // // string seviceAmount = servicefee.ToString("f0"); //服务费
  64. // string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, acctType, "1", "0"));
  65. // }
  66. // string content = function.ReadInstance("content.txt");
  67. // string[] list = content.Split('\n');
  68. // foreach(string sub in list)
  69. // {
  70. // JsonData jsonObj = JsonMapper.ToObject(sub);
  71. // string orderNo = jsonObj["orderNo"].ToString();
  72. // JsonData detail = jsonObj["detail"];
  73. // string me = detail[0]["amount"].ToString();
  74. // string mer = detail[1]["amount"].ToString();
  75. // ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == orderNo) ?? new ConsumerOrders();
  76. // if(order.SettleAmount > 0)
  77. // {
  78. // MerchantParamSet set = Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantParamSet>(order.SeoDescription);
  79. // MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
  80. // string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
  81. // string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
  82. // string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
  83. // string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
  84. // decimal settleAmount = (decimal)order.SettleAmount / 100M;
  85. // decimal divideAmt = (1 - 0.0038M) * order.PayMoney;
  86. // divideAmt = decimal.Parse(divideAmt.ToString("f2"));
  87. // decimal hdfee = 0.0038M * order.PayMoney * (1 - set.GetPercent / 100 - 0.01M);
  88. // hdfee = decimal.Parse(hdfee.ToString("f2"));
  89. // decimal servicefee = 0.01M * order.PayMoney - hdfee;
  90. // servicefee = decimal.Parse(servicefee.ToString("f2"));
  91. // decimal amount = order.PayMoney*(1-0.0038M) - servicefee;
  92. // amount = decimal.Parse(amount.ToString("f2"));
  93. // decimal otherAmt = settleAmount - servicefee - amount;
  94. // if(otherAmt != 0)
  95. // {
  96. // amount += otherAmt;
  97. // }
  98. // amount -= decimal.Parse(mer) / 100M;
  99. // servicefee -= decimal.Parse(me) / 100M;
  100. // if(amount > 0)
  101. // {
  102. // if(servicefee < 0) servicefee = 0;
  103. // amount = amount * 100 - 1; //金额(分)
  104. // servicefee = servicefee * 100;
  105. // string seviceAmount = servicefee.ToString("f0"); //服务费
  106. // string amountAmount = amount.ToString("f0");
  107. // string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, "0", amountAmount, seviceAmount));
  108. // }
  109. // }
  110. // }
  111. // List<string> list = new List<string>();
  112. // list.Add("{\"orderNo\":\"G2231124C02180937731\",\"settle\":\"29687\",\"part\":\"29575\"}");
  113. // foreach(string sub in list)
  114. // {
  115. // JsonData jsonObj = JsonMapper.ToObject(sub);
  116. // string orderNo = jsonObj["orderNo"].ToString();
  117. // string settle = jsonObj["settle"].ToString();
  118. // string part = jsonObj["part"].ToString();
  119. // ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == orderNo) ?? new ConsumerOrders();
  120. // if(order.SettleAmount > 0)
  121. // {
  122. // MerchantParamSet set = Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantParamSet>(order.SeoDescription);
  123. // MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
  124. // string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
  125. // string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
  126. // string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
  127. // string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
  128. // decimal settleamount = decimal.Parse(settle);
  129. // decimal partamount = decimal.Parse(part);
  130. // decimal amount = settleamount - partamount;
  131. // if(amount > 0)
  132. // {
  133. // decimal servicefee = amount / 100M;
  134. // servicefee = decimal.Parse(servicefee.ToString("f0"));
  135. // amount -= servicefee;
  136. // string seviceAmount = servicefee.ToString("f0"); //服务费
  137. // string amountAmount = amount.ToString("f0");
  138. // string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, "0", amountAmount, seviceAmount));
  139. // }
  140. // }
  141. // }
  142. // db.Dispose();
  143. }
  144. public void StartProfitShareListen()
  145. {
  146. bool op = true;
  147. while (op)
  148. {
  149. try
  150. {
  151. WebCMSEntities db = new WebCMSEntities();
  152. var list = db.ConsumerOrders.Where(m => m.Status == 1 && m.IsAct == 0).OrderByDescending(m => m.Id).ToList();
  153. foreach (var sub in list)
  154. {
  155. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == sub.Id);
  156. if (order != null)
  157. {
  158. int Status = 2;
  159. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantInfo();
  160. MerchantParamSet set = db.MerchantParamSet.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantParamSet();
  161. MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
  162. //发起分账
  163. string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
  164. string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
  165. string orderNo = order.SeoTitle; //交易订单号(好哒平台订单号,G开头)
  166. string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
  167. string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
  168. string acctType = "0"; //账户类型(0:商户收款账户(大B),1:分账接收方账户(小B))
  169. decimal amount = order.PayMoney * (1M - 0.0038M) * 100;
  170. string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, acctType, amount.ToString().Split('.')[0], "0"));
  171. if(result.Contains("\"resultCode\":\"0\"") && result.Contains("分账金额不足"))
  172. {
  173. Status = 1;
  174. }
  175. order.Status = Status;
  176. }
  177. }
  178. db.SaveChanges();
  179. db.Dispose();
  180. }
  181. catch (Exception ex)
  182. {
  183. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "好哒分账队列异常");
  184. }
  185. Thread.Sleep(2000);
  186. }
  187. }
  188. //新建商户查询状态
  189. public void QueryMerchantStatus(int MerchantId)
  190. {
  191. WebCMSEntities db = new WebCMSEntities();
  192. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  193. var returnInfo = HaoDaHelper.Instance.QueryMerchantStatus(HaoDaHelper.BrhCode, AddInfo.MchtNo);
  194. // string result = HaoDaHelper.Instance.AddNewMerchant(AddNewMerchantSetUtil.SetValue(AddInfo));
  195. db.Dispose();
  196. }
  197. //提交支付宝开户意愿申请单
  198. public void AlipayAddInfo(int Id)
  199. {
  200. try
  201. {
  202. WebCMSEntities db = new WebCMSEntities();
  203. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  204. string result = AlipayFunctionForHD.Instance.AuthOrderCreate(info, info.AlipayAuthToken);
  205. JsonData jsonObj = JsonMapper.ToObject(result);
  206. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  207. reqdic.Add("Id", Id); // 商户Id
  208. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  209. LogHelper.Instance.WriteLog(req, "提交支付宝商户意愿申请单");
  210. Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
  211. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  212. LogHelper.Instance.WriteLog("请求参数\n" + req, "提交支付宝商户意愿申请单");
  213. LogHelper.Instance.WriteLog(result, "提交支付宝商户意愿申请单");
  214. if (jsonObj["alipay_merchant_indirect_authorder_create_response"]["code"].ToString() == "10000")
  215. {
  216. LogHelper.Instance.WriteLog("success", "提交支付宝商户意愿申请单");
  217. string order_no = jsonObj["alipay_merchant_indirect_authorder_create_response"]["order_no"].ToString();
  218. // RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + order_no + "\"}");
  219. LogHelper.Instance.WriteLog("end", "提交支付宝商户意愿申请单");
  220. }
  221. else
  222. {
  223. LogHelper.Instance.WriteLog("false", "提交支付宝商户意愿申请单");
  224. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  225. info.QueryCount = -1;
  226. merchant.QueryCount = -1;
  227. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_create_response"]["msg"].ToString();
  228. LogHelper.Instance.WriteLog("end", "提交支付宝商户意愿申请单");
  229. db.SaveChanges();
  230. }
  231. db.Dispose();
  232. }
  233. catch (Exception ex)
  234. {
  235. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
  236. }
  237. }
  238. //查询支付宝开户意愿申请状态
  239. public void AlipayAddInfo(int Id, string OrderNo)
  240. {
  241. try
  242. {
  243. LogHelper.Instance.WriteLog("start", "查询支付宝商户意愿申请状态");
  244. WebCMSEntities db = new WebCMSEntities();
  245. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  246. string result = AlipayFunctionForHD.Instance.AuthOrderQuery(OrderNo);
  247. JsonData jsonObj = JsonMapper.ToObject(result);
  248. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  249. reqdic.Add("Id", Id); // 商户Id
  250. reqdic.Add("OrderNo", OrderNo); // 商户Id
  251. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  252. LogHelper.Instance.WriteLog(req, "查询支付宝商户意愿申请状态");
  253. Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
  254. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  255. LogHelper.Instance.WriteLog("请求参数\n" + req, "查询支付宝商户意愿申请状态");
  256. LogHelper.Instance.WriteLog(result, "查询支付宝商户意愿申请状态");
  257. if (jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["code"].ToString() == "10000")
  258. {
  259. LogHelper.Instance.WriteLog("start1", "查询支付宝商户意愿申请状态");
  260. string order_status = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["order_status"].ToString();
  261. if (order_status == "CONTACT_CONFIRM")
  262. {
  263. LogHelper.Instance.WriteLog("start1", "查询支付宝商户意愿申请状态");
  264. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  265. info.QueryCount = 1;
  266. merchant.QueryCount = 1;
  267. info.AlipayRemark = "";
  268. info.AlipaySignUrl = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["qr_code"].ToString();
  269. db.SaveChanges();
  270. // RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
  271. LogHelper.Instance.WriteLog("start1end", "查询支付宝商户意愿申请状态");
  272. }
  273. else if (order_status == "AUDIT_REJECT" || order_status == "AUDIT_FREEZE")
  274. {
  275. LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
  276. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  277. info.QueryCount = -1;
  278. merchant.QueryCount = -1;
  279. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  280. LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
  281. db.SaveChanges();
  282. }
  283. else if (order_status == "AUDIT_PASS")
  284. {
  285. LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
  286. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  287. info.QueryCount = 2;
  288. merchant.QueryCount = 2;
  289. info.AlipayRemark = "";
  290. LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
  291. db.SaveChanges();
  292. }
  293. // else
  294. // {
  295. // RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + OrderNo + "\"}");
  296. // }
  297. }
  298. else
  299. {
  300. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  301. info.QueryCount = -1;
  302. merchant.QueryCount = -1;
  303. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  304. db.SaveChanges();
  305. }
  306. db.Dispose();
  307. }
  308. catch (Exception ex)
  309. {
  310. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
  311. }
  312. }
  313. //提交微信开户意愿申请单
  314. public void WeChatAddInfo(int Id)
  315. {
  316. try
  317. {
  318. WebCMSEntities db = new WebCMSEntities();
  319. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  320. string result = WeChatFunctionForHD.Instance.MerchantApply(info);
  321. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  322. reqdic.Add("Id", Id); // 商户Id
  323. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  324. LogHelper.Instance.WriteLog(req, "提交微信商户意愿申请单");
  325. Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
  326. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  327. LogHelper.Instance.WriteLog("请求参数\n" + req, "提交微信商户意愿申请单");
  328. LogHelper.Instance.WriteLog(result, "提交微信商户意愿申请单");
  329. if (result.Contains("\"applyment_id\":"))
  330. {
  331. LogHelper.Instance.WriteLog("success", "提交微信商户意愿申请单");
  332. JsonData json = JsonMapper.ToObject(result);
  333. string applyment_id = json["applyment_id"].ToString();
  334. // RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + applyment_id + "\"}");
  335. LogHelper.Instance.WriteLog("end", "提交微信商户意愿申请单");
  336. }
  337. else if (result.Contains("\"message\":"))
  338. {
  339. LogHelper.Instance.WriteLog("false", "提交微信商户意愿申请单");
  340. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  341. JsonData jsonObj = JsonMapper.ToObject(result);
  342. info.Status = -1;
  343. merchant.Status = -1;
  344. info.WeChatRemark = jsonObj["message"].ToString();
  345. LogHelper.Instance.WriteLog("end", "提交微信商户意愿申请单");
  346. db.SaveChanges();
  347. }
  348. db.Dispose();
  349. }
  350. catch (Exception ex)
  351. {
  352. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
  353. }
  354. }
  355. //查询微信开户意愿申请状态
  356. public void WeChatAddInfo(int Id, string ApplymentId)
  357. {
  358. try
  359. {
  360. WebCMSEntities db = new WebCMSEntities();
  361. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  362. string result = WeChatFunctionForHD.Instance.QueryMerchant(ApplymentId);
  363. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  364. reqdic.Add("Id", Id); // 商户Id
  365. reqdic.Add("ApplymentId", ApplymentId); // 商户Id
  366. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  367. LogHelper.Instance.WriteLog(req, "提交微信商户意愿申请单");
  368. Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
  369. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  370. LogHelper.Instance.WriteLog("请求参数\n" + req, "提交微信商户意愿申请单");
  371. JsonData jsonObj = JsonMapper.ToObject(result);
  372. if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT")
  373. {
  374. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  375. info.Status = 1;
  376. merchant.Status = 1;
  377. info.WeChatRemark = "";
  378. info.WeChatSignUrl = jsonObj["qrcode_data"].ToString();
  379. db.SaveChanges();
  380. // RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
  381. }
  382. else if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_REJECTED")
  383. {
  384. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  385. info.Status = -1;
  386. merchant.Status = -1;
  387. info.WeChatRemark = jsonObj["reject_reason"].ToString();
  388. db.SaveChanges();
  389. }
  390. // else
  391. // {
  392. // RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + ApplymentId + "\"}");
  393. // }
  394. db.Dispose();
  395. }
  396. catch (Exception ex)
  397. {
  398. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
  399. }
  400. }
  401. //添加分账接收方账户
  402. public void AddOpenDivideAccounts(int MerchantId)
  403. {
  404. WebCMSEntities db = new WebCMSEntities();
  405. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  406. string result = HaoDaHelper.Instance.AddOpenDivideAccounts(AddOpenDivideAccountsUtil.AddValue(AddInfo));
  407. db.Dispose();
  408. }
  409. public void ConfiemMer(int MerchantId)
  410. {
  411. WebCMSEntities db = new WebCMSEntities();
  412. Models.Main1.WebCMSEntities db1 = new Models.Main1.WebCMSEntities();
  413. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  414. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
  415. if (AddInfo != null && merchant != null)
  416. {
  417. string BusinessCode = AddInfo.BusinessCode;
  418. if (string.IsNullOrEmpty(BusinessCode))
  419. {
  420. BusinessCode = "LKB" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(5);
  421. AddInfo.BusinessCode = BusinessCode;
  422. }
  423. string pwd = AddInfo.MobilePhone.Substring(5);
  424. merchant.LoginPwd = function.MD532(pwd);
  425. MerchantParamSet query = db.MerchantParamSet.FirstOrDefault(m => m.Id == MerchantId);
  426. if (query == null)
  427. {
  428. query = new MerchantParamSet();
  429. query.IsAll = 1;
  430. db.MerchantParamSet.Add(query);
  431. db.SaveChanges();
  432. }
  433. MerchantForMobile merchantForMobile = db.MerchantForMobile.FirstOrDefault(m => m.Mobile == AddInfo.MobilePhone);
  434. if (merchantForMobile == null)
  435. {
  436. merchantForMobile = db.MerchantForMobile.Add(new MerchantForMobile()
  437. {
  438. Mobile = AddInfo.MobilePhone,
  439. }).Entity;
  440. db.SaveChanges();
  441. }
  442. merchantForMobile.MerchantId = MerchantId;
  443. db.SaveChanges();
  444. Models.Main1.MerchantLoginInfo info = db1.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == AddInfo.MobilePhone);
  445. if (info == null)
  446. {
  447. info = db1.MerchantLoginInfo.Add(new Models.Main1.MerchantLoginInfo()
  448. {
  449. LoginMobile = AddInfo.MobilePhone,
  450. }).Entity;
  451. db1.SaveChanges();
  452. }
  453. info.LoginPwd = function.MD532(pwd);
  454. db1.SaveChanges();
  455. Models.Main1.MerchantAccountLinkInfo infolink = db1.MerchantAccountLinkInfo.FirstOrDefault(m => m.LoginId == info.Id && m.MerchantId == MerchantId && m.Kind == 2);
  456. if (infolink == null)
  457. {
  458. infolink = db1.MerchantAccountLinkInfo.Add(new Models.Main1.MerchantAccountLinkInfo()
  459. {
  460. LoginId = info.Id,
  461. MerchantId = MerchantId,
  462. Kind = 2,
  463. }).Entity;
  464. db1.SaveChanges();
  465. }
  466. if (AddInfo.Status <= 0)
  467. {
  468. //好哒新建商户
  469. string result = HaoDaHelper.Instance.AddNewMerchant(AddNewMerchantSetUtil.SetValue(AddInfo));
  470. JsonData jsonObj = JsonMapper.ToObject(result);
  471. //创建成功
  472. if (jsonObj["resultCode"].ToString() == "1")
  473. {
  474. AddInfo.WeChatRemark = "";
  475. if (string.IsNullOrEmpty(AddInfo.MchtNo))
  476. {
  477. AddInfo.MchtNo = jsonObj["data"]["mchtNo"].ToString();
  478. }
  479. AddInfo.Status = 0;
  480. merchant.Status = 0;
  481. db.SaveChanges();
  482. QueryMerchantStatus queryMerchantStatus = new QueryMerchantStatus();
  483. queryMerchantStatus.MerchantId = MerchantId.ToString();
  484. queryMerchantStatus.MerchantNo = AddInfo.MchtNo;
  485. // RedisDbconn.Instance.AddList("WeChatSignHdQueue", queryMerchantStatus);
  486. }
  487. //创建失败
  488. else
  489. {
  490. AddInfo.Status = -1;
  491. merchant.Status = -1;
  492. AddInfo.WeChatRemark = jsonObj["errorDesc"].ToString();
  493. // if (string.IsNullOrEmpty(AddInfo.MchtNo))
  494. // {
  495. // if (jsonObj.ToJson().Contains("mchtNo"))
  496. // {
  497. // AddInfo.MchtNo = jsonObj["data"]["mchtNo"].ToString();
  498. // }
  499. // }
  500. db.SaveChanges();
  501. }
  502. }
  503. }
  504. db.Dispose();
  505. db1.Dispose();
  506. }
  507. //商户开通分账
  508. public void OpenDivideAccounts(int MerchantId)
  509. {
  510. WebCMSEntities db = new WebCMSEntities();
  511. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  512. string result = HaoDaHelper.Instance.OpenDivideAccounts(AddInfo.OutMchtNo, AddInfo.StoreNo);
  513. db.Dispose();
  514. }
  515. //分账接收方签约
  516. public void DivideAccountsSign(int MerchantId)
  517. {
  518. WebCMSEntities db = new WebCMSEntities();
  519. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  520. string result = HaoDaHelper.Instance.DivideAccountsSign("230817000000000278", AddInfo.OutMchtNo, AddInfo.StoreNo);
  521. db.Dispose();
  522. }
  523. //查询实名认证状态
  524. public void QueryAuthStatus(int MerchantId)
  525. {
  526. WebCMSEntities db = new WebCMSEntities();
  527. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  528. string result = HaoDaHelper.Instance.QueryAuthStatus(AddInfo.OutMchtNo, AddInfo.StoreNo);
  529. db.Dispose();
  530. }
  531. //商户修改银行卡
  532. public void ChangeMerchantCard(int MerchantId)
  533. {
  534. WebCMSEntities db = new WebCMSEntities();
  535. // MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  536. // var request = TestChangeMerchantCardSetUtil.SetValue(AddInfo);
  537. // JsonData Infos = JsonMapper.ToObject(HaoDaHelper.Instance.ChangeMerchantCard(request));
  538. // JsonData results = JsonMapper.ToObject(HaoDaHelper.Instance.QueryChangeCardStatus(AddInfo.MchtNo, Infos["taskId"].ToString()));
  539. //TODO:修改结算卡变更商户相关信息
  540. // AccountNumber
  541. // BankName
  542. // BankBranchId
  543. // BankAddressCode
  544. // BankAccountType
  545. // OpenUnionNo
  546. // OpenCollectBankCode
  547. // OpenBankRegionCode
  548. // OpenBankAccout
  549. // OpenBankAccName
  550. // ZbankRegionCode
  551. // ZBankNo
  552. db.Dispose();
  553. }
  554. public void refund()
  555. {
  556. Thread th = new Thread(refunddo);
  557. th.IsBackground = true;
  558. th.Start();
  559. }
  560. public void refunddo()
  561. {
  562. for(int month = 10; month <= 11; month ++)
  563. {
  564. for(int day = 1; day <= 31; day ++)
  565. {
  566. string content = function.ReadInstance("/log/好哒聚合支付退款/2023/" + month + "/" + day + "/content.log");
  567. if(!string.IsNullOrEmpty(content))
  568. {
  569. content = content.Replace("\n\n\n", "####");
  570. content = content.Replace("\n", "");
  571. content = content.Replace("####", "\n");
  572. MatchCollection mc = Regex.Matches(content, "请求参数.*?退款次数超出限制");
  573. foreach(Match m in mc)
  574. {
  575. string mchtNo = Regex.Match(m.Value, "\"mchtNo\":\".*?\"").Value.Replace("\"mchtNo\":\"", "").Replace("\"", "");
  576. string storeNo = Regex.Match(m.Value, "\"storeNo\":\".*?\"").Value.Replace("\"storeNo\":\"", "").Replace("\"", "");
  577. string outOrderNo = Regex.Match(m.Value, "\"outOrderNo\":\".*?\"").Value.Replace("\"outOrderNo\":\"", "").Replace("\"", "");
  578. string refundAmount = Regex.Match(m.Value, "\"refundAmount\":\".*?\"").Value.Replace("\"refundAmount\":\"", "").Replace("\"", "");
  579. function.WriteLog("mchtNo:" + mchtNo + ";storeNo:" + storeNo + ";outOrderNo:" + outOrderNo + ";refundAmount:" + refundAmount + ";", "补充退款日志");
  580. var info = HaoDaHelper.Instance.AggregatedPayRefund(mchtNo, storeNo, "HDTK" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), outOrderNo, refundAmount);
  581. function.WriteLog(info + "\n\n", "补充退款日志");
  582. Thread.Sleep(1000);
  583. }
  584. }
  585. }
  586. }
  587. }
  588. }
  589. }