HaoDaExtQueryAuthHelper.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 BrandId=0 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. if (merchant.Latitude == 0)
  68. {
  69. //签约成功调用腾讯地图接口获取地址
  70. RedisDbconn.Instance.AddList("GetTencentAddressInfoQueueHd", "{\"MerChantId\":\"" + merchant.Id + "\",\"Address\":\"" + merchant.Areas + merchant.Address + "\"}");
  71. }
  72. db.SaveChanges();
  73. LogHelper.Instance.WriteLog("startsend", "获取微信商户开户意愿确认状态");
  74. }
  75. }
  76. // else
  77. // {
  78. // LogHelper.Instance.WriteLog("starte", "获取微信商户开户意愿确认状态");
  79. // RedisDbconn.Instance.AddList("WeChatAuthResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\"}");
  80. // LogHelper.Instance.WriteLog("start2end", "获取微信商户开户意愿确认状态");
  81. // }
  82. db.Dispose();
  83. }
  84. catch (Exception ex)
  85. {
  86. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "获取微信商户开户意愿确认状态异常");
  87. }
  88. }
  89. public void StartAlipay()
  90. {
  91. Thread th = new Thread(StartAlipayDo);
  92. th.IsBackground = true;
  93. th.Start();
  94. }
  95. private void StartAlipayDo()
  96. {
  97. while (true)
  98. {
  99. // string content = RedisDbconn.Instance.RPop<string>("AlipayAuthResultForHaoDaQueue");
  100. // if (!string.IsNullOrEmpty(content))
  101. // {
  102. // JsonData json = JsonMapper.ToObject(content);
  103. // AlipayAddInfo(int.Parse(json["MerchantId"].ToString()));
  104. // }
  105. // else
  106. // {
  107. // Thread.Sleep(10000);
  108. // }
  109. DataTable dt = CustomerSqlConn.dtable("select Id from MerchantAddInfo where HdStatus=3 and BrandId=0 and `QueryCount`=1 and AliMerchantId!='' and AliMerchantId is not null", AppConfig.Base.SqlConnStr);
  110. foreach (DataRow dr in dt.Rows)
  111. {
  112. AlipayAddInfo(int.Parse(dr["Id"].ToString()));
  113. Thread.Sleep(1000);
  114. }
  115. Thread.Sleep(120000);
  116. }
  117. }
  118. public void AlipayAddInfo(int Id)
  119. {
  120. try
  121. {
  122. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "获取支付宝商家认证状态");
  123. LogHelper.Instance.WriteLog("start", "获取支付宝商家认证状态");
  124. WebCMSEntities db = new WebCMSEntities();
  125. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  126. string result = AlipayFunctionForHD.Instance.AuthOrderAuthQuery(info.AliMerchantId);
  127. JsonData jsonObj = JsonMapper.ToObject(result);
  128. LogHelper.Instance.WriteLog(result, "获取支付宝商家认证状态");
  129. if (jsonObj["alipay_merchant_indirect_smidbind_query_response"]["code"].ToString() == "10000")
  130. {
  131. LogHelper.Instance.WriteLog("starts", "获取支付宝商家认证状态");
  132. string order_status = jsonObj["alipay_merchant_indirect_smidbind_query_response"]["check_result"].ToString();
  133. LogHelper.Instance.WriteLog(order_status, "获取支付宝商家认证状态");
  134. if (order_status == "AUTHORIZED")
  135. {
  136. LogHelper.Instance.WriteLog("start1", "获取支付宝商家认证状态");
  137. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  138. info.QueryCount = 2;
  139. merchant.QueryCount = 2;
  140. db.SaveChanges();
  141. LogHelper.Instance.WriteLog("start1end", "获取支付宝商家认证状态");
  142. if (merchant.Latitude == 0)
  143. {
  144. //签约成功调用腾讯地图接口获取地址
  145. RedisDbconn.Instance.AddList("GetTencentAddressInfoQueueHd", "{\"MerChantId\":\"" + merchant.Id + "\",\"Address\":\"" + merchant.Areas + merchant.Address + "\"}");
  146. }
  147. }
  148. // else
  149. // {
  150. // RedisDbconn.Instance.AddList("AlipayAuthResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\"}");
  151. // }
  152. }
  153. db.Dispose();
  154. }
  155. catch (Exception ex)
  156. {
  157. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "获取支付宝商家认证状态异常");
  158. }
  159. }
  160. }