HaoDaExtQueryAuthHelper.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using System.Linq;
  6. using System.Data;
  7. using Microsoft.Extensions.Hosting;
  8. using MySystem;
  9. using MySystem.Models;
  10. using LitJson;
  11. using Library;
  12. using MySystem.Models.Main;
  13. public class HaoDaExtQueryAuthHelper
  14. {
  15. public readonly static HaoDaExtQueryAuthHelper Instance = new HaoDaExtQueryAuthHelper();
  16. private HaoDaExtQueryAuthHelper()
  17. {
  18. }
  19. public void StartWeChat()
  20. {
  21. Thread th = new Thread(StartWeChatDo);
  22. th.IsBackground = true;
  23. th.Start();
  24. }
  25. private void StartWeChatDo()
  26. {
  27. while (true)
  28. {
  29. // string content = RedisDbconn.Instance.RPop<string>("WeChatAuthResultForHaoDaQueue");
  30. // if (!string.IsNullOrEmpty(content))
  31. // {
  32. // JsonData json = JsonMapper.ToObject(content);
  33. // WeChatAddInfo(int.Parse(json["MerchantId"].ToString()));
  34. // }
  35. // else
  36. // {
  37. // Thread.Sleep(10000);
  38. // }
  39. DataTable dt = CustomerSqlConn.dtable("select Id from MerchantAddInfo where HdStatus=3 and `Status`=1 and WeChatMerchantId!='' and WeChatMerchantId is not null", AppConfig.Base.SqlConnStr);
  40. foreach(DataRow dr in dt.Rows)
  41. {
  42. WeChatAddInfo(int.Parse(dr["Id"].ToString()));
  43. Thread.Sleep(1000);
  44. }
  45. Thread.Sleep(120000);
  46. }
  47. }
  48. public void WeChatAddInfo(int Id)
  49. {
  50. try
  51. {
  52. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "获取微信商户开户意愿确认状态");
  53. LogHelper.Instance.WriteLog("start", "获取微信商户开户意愿确认状态");
  54. WebCMSEntities db = new WebCMSEntities();
  55. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  56. string result = WeChatFunctionForHD.Instance.QueryAuthMerchant(info.WeChatMerchantId);
  57. LogHelper.Instance.WriteLog(result, "获取微信商户开户意愿确认状态");
  58. JsonData jsonObj = JsonMapper.ToObject(result);
  59. if(result.Contains("authorize_state"))
  60. {
  61. if (jsonObj["authorize_state"].ToString() == "AUTHORIZE_STATE_AUTHORIZED")
  62. {
  63. LogHelper.Instance.WriteLog("starts", "获取微信商户开户意愿确认状态");
  64. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  65. info.Status = 2;
  66. merchant.Status = 2;
  67. db.SaveChanges();
  68. LogHelper.Instance.WriteLog("startsend", "获取微信商户开户意愿确认状态");
  69. }
  70. }
  71. // else
  72. // {
  73. // LogHelper.Instance.WriteLog("starte", "获取微信商户开户意愿确认状态");
  74. // RedisDbconn.Instance.AddList("WeChatAuthResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\"}");
  75. // LogHelper.Instance.WriteLog("start2end", "获取微信商户开户意愿确认状态");
  76. // }
  77. db.Dispose();
  78. }
  79. catch (Exception ex)
  80. {
  81. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "获取微信商户开户意愿确认状态异常");
  82. }
  83. }
  84. public void StartAlipay()
  85. {
  86. Thread th = new Thread(StartAlipayDo);
  87. th.IsBackground = true;
  88. th.Start();
  89. }
  90. private void StartAlipayDo()
  91. {
  92. while (true)
  93. {
  94. // string content = RedisDbconn.Instance.RPop<string>("AlipayAuthResultForHaoDaQueue");
  95. // if (!string.IsNullOrEmpty(content))
  96. // {
  97. // JsonData json = JsonMapper.ToObject(content);
  98. // AlipayAddInfo(int.Parse(json["MerchantId"].ToString()));
  99. // }
  100. // else
  101. // {
  102. // Thread.Sleep(10000);
  103. // }
  104. DataTable dt = CustomerSqlConn.dtable("select Id from MerchantAddInfo where HdStatus=3 and `QueryCount`=1 and AliMerchantId!='' and AliMerchantId is not null", AppConfig.Base.SqlConnStr);
  105. foreach(DataRow dr in dt.Rows)
  106. {
  107. AlipayAddInfo(int.Parse(dr["Id"].ToString()));
  108. Thread.Sleep(1000);
  109. }
  110. Thread.Sleep(120000);
  111. }
  112. }
  113. public void AlipayAddInfo(int Id)
  114. {
  115. try
  116. {
  117. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "获取支付宝商家认证状态");
  118. LogHelper.Instance.WriteLog("start", "获取支付宝商家认证状态");
  119. WebCMSEntities db = new WebCMSEntities();
  120. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  121. string result = AlipayFunctionForHD.Instance.AuthOrderAuthQuery(info.AliMerchantId);
  122. JsonData jsonObj = JsonMapper.ToObject(result);
  123. LogHelper.Instance.WriteLog(result, "获取支付宝商家认证状态");
  124. if (jsonObj["alipay_merchant_indirect_smidbind_query_response"]["code"].ToString() == "10000")
  125. {
  126. LogHelper.Instance.WriteLog("starts", "获取支付宝商家认证状态");
  127. string order_status = jsonObj["alipay_merchant_indirect_smidbind_query_response"]["check_result"].ToString();
  128. LogHelper.Instance.WriteLog(order_status, "获取支付宝商家认证状态");
  129. if (order_status == "AUTHORIZED")
  130. {
  131. LogHelper.Instance.WriteLog("start1", "获取支付宝商家认证状态");
  132. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  133. info.QueryCount = 2;
  134. merchant.QueryCount = 2;
  135. db.SaveChanges();
  136. LogHelper.Instance.WriteLog("start1end", "获取支付宝商家认证状态");
  137. }
  138. // else
  139. // {
  140. // RedisDbconn.Instance.AddList("AlipayAuthResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\"}");
  141. // }
  142. }
  143. db.Dispose();
  144. }
  145. catch (Exception ex)
  146. {
  147. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "获取支付宝商家认证状态异常");
  148. }
  149. }
  150. }