HaoDaExtQueryAuthHelper.cs 7.8 KB

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