HaoDaExtQueryAuthHelper.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. }
  44. Thread.Sleep(120000);
  45. }
  46. }
  47. public void WeChatAddInfo(int Id)
  48. {
  49. try
  50. {
  51. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "获取微信商户开户意愿确认状态");
  52. LogHelper.Instance.WriteLog("start", "获取微信商户开户意愿确认状态");
  53. WebCMSEntities db = new WebCMSEntities();
  54. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  55. string result = WeChatFunctionForHD.Instance.QueryAuthMerchant(info.WeChatMerchantId);
  56. LogHelper.Instance.WriteLog(result, "获取微信商户开户意愿确认状态");
  57. JsonData jsonObj = JsonMapper.ToObject(result);
  58. if(result.Contains("authorize_state"))
  59. {
  60. if (jsonObj["authorize_state"].ToString() == "AUTHORIZE_STATE_AUTHORIZED")
  61. {
  62. LogHelper.Instance.WriteLog("starts", "获取微信商户开户意愿确认状态");
  63. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  64. info.Status = 2;
  65. merchant.Status = 2;
  66. db.SaveChanges();
  67. LogHelper.Instance.WriteLog("startsend", "获取微信商户开户意愿确认状态");
  68. }
  69. }
  70. // else
  71. // {
  72. // LogHelper.Instance.WriteLog("starte", "获取微信商户开户意愿确认状态");
  73. // RedisDbconn.Instance.AddList("WeChatAuthResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\"}");
  74. // LogHelper.Instance.WriteLog("start2end", "获取微信商户开户意愿确认状态");
  75. // }
  76. db.Dispose();
  77. }
  78. catch (Exception ex)
  79. {
  80. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "获取微信商户开户意愿确认状态异常");
  81. }
  82. }
  83. public void StartAlipay()
  84. {
  85. Thread th = new Thread(StartAlipayDo);
  86. th.IsBackground = true;
  87. th.Start();
  88. }
  89. private void StartAlipayDo()
  90. {
  91. while (true)
  92. {
  93. // string content = RedisDbconn.Instance.RPop<string>("AlipayAuthResultForHaoDaQueue");
  94. // if (!string.IsNullOrEmpty(content))
  95. // {
  96. // JsonData json = JsonMapper.ToObject(content);
  97. // AlipayAddInfo(int.Parse(json["MerchantId"].ToString()));
  98. // }
  99. // else
  100. // {
  101. // Thread.Sleep(10000);
  102. // }
  103. DataTable dt = CustomerSqlConn.dtable("select Id from MerchantAddInfo where HdStatus=3 and `QueryCount`=1 and AliMerchantId!='' and AliMerchantId is not null", AppConfig.Base.SqlConnStr);
  104. foreach(DataRow dr in dt.Rows)
  105. {
  106. AlipayAddInfo(int.Parse(dr["Id"].ToString()));
  107. }
  108. Thread.Sleep(120000);
  109. }
  110. }
  111. public void AlipayAddInfo(int Id)
  112. {
  113. try
  114. {
  115. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "获取支付宝商家认证状态");
  116. LogHelper.Instance.WriteLog("start", "获取支付宝商家认证状态");
  117. WebCMSEntities db = new WebCMSEntities();
  118. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  119. string result = AlipayFunctionForHD.Instance.AuthOrderAuthQuery(info.AliMerchantId);
  120. JsonData jsonObj = JsonMapper.ToObject(result);
  121. LogHelper.Instance.WriteLog(result, "获取支付宝商家认证状态");
  122. if (jsonObj["alipay_merchant_indirect_smidbind_query_response"]["code"].ToString() == "10000")
  123. {
  124. LogHelper.Instance.WriteLog("starts", "获取支付宝商家认证状态");
  125. string order_status = jsonObj["alipay_merchant_indirect_smidbind_query_response"]["check_result"].ToString();
  126. LogHelper.Instance.WriteLog(order_status, "获取支付宝商家认证状态");
  127. if (order_status == "AUTHORIZED")
  128. {
  129. LogHelper.Instance.WriteLog("start1", "获取支付宝商家认证状态");
  130. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  131. info.QueryCount = 2;
  132. merchant.QueryCount = 2;
  133. db.SaveChanges();
  134. LogHelper.Instance.WriteLog("start1end", "获取支付宝商家认证状态");
  135. }
  136. // else
  137. // {
  138. // RedisDbconn.Instance.AddList("AlipayAuthResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\"}");
  139. // }
  140. }
  141. db.Dispose();
  142. }
  143. catch (Exception ex)
  144. {
  145. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "获取支付宝商家认证状态异常");
  146. }
  147. }
  148. }