HaoDaExtQueryHelper.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 HaoDaExtQueryHelper
  14. {
  15. public readonly static HaoDaExtQueryHelper Instance = new HaoDaExtQueryHelper();
  16. private HaoDaExtQueryHelper()
  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>("WeChatResultForHaoDaQueue");
  30. // if (!string.IsNullOrEmpty(content))
  31. // {
  32. // JsonData json = JsonMapper.ToObject(content);
  33. // WeChatAddInfo(int.Parse(json["MerchantId"].ToString()), json["ApplymentId"].ToString());
  34. // }
  35. // else
  36. // {
  37. // Thread.Sleep(10000);
  38. // }
  39. DataTable dt = CustomerSqlConn.dtable("select Id,ApplymentId from MerchantAddInfo where HdStatus=3 and BrandId=0 and `Status`=0 and ApplymentId!='' and ApplymentId is not null", AppConfig.Base.SqlConnStr);
  40. foreach (DataRow dr in dt.Rows)
  41. {
  42. WeChatAddInfo(int.Parse(dr["Id"].ToString()), dr["ApplymentId"].ToString());
  43. }
  44. Thread.Sleep(120000);
  45. }
  46. }
  47. public void WeChatAddInfo(int Id, string ApplymentId)
  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.QueryMerchant(ApplymentId);
  56. LogHelper.Instance.WriteLog(result, "查询微信商户意愿申请状态");
  57. JsonData jsonObj = JsonMapper.ToObject(result);
  58. if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT")
  59. {
  60. LogHelper.Instance.WriteLog("starts", "查询微信商户意愿申请状态");
  61. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  62. info.Status = 1;
  63. merchant.Status = 1;
  64. info.WeChatRemark = "";
  65. info.WeChatSignUrl = jsonObj["qrcode_data"].ToString();
  66. db.SaveChanges();
  67. // RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
  68. LogHelper.Instance.WriteLog("startsend", "查询微信商户意愿申请状态");
  69. }
  70. else if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_REJECTED")
  71. {
  72. LogHelper.Instance.WriteLog("start1", "查询微信商户意愿申请状态");
  73. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  74. info.Status = -1;
  75. merchant.Status = -1;
  76. info.WeChatRemark = jsonObj["reject_reason"].ToString();
  77. LogHelper.Instance.WriteLog("start1end", "查询微信商户意愿申请状态");
  78. db.SaveChanges();
  79. }
  80. else if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_PASSED")
  81. {
  82. LogHelper.Instance.WriteLog("start1", "查询微信商户意愿申请状态");
  83. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  84. info.Status = 2;
  85. merchant.Status = 2;
  86. info.WeChatRemark = "";
  87. LogHelper.Instance.WriteLog("start1end", "查询微信商户意愿申请状态");
  88. if (merchant.Latitude == 0)
  89. {
  90. //签约成功调用腾讯地图接口获取地址
  91. RedisDbconn.Instance.AddList("GetTencentAddressInfoQueueHd", "{\"MerChantId\":\"" + merchant.Id + "\",\"Address\":\"" + merchant.Areas + merchant.Address + "\"}");
  92. }
  93. db.SaveChanges();
  94. }
  95. // else
  96. // {
  97. // LogHelper.Instance.WriteLog("starte", "查询微信商户意愿申请状态");
  98. // RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + ApplymentId + "\"}");
  99. // LogHelper.Instance.WriteLog("start2end", "查询微信商户意愿申请状态");
  100. // }
  101. db.Dispose();
  102. }
  103. catch (Exception ex)
  104. {
  105. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
  106. }
  107. }
  108. public void StartAlipay()
  109. {
  110. Thread th = new Thread(StartAlipayDo);
  111. th.IsBackground = true;
  112. th.Start();
  113. }
  114. private void StartAlipayDo()
  115. {
  116. while (true)
  117. {
  118. // string content = RedisDbconn.Instance.RPop<string>("AlipayResultForHaoDaQueue");
  119. // if (!string.IsNullOrEmpty(content))
  120. // {
  121. // JsonData json = JsonMapper.ToObject(content);
  122. // AlipayAddInfo(int.Parse(json["MerchantId"].ToString()), json["order_no"].ToString());
  123. // }
  124. // else
  125. // {
  126. // Thread.Sleep(10000);
  127. // }
  128. DataTable dt = CustomerSqlConn.dtable("select Id,SeoTitle from MerchantAddInfo where HdStatus=3 and BrandId=0 and `QueryCount`=0 and SeoTitle!='' and SeoTitle is not null", AppConfig.Base.SqlConnStr);
  129. foreach (DataRow dr in dt.Rows)
  130. {
  131. AlipayAddInfo(int.Parse(dr["Id"].ToString()), dr["SeoTitle"].ToString());
  132. }
  133. Thread.Sleep(120000);
  134. }
  135. }
  136. public void AlipayAddInfo(int Id, string OrderNo)
  137. {
  138. try
  139. {
  140. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "查询支付宝商户意愿申请状态");
  141. LogHelper.Instance.WriteLog("start", "查询支付宝商户意愿申请状态");
  142. WebCMSEntities db = new WebCMSEntities();
  143. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  144. string result = AlipayFunctionForHD.Instance.AuthOrderQuery(OrderNo);
  145. JsonData jsonObj = JsonMapper.ToObject(result);
  146. LogHelper.Instance.WriteLog(result, "查询支付宝商户意愿申请状态");
  147. if (jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["code"].ToString() == "10000")
  148. {
  149. LogHelper.Instance.WriteLog("starts", "查询支付宝商户意愿申请状态");
  150. string order_status = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["order_status"].ToString();
  151. LogHelper.Instance.WriteLog(order_status, "查询支付宝商户意愿申请状态");
  152. if (order_status == "CONTACT_CONFIRM")
  153. {
  154. LogHelper.Instance.WriteLog("start1", "查询支付宝商户意愿申请状态");
  155. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  156. info.QueryCount = 1;
  157. merchant.QueryCount = 1;
  158. info.AlipayRemark = "";
  159. info.AlipaySignUrl = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["qr_code"].ToString();
  160. db.SaveChanges();
  161. // RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
  162. LogHelper.Instance.WriteLog("start1end", "查询支付宝商户意愿申请状态");
  163. }
  164. else if (order_status == "AUDIT_FREEZE")
  165. {
  166. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  167. LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
  168. if (result.Contains("\"qr_code\":"))
  169. {
  170. info.QueryCount = 1;
  171. merchant.QueryCount = 1;
  172. info.AlipayRemark = "";
  173. info.AlipaySignUrl = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["qr_code"].ToString();
  174. }
  175. else
  176. {
  177. info.QueryCount = -1;
  178. merchant.QueryCount = -1;
  179. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  180. }
  181. LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
  182. db.SaveChanges();
  183. }
  184. else if (order_status == "AUDIT_REJECT")
  185. {
  186. LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
  187. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  188. info.QueryCount = -1;
  189. merchant.QueryCount = -1;
  190. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["verify_list"][0]["fail_reason"].ToString();
  191. LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
  192. db.SaveChanges();
  193. }
  194. else if (order_status == "AUDIT_PASS")
  195. {
  196. LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
  197. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  198. info.QueryCount = 2;
  199. merchant.QueryCount = 2;
  200. info.AlipayRemark = "";
  201. LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
  202. if (merchant.Latitude == 0)
  203. {
  204. //签约成功调用腾讯地图接口获取地址
  205. RedisDbconn.Instance.AddList("GetTencentAddressInfoQueueHd", "{\"MerChantId\":\"" + merchant.Id + "\",\"Address\":\"" + merchant.Areas + merchant.Address + "\"}");
  206. }
  207. db.SaveChanges();
  208. }
  209. // else
  210. // {
  211. // RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + OrderNo + "\"}");
  212. // }
  213. }
  214. else
  215. {
  216. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  217. info.QueryCount = -1;
  218. merchant.QueryCount = -1;
  219. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  220. db.SaveChanges();
  221. }
  222. db.Dispose();
  223. }
  224. catch (Exception ex)
  225. {
  226. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
  227. }
  228. }
  229. }