TestHaoDaService.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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 BrhCode = HaodaUnionParam.BrhCode;
  194. if (AddInfo.BrandId == 1) BrhCode = HaodaParam.BrhCode;
  195. var returnInfo = HaoDaHelper.Instance.QueryMerchantStatus(BrhCode, AddInfo.MchtNo);
  196. // string result = HaoDaHelper.Instance.AddNewMerchant(AddNewMerchantSetUtil.SetValue(AddInfo));
  197. db.Dispose();
  198. }
  199. //提交支付宝开户意愿申请单
  200. public void AlipayAddInfo(int Id)
  201. {
  202. try
  203. {
  204. WebCMSEntities db = new WebCMSEntities();
  205. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  206. string result = AlipayFunctionForHD.Instance.AuthOrderCreate(info, info.AlipayAuthToken);
  207. JsonData jsonObj = JsonMapper.ToObject(result);
  208. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  209. reqdic.Add("Id", Id); // 商户Id
  210. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  211. LogHelper.Instance.WriteLog(req, "提交支付宝商户意愿申请单");
  212. Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
  213. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  214. LogHelper.Instance.WriteLog("请求参数\n" + req, "提交支付宝商户意愿申请单");
  215. LogHelper.Instance.WriteLog(result, "提交支付宝商户意愿申请单");
  216. if (jsonObj["alipay_merchant_indirect_authorder_create_response"]["code"].ToString() == "10000")
  217. {
  218. LogHelper.Instance.WriteLog("success", "提交支付宝商户意愿申请单");
  219. string order_no = jsonObj["alipay_merchant_indirect_authorder_create_response"]["order_no"].ToString();
  220. // RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + order_no + "\"}");
  221. LogHelper.Instance.WriteLog("end", "提交支付宝商户意愿申请单");
  222. }
  223. else
  224. {
  225. LogHelper.Instance.WriteLog("false", "提交支付宝商户意愿申请单");
  226. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  227. info.QueryCount = -1;
  228. merchant.QueryCount = -1;
  229. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_create_response"]["msg"].ToString();
  230. LogHelper.Instance.WriteLog("end", "提交支付宝商户意愿申请单");
  231. db.SaveChanges();
  232. }
  233. db.Dispose();
  234. }
  235. catch (Exception ex)
  236. {
  237. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
  238. }
  239. }
  240. //查询支付宝开户意愿申请状态
  241. public void AlipayAddInfo(int Id, string OrderNo)
  242. {
  243. try
  244. {
  245. LogHelper.Instance.WriteLog("start", "查询支付宝商户意愿申请状态");
  246. WebCMSEntities db = new WebCMSEntities();
  247. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  248. string result = AlipayFunctionForHD.Instance.AuthOrderQuery(OrderNo);
  249. JsonData jsonObj = JsonMapper.ToObject(result);
  250. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  251. reqdic.Add("Id", Id); // 商户Id
  252. reqdic.Add("OrderNo", OrderNo); // 商户Id
  253. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  254. LogHelper.Instance.WriteLog(req, "查询支付宝商户意愿申请状态");
  255. Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
  256. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  257. LogHelper.Instance.WriteLog("请求参数\n" + req, "查询支付宝商户意愿申请状态");
  258. LogHelper.Instance.WriteLog(result, "查询支付宝商户意愿申请状态");
  259. if (jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["code"].ToString() == "10000")
  260. {
  261. LogHelper.Instance.WriteLog("start1", "查询支付宝商户意愿申请状态");
  262. string order_status = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["order_status"].ToString();
  263. if (order_status == "CONTACT_CONFIRM")
  264. {
  265. LogHelper.Instance.WriteLog("start1", "查询支付宝商户意愿申请状态");
  266. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  267. info.QueryCount = 1;
  268. merchant.QueryCount = 1;
  269. info.AlipayRemark = "";
  270. info.AlipaySignUrl = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["qr_code"].ToString();
  271. db.SaveChanges();
  272. // RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
  273. LogHelper.Instance.WriteLog("start1end", "查询支付宝商户意愿申请状态");
  274. }
  275. else if (order_status == "AUDIT_REJECT" || order_status == "AUDIT_FREEZE")
  276. {
  277. LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
  278. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  279. info.QueryCount = -1;
  280. merchant.QueryCount = -1;
  281. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  282. LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
  283. db.SaveChanges();
  284. }
  285. else if (order_status == "AUDIT_PASS")
  286. {
  287. LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
  288. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  289. info.QueryCount = 2;
  290. merchant.QueryCount = 2;
  291. info.AlipayRemark = "";
  292. LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
  293. if (merchant.Latitude == 0)
  294. {
  295. //签约成功调用腾讯地图接口获取地址
  296. RedisDbconn.Instance.AddList("GetTencentAddressInfoQueueHd", "{\"MerChantId\":\"" + merchant.Id + "\",\"Address\":\"" + merchant.Areas + merchant.Address + "\"}");
  297. }
  298. db.SaveChanges();
  299. }
  300. // else
  301. // {
  302. // RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + OrderNo + "\"}");
  303. // }
  304. }
  305. else
  306. {
  307. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  308. info.QueryCount = -1;
  309. merchant.QueryCount = -1;
  310. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  311. db.SaveChanges();
  312. }
  313. db.Dispose();
  314. }
  315. catch (Exception ex)
  316. {
  317. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
  318. }
  319. }
  320. //提交微信开户意愿申请单
  321. public void WeChatAddInfo(int Id)
  322. {
  323. try
  324. {
  325. WebCMSEntities db = new WebCMSEntities();
  326. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  327. string result = WeChatFunctionForHD.Instance.MerchantApply(info);
  328. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  329. reqdic.Add("Id", Id); // 商户Id
  330. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  331. LogHelper.Instance.WriteLog(req, "提交微信商户意愿申请单");
  332. Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
  333. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  334. LogHelper.Instance.WriteLog("请求参数\n" + req, "提交微信商户意愿申请单");
  335. LogHelper.Instance.WriteLog(result, "提交微信商户意愿申请单");
  336. if (result.Contains("\"applyment_id\":"))
  337. {
  338. LogHelper.Instance.WriteLog("success", "提交微信商户意愿申请单");
  339. JsonData json = JsonMapper.ToObject(result);
  340. string applyment_id = json["applyment_id"].ToString();
  341. // RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + applyment_id + "\"}");
  342. LogHelper.Instance.WriteLog("end", "提交微信商户意愿申请单");
  343. }
  344. else if (result.Contains("\"message\":"))
  345. {
  346. LogHelper.Instance.WriteLog("false", "提交微信商户意愿申请单");
  347. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  348. JsonData jsonObj = JsonMapper.ToObject(result);
  349. info.Status = -1;
  350. merchant.Status = -1;
  351. info.WeChatRemark = jsonObj["message"].ToString();
  352. LogHelper.Instance.WriteLog("end", "提交微信商户意愿申请单");
  353. db.SaveChanges();
  354. }
  355. db.Dispose();
  356. }
  357. catch (Exception ex)
  358. {
  359. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
  360. }
  361. }
  362. //查询微信开户意愿申请状态
  363. public void WeChatAddInfo(int Id, string ApplymentId)
  364. {
  365. try
  366. {
  367. WebCMSEntities db = new WebCMSEntities();
  368. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  369. string result = WeChatFunctionForHD.Instance.QueryMerchant(ApplymentId);
  370. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  371. reqdic.Add("Id", Id); // 商户Id
  372. reqdic.Add("ApplymentId", ApplymentId); // 商户Id
  373. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  374. LogHelper.Instance.WriteLog(req, "提交微信商户意愿申请单");
  375. Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
  376. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  377. LogHelper.Instance.WriteLog("请求参数\n" + req, "提交微信商户意愿申请单");
  378. JsonData jsonObj = JsonMapper.ToObject(result);
  379. if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT")
  380. {
  381. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  382. info.Status = 1;
  383. merchant.Status = 1;
  384. info.WeChatRemark = "";
  385. info.WeChatSignUrl = jsonObj["qrcode_data"].ToString();
  386. db.SaveChanges();
  387. // RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
  388. }
  389. else if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_REJECTED")
  390. {
  391. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  392. info.Status = -1;
  393. merchant.Status = -1;
  394. info.WeChatRemark = jsonObj["reject_reason"].ToString();
  395. db.SaveChanges();
  396. }
  397. // else
  398. // {
  399. // RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + ApplymentId + "\"}");
  400. // }
  401. db.Dispose();
  402. }
  403. catch (Exception ex)
  404. {
  405. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
  406. }
  407. }
  408. //添加分账接收方账户
  409. public void AddOpenDivideAccounts(int MerchantId)
  410. {
  411. WebCMSEntities db = new WebCMSEntities();
  412. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  413. string result = HaoDaHelper.Instance.AddOpenDivideAccounts(AddOpenDivideAccountsUtil.AddValue(AddInfo));
  414. db.Dispose();
  415. }
  416. public void ConfiemMer(int MerchantId)
  417. {
  418. WebCMSEntities db = new WebCMSEntities();
  419. Models.Main1.WebCMSEntities db1 = new Models.Main1.WebCMSEntities();
  420. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  421. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
  422. if (AddInfo != null && merchant != null)
  423. {
  424. string BusinessCode = AddInfo.BusinessCode;
  425. if (string.IsNullOrEmpty(BusinessCode))
  426. {
  427. BusinessCode = "LKB" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(5);
  428. AddInfo.BusinessCode = BusinessCode;
  429. }
  430. string pwd = AddInfo.MobilePhone.Substring(5);
  431. merchant.LoginPwd = function.MD532(pwd);
  432. MerchantParamSet query = db.MerchantParamSet.FirstOrDefault(m => m.Id == MerchantId);
  433. if (query == null)
  434. {
  435. query = new MerchantParamSet();
  436. query.IsAll = 1;
  437. db.MerchantParamSet.Add(query);
  438. db.SaveChanges();
  439. }
  440. MerchantForMobile merchantForMobile = db.MerchantForMobile.FirstOrDefault(m => m.Mobile == AddInfo.MobilePhone);
  441. if (merchantForMobile == null)
  442. {
  443. merchantForMobile = db.MerchantForMobile.Add(new MerchantForMobile()
  444. {
  445. Mobile = AddInfo.MobilePhone,
  446. }).Entity;
  447. db.SaveChanges();
  448. }
  449. merchantForMobile.MerchantId = MerchantId;
  450. db.SaveChanges();
  451. Models.Main1.MerchantLoginInfo info = db1.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == AddInfo.MobilePhone);
  452. if (info == null)
  453. {
  454. info = db1.MerchantLoginInfo.Add(new Models.Main1.MerchantLoginInfo()
  455. {
  456. LoginMobile = AddInfo.MobilePhone,
  457. }).Entity;
  458. db1.SaveChanges();
  459. }
  460. info.LoginPwd = function.MD532(pwd);
  461. db1.SaveChanges();
  462. Models.Main1.MerchantAccountLinkInfo infolink = db1.MerchantAccountLinkInfo.FirstOrDefault(m => m.LoginId == info.Id && m.MerchantId == MerchantId && m.Kind == 2);
  463. if (infolink == null)
  464. {
  465. infolink = db1.MerchantAccountLinkInfo.Add(new Models.Main1.MerchantAccountLinkInfo()
  466. {
  467. LoginId = info.Id,
  468. MerchantId = MerchantId,
  469. Kind = 2,
  470. }).Entity;
  471. db1.SaveChanges();
  472. }
  473. if (AddInfo.Status <= 0)
  474. {
  475. //好哒新建商户
  476. string result = HaoDaHelper.Instance.AddNewMerchant(AddNewMerchantSetUtil.SetValue(AddInfo));
  477. JsonData jsonObj = JsonMapper.ToObject(result);
  478. //创建成功
  479. if (jsonObj["resultCode"].ToString() == "1")
  480. {
  481. AddInfo.WeChatRemark = "";
  482. if (string.IsNullOrEmpty(AddInfo.MchtNo))
  483. {
  484. AddInfo.MchtNo = jsonObj["data"]["mchtNo"].ToString();
  485. }
  486. AddInfo.Status = 0;
  487. merchant.Status = 0;
  488. db.SaveChanges();
  489. QueryMerchantStatus queryMerchantStatus = new QueryMerchantStatus();
  490. queryMerchantStatus.MerchantId = MerchantId.ToString();
  491. queryMerchantStatus.MerchantNo = AddInfo.MchtNo;
  492. // RedisDbconn.Instance.AddList("WeChatSignHdQueue", queryMerchantStatus);
  493. }
  494. //创建失败
  495. else
  496. {
  497. AddInfo.Status = -1;
  498. merchant.Status = -1;
  499. AddInfo.WeChatRemark = jsonObj["errorDesc"].ToString();
  500. // if (string.IsNullOrEmpty(AddInfo.MchtNo))
  501. // {
  502. // if (jsonObj.ToJson().Contains("mchtNo"))
  503. // {
  504. // AddInfo.MchtNo = jsonObj["data"]["mchtNo"].ToString();
  505. // }
  506. // }
  507. db.SaveChanges();
  508. }
  509. }
  510. }
  511. db.Dispose();
  512. db1.Dispose();
  513. }
  514. //商户开通分账
  515. public void OpenDivideAccounts(int MerchantId)
  516. {
  517. WebCMSEntities db = new WebCMSEntities();
  518. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  519. string result = HaoDaHelper.Instance.OpenDivideAccounts(AddInfo.OutMchtNo, AddInfo.StoreNo);
  520. db.Dispose();
  521. }
  522. //分账接收方签约
  523. public void DivideAccountsSign(int MerchantId)
  524. {
  525. WebCMSEntities db = new WebCMSEntities();
  526. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  527. string result = HaoDaHelper.Instance.DivideAccountsSign("230817000000000278", AddInfo.OutMchtNo, AddInfo.StoreNo);
  528. db.Dispose();
  529. }
  530. //查询实名认证状态
  531. public void QueryAuthStatus(int MerchantId)
  532. {
  533. WebCMSEntities db = new WebCMSEntities();
  534. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  535. string result = HaoDaHelper.Instance.QueryAuthStatus(AddInfo.OutMchtNo, AddInfo.StoreNo);
  536. db.Dispose();
  537. }
  538. //商户修改银行卡
  539. public void ChangeMerchantCard(int MerchantId)
  540. {
  541. WebCMSEntities db = new WebCMSEntities();
  542. // MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  543. // var request = TestChangeMerchantCardSetUtil.SetValue(AddInfo);
  544. // JsonData Infos = JsonMapper.ToObject(HaoDaHelper.Instance.ChangeMerchantCard(request));
  545. // JsonData results = JsonMapper.ToObject(HaoDaHelper.Instance.QueryChangeCardStatus(AddInfo.MchtNo, Infos["taskId"].ToString()));
  546. //TODO:修改结算卡变更商户相关信息
  547. // AccountNumber
  548. // BankName
  549. // BankBranchId
  550. // BankAddressCode
  551. // BankAccountType
  552. // OpenUnionNo
  553. // OpenCollectBankCode
  554. // OpenBankRegionCode
  555. // OpenBankAccout
  556. // OpenBankAccName
  557. // ZbankRegionCode
  558. // ZBankNo
  559. db.Dispose();
  560. }
  561. public void refund()
  562. {
  563. Thread th = new Thread(refunddo);
  564. th.IsBackground = true;
  565. th.Start();
  566. }
  567. public void refunddo()
  568. {
  569. for (int month = 10; month <= 11; month++)
  570. {
  571. for (int day = 1; day <= 31; day++)
  572. {
  573. string content = function.ReadInstance("/log/好哒聚合支付退款/2023/" + month + "/" + day + "/content.log");
  574. if (!string.IsNullOrEmpty(content))
  575. {
  576. content = content.Replace("\n\n\n", "####");
  577. content = content.Replace("\n", "");
  578. content = content.Replace("####", "\n");
  579. MatchCollection mc = Regex.Matches(content, "请求参数.*?退款次数超出限制");
  580. foreach (Match m in mc)
  581. {
  582. string mchtNo = Regex.Match(m.Value, "\"mchtNo\":\".*?\"").Value.Replace("\"mchtNo\":\"", "").Replace("\"", "");
  583. string storeNo = Regex.Match(m.Value, "\"storeNo\":\".*?\"").Value.Replace("\"storeNo\":\"", "").Replace("\"", "");
  584. string outOrderNo = Regex.Match(m.Value, "\"outOrderNo\":\".*?\"").Value.Replace("\"outOrderNo\":\"", "").Replace("\"", "");
  585. string refundAmount = Regex.Match(m.Value, "\"refundAmount\":\".*?\"").Value.Replace("\"refundAmount\":\"", "").Replace("\"", "");
  586. function.WriteLog("mchtNo:" + mchtNo + ";storeNo:" + storeNo + ";outOrderNo:" + outOrderNo + ";refundAmount:" + refundAmount + ";", "补充退款日志");
  587. var info = HaoDaHelper.Instance.AggregatedPayRefund(mchtNo, storeNo, "HDTK" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), outOrderNo, refundAmount);
  588. function.WriteLog(info + "\n\n", "补充退款日志");
  589. Thread.Sleep(1000);
  590. }
  591. }
  592. }
  593. }
  594. }
  595. }
  596. }