HaoDaExtQueryHelper.cs 5.7 KB

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