HaoDaExtQueryAuthHelper.cs 8.0 KB

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