HaoDaExtQueryAuthHelper.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using System.Linq;
  6. using Microsoft.Extensions.Hosting;
  7. using MySystem;
  8. using MySystem.Models;
  9. using LitJson;
  10. using Library;
  11. using MySystem.Models.Main;
  12. public class HaoDaExtQueryAuthHelper
  13. {
  14. public readonly static HaoDaExtQueryAuthHelper Instance = new HaoDaExtQueryAuthHelper();
  15. private HaoDaExtQueryAuthHelper()
  16. {
  17. }
  18. public void StartWeChat()
  19. {
  20. Thread th = new Thread(StartWeChatDo);
  21. th.IsBackground = true;
  22. th.Start();
  23. }
  24. private void StartWeChatDo()
  25. {
  26. while (true)
  27. {
  28. string content = RedisDbconn.Instance.RPop<string>("WeChatAuthResultForHaoDaQueue");
  29. if (!string.IsNullOrEmpty(content))
  30. {
  31. JsonData json = JsonMapper.ToObject(content);
  32. WeChatAddInfo(int.Parse(json["MerchantId"].ToString()));
  33. }
  34. else
  35. {
  36. Thread.Sleep(10000);
  37. }
  38. }
  39. }
  40. public void WeChatAddInfo(int Id)
  41. {
  42. try
  43. {
  44. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "获取微信商户开户意愿确认状态");
  45. LogHelper.Instance.WriteLog("start", "获取微信商户开户意愿确认状态");
  46. WebCMSEntities db = new WebCMSEntities();
  47. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  48. string result = WeChatFunctionForHD.Instance.QueryAuthMerchant(info.WeChatMerchantId);
  49. LogHelper.Instance.WriteLog(result, "获取微信商户开户意愿确认状态");
  50. JsonData jsonObj = JsonMapper.ToObject(result);
  51. if (jsonObj["authorize_state"].ToString() == "AUTHORIZE_STATE_AUTHORIZED")
  52. {
  53. LogHelper.Instance.WriteLog("starts", "获取微信商户开户意愿确认状态");
  54. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  55. info.Status = 2;
  56. merchant.Status = 2;
  57. db.SaveChanges();
  58. LogHelper.Instance.WriteLog("startsend", "获取微信商户开户意愿确认状态");
  59. }
  60. else
  61. {
  62. LogHelper.Instance.WriteLog("starte", "获取微信商户开户意愿确认状态");
  63. RedisDbconn.Instance.AddList("WeChatAuthResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\"}");
  64. LogHelper.Instance.WriteLog("start2end", "获取微信商户开户意愿确认状态");
  65. }
  66. db.Dispose();
  67. }
  68. catch (Exception ex)
  69. {
  70. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "获取微信商户开户意愿确认状态异常");
  71. }
  72. }
  73. public void StartAlipay()
  74. {
  75. Thread th = new Thread(StartAlipayDo);
  76. th.IsBackground = true;
  77. th.Start();
  78. }
  79. private void StartAlipayDo()
  80. {
  81. while (true)
  82. {
  83. string content = RedisDbconn.Instance.RPop<string>("AlipayAuthResultForHaoDaQueue");
  84. if (!string.IsNullOrEmpty(content))
  85. {
  86. JsonData json = JsonMapper.ToObject(content);
  87. AlipayAddInfo(int.Parse(json["MerchantId"].ToString()));
  88. }
  89. else
  90. {
  91. Thread.Sleep(10000);
  92. }
  93. }
  94. }
  95. public void AlipayAddInfo(int Id)
  96. {
  97. try
  98. {
  99. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "获取支付宝商家认证状态");
  100. LogHelper.Instance.WriteLog("start", "获取支付宝商家认证状态");
  101. WebCMSEntities db = new WebCMSEntities();
  102. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  103. string result = AlipayFunctionForHD.Instance.AuthOrderAuthQuery(info.AliMerchantId);
  104. JsonData jsonObj = JsonMapper.ToObject(result);
  105. LogHelper.Instance.WriteLog(result, "获取支付宝商家认证状态");
  106. if (jsonObj["alipay_merchant_indirect_smidbind_query_response"]["code"].ToString() == "10000")
  107. {
  108. LogHelper.Instance.WriteLog("starts", "获取支付宝商家认证状态");
  109. string order_status = jsonObj["alipay_merchant_indirect_smidbind_query_response"]["check_result"].ToString();
  110. LogHelper.Instance.WriteLog(order_status, "获取支付宝商家认证状态");
  111. if (order_status == "AUTHORIZED")
  112. {
  113. LogHelper.Instance.WriteLog("start1", "获取支付宝商家认证状态");
  114. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  115. info.QueryCount = 2;
  116. merchant.QueryCount = 2;
  117. db.SaveChanges();
  118. LogHelper.Instance.WriteLog("start1end", "获取支付宝商家认证状态");
  119. }
  120. else
  121. {
  122. RedisDbconn.Instance.AddList("AlipayAuthResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\"}");
  123. }
  124. }
  125. db.Dispose();
  126. }
  127. catch (Exception ex)
  128. {
  129. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "获取支付宝商家认证状态异常");
  130. }
  131. }
  132. }