HaoDaExtQueryHelper.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_FINISHED")
  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["sign_url"].ToString();
  55. db.SaveChanges();
  56. }
  57. else if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_REJECTED")
  58. {
  59. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  60. info.Status = -1;
  61. merchant.Status = -1;
  62. info.WeChatRemark = jsonObj["reject_reason"].ToString();
  63. db.SaveChanges();
  64. }
  65. else
  66. {
  67. RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + ApplymentId + "\"}");
  68. }
  69. db.Dispose();
  70. }
  71. catch(Exception ex)
  72. {
  73. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
  74. }
  75. }
  76. public void StartAlipay()
  77. {
  78. Thread th = new Thread(StartAlipayDo);
  79. th.IsBackground = true;
  80. th.Start();
  81. }
  82. private void StartAlipayDo()
  83. {
  84. while (true)
  85. {
  86. string content = RedisDbconn.Instance.RPop<string>("AlipayResultForHaoDaQueue");
  87. if (!string.IsNullOrEmpty(content))
  88. {
  89. JsonData json = JsonMapper.ToObject(content);
  90. AlipayAddInfo(int.Parse(json["MerchantId"].ToString()), json["order_no"].ToString());
  91. }
  92. else
  93. {
  94. Thread.Sleep(10000);
  95. }
  96. }
  97. }
  98. public void AlipayAddInfo(int Id, string OrderNo)
  99. {
  100. try
  101. {
  102. WebCMSEntities db = new WebCMSEntities();
  103. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  104. string result = AlipayFunctionForHD.Instance.AuthOrderQuery(OrderNo);
  105. JsonData jsonObj = JsonMapper.ToObject(result);
  106. if (jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["code"].ToString() == "10000")
  107. {
  108. string order_status = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["order_status"].ToString();
  109. if (order_status == "CONTACT_CONFIRM")
  110. {
  111. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  112. info.QueryCount = 1;
  113. merchant.QueryCount = 1;
  114. info.AlipayRemark = "";
  115. info.AlipaySignUrl = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["qr_code"].ToString();
  116. db.SaveChanges();
  117. }
  118. else if (order_status == "AUDIT_PASS" || order_status == "AUDIT_REJECT" || order_status == "AUDIT_FREEZE")
  119. {
  120. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  121. info.QueryCount = -1;
  122. merchant.QueryCount = -1;
  123. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  124. db.SaveChanges();
  125. }
  126. else
  127. {
  128. RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + OrderNo + "\"}");
  129. }
  130. }
  131. else
  132. {
  133. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  134. info.QueryCount = -1;
  135. merchant.QueryCount = -1;
  136. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  137. db.SaveChanges();
  138. }
  139. db.Dispose();
  140. }
  141. catch(Exception ex)
  142. {
  143. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
  144. }
  145. }
  146. }