HaoDaExtQueryHelper.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using System.Linq;
  6. using Microsoft.Extensions.Hosting;
  7. using MySystem;
  8. using MySystem.Models;
  9. using LitJson;
  10. using Library;
  11. using MySystem.Models.Main;
  12. public class HaoDaExtQueryHelper
  13. {
  14. public readonly static HaoDaExtQueryHelper Instance = new HaoDaExtQueryHelper();
  15. private HaoDaExtQueryHelper()
  16. {
  17. }
  18. public void StartWeChat()
  19. {
  20. Thread th = new Thread(StartWeChatDo);
  21. th.IsBackground = true;
  22. th.Start();
  23. }
  24. private void StartWeChatDo()
  25. {
  26. while (true)
  27. {
  28. string content = RedisDbconn.Instance.RPop<string>("WeChatResultForHaoDaQueue");
  29. if (!string.IsNullOrEmpty(content))
  30. {
  31. JsonData json = JsonMapper.ToObject(content);
  32. WeChatAddInfo(int.Parse(json["MerchantId"].ToString()), json["ApplymentId"].ToString());
  33. }
  34. else
  35. {
  36. Thread.Sleep(10000);
  37. }
  38. }
  39. }
  40. public void WeChatAddInfo(int Id, string ApplymentId)
  41. {
  42. try
  43. {
  44. WebCMSEntities db = new WebCMSEntities();
  45. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  46. string result = WeChatFunctionForHD.Instance.QueryMerchant(ApplymentId);
  47. JsonData jsonObj = JsonMapper.ToObject(result);
  48. if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT")
  49. {
  50. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  51. info.Status = 1;
  52. merchant.Status = 1;
  53. info.WeChatRemark = "";
  54. info.WeChatSignUrl = jsonObj["qrcode_data"].ToString();
  55. db.SaveChanges();
  56. RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
  57. }
  58. else if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_REJECTED")
  59. {
  60. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  61. info.Status = -1;
  62. merchant.Status = -1;
  63. info.WeChatRemark = jsonObj["reject_reason"].ToString();
  64. db.SaveChanges();
  65. }
  66. else
  67. {
  68. RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + ApplymentId + "\"}");
  69. }
  70. db.Dispose();
  71. }
  72. catch (Exception ex)
  73. {
  74. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
  75. }
  76. }
  77. public void StartAlipay()
  78. {
  79. Thread th = new Thread(StartAlipayDo);
  80. th.IsBackground = true;
  81. th.Start();
  82. }
  83. private void StartAlipayDo()
  84. {
  85. while (true)
  86. {
  87. string content = RedisDbconn.Instance.RPop<string>("AlipayResultForHaoDaQueue");
  88. if (!string.IsNullOrEmpty(content))
  89. {
  90. JsonData json = JsonMapper.ToObject(content);
  91. AlipayAddInfo(int.Parse(json["MerchantId"].ToString()), json["order_no"].ToString());
  92. }
  93. else
  94. {
  95. Thread.Sleep(10000);
  96. }
  97. }
  98. }
  99. public void AlipayAddInfo(int Id, string OrderNo)
  100. {
  101. try
  102. {
  103. WebCMSEntities db = new WebCMSEntities();
  104. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  105. string result = AlipayFunctionForHD.Instance.AuthOrderQuery(OrderNo);
  106. JsonData jsonObj = JsonMapper.ToObject(result);
  107. if (jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["code"].ToString() == "10000")
  108. {
  109. string order_status = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["order_status"].ToString();
  110. if (order_status == "CONTACT_CONFIRM")
  111. {
  112. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  113. info.QueryCount = 1;
  114. merchant.QueryCount = 1;
  115. info.AlipayRemark = "";
  116. info.AlipaySignUrl = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["qr_code"].ToString();
  117. db.SaveChanges();
  118. RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
  119. }
  120. else if (order_status == "AUDIT_REJECT" || order_status == "AUDIT_FREEZE")
  121. {
  122. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  123. info.QueryCount = -1;
  124. merchant.QueryCount = -1;
  125. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  126. db.SaveChanges();
  127. }
  128. else if (order_status == "AUDIT_PASS")
  129. {
  130. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  131. info.QueryCount = 2;
  132. merchant.QueryCount = 2;
  133. info.AlipayRemark = "";
  134. db.SaveChanges();
  135. }
  136. else
  137. {
  138. RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + OrderNo + "\"}");
  139. }
  140. }
  141. else
  142. {
  143. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  144. info.QueryCount = -1;
  145. merchant.QueryCount = -1;
  146. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  147. db.SaveChanges();
  148. }
  149. db.Dispose();
  150. }
  151. catch (Exception ex)
  152. {
  153. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
  154. }
  155. }
  156. }