HaoDaExtQueryHelper.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 `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. db.SaveChanges();
  89. }
  90. // else
  91. // {
  92. // LogHelper.Instance.WriteLog("starte", "查询微信商户意愿申请状态");
  93. // RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + ApplymentId + "\"}");
  94. // LogHelper.Instance.WriteLog("start2end", "查询微信商户意愿申请状态");
  95. // }
  96. db.Dispose();
  97. }
  98. catch (Exception ex)
  99. {
  100. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
  101. }
  102. }
  103. public void StartAlipay()
  104. {
  105. Thread th = new Thread(StartAlipayDo);
  106. th.IsBackground = true;
  107. th.Start();
  108. }
  109. private void StartAlipayDo()
  110. {
  111. while (true)
  112. {
  113. // string content = RedisDbconn.Instance.RPop<string>("AlipayResultForHaoDaQueue");
  114. // if (!string.IsNullOrEmpty(content))
  115. // {
  116. // JsonData json = JsonMapper.ToObject(content);
  117. // AlipayAddInfo(int.Parse(json["MerchantId"].ToString()), json["order_no"].ToString());
  118. // }
  119. // else
  120. // {
  121. // Thread.Sleep(10000);
  122. // }
  123. DataTable dt = CustomerSqlConn.dtable("select Id,SeoTitle from MerchantAddInfo where HdStatus=3 and `QueryCount`=0 and SeoTitle!='' and SeoTitle is not null", AppConfig.Base.SqlConnStr);
  124. foreach(DataRow dr in dt.Rows)
  125. {
  126. AlipayAddInfo(int.Parse(dr["Id"].ToString()), dr["SeoTitle"].ToString());
  127. }
  128. Thread.Sleep(120000);
  129. }
  130. }
  131. public void AlipayAddInfo(int Id, string OrderNo)
  132. {
  133. try
  134. {
  135. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "查询支付宝商户意愿申请状态");
  136. LogHelper.Instance.WriteLog("start", "查询支付宝商户意愿申请状态");
  137. WebCMSEntities db = new WebCMSEntities();
  138. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  139. string result = AlipayFunctionForHD.Instance.AuthOrderQuery(OrderNo);
  140. JsonData jsonObj = JsonMapper.ToObject(result);
  141. LogHelper.Instance.WriteLog(result, "查询支付宝商户意愿申请状态");
  142. if (jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["code"].ToString() == "10000")
  143. {
  144. LogHelper.Instance.WriteLog("starts", "查询支付宝商户意愿申请状态");
  145. string order_status = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["order_status"].ToString();
  146. LogHelper.Instance.WriteLog(order_status, "查询支付宝商户意愿申请状态");
  147. if (order_status == "CONTACT_CONFIRM")
  148. {
  149. LogHelper.Instance.WriteLog("start1", "查询支付宝商户意愿申请状态");
  150. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  151. info.QueryCount = 1;
  152. merchant.QueryCount = 1;
  153. info.AlipayRemark = "";
  154. info.AlipaySignUrl = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["qr_code"].ToString();
  155. db.SaveChanges();
  156. // RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
  157. LogHelper.Instance.WriteLog("start1end", "查询支付宝商户意愿申请状态");
  158. }
  159. else if (order_status == "AUDIT_FREEZE")
  160. {
  161. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  162. LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
  163. if(result.Contains("\"qr_code\":"))
  164. {
  165. info.QueryCount = 1;
  166. merchant.QueryCount = 1;
  167. info.AlipayRemark = "";
  168. info.AlipaySignUrl = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["qr_code"].ToString();
  169. }
  170. else
  171. {
  172. info.QueryCount = -1;
  173. merchant.QueryCount = -1;
  174. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  175. }
  176. LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
  177. db.SaveChanges();
  178. }
  179. else if (order_status == "AUDIT_REJECT")
  180. {
  181. LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
  182. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  183. info.QueryCount = -1;
  184. merchant.QueryCount = -1;
  185. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["verify_list"][0]["fail_reason"].ToString();
  186. LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
  187. db.SaveChanges();
  188. }
  189. else if (order_status == "AUDIT_PASS")
  190. {
  191. LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
  192. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  193. info.QueryCount = 2;
  194. merchant.QueryCount = 2;
  195. info.AlipayRemark = "";
  196. LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
  197. db.SaveChanges();
  198. }
  199. // else
  200. // {
  201. // RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + OrderNo + "\"}");
  202. // }
  203. }
  204. else
  205. {
  206. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  207. info.QueryCount = -1;
  208. merchant.QueryCount = -1;
  209. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  210. db.SaveChanges();
  211. }
  212. db.Dispose();
  213. }
  214. catch (Exception ex)
  215. {
  216. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
  217. }
  218. }
  219. }