HaoDaExtHelper.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. public class HaoDaExtHelper
  12. {
  13. public readonly static HaoDaExtHelper Instance = new HaoDaExtHelper();
  14. private HaoDaExtHelper()
  15. {
  16. }
  17. public void StartWeChat()
  18. {
  19. Thread th = new Thread(StartWeChatDo);
  20. th.IsBackground = true;
  21. th.Start();
  22. }
  23. private void StartWeChatDo()
  24. {
  25. while (true)
  26. {
  27. string content = RedisDbconn.Instance.RPop<string>("WeChatForHaoDaQueue");
  28. if (!string.IsNullOrEmpty(content))
  29. {
  30. WeChatAddInfo(int.Parse(content));
  31. }
  32. else
  33. {
  34. Thread.Sleep(10000);
  35. }
  36. }
  37. }
  38. public void WeChatAddInfo(int Id)
  39. {
  40. try
  41. {
  42. WebCMSEntities db = new WebCMSEntities();
  43. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  44. string result = WeChatFunctionForHD.Instance.MerchantApply(info);
  45. if (result.Contains("\"applyment_id\":"))
  46. {
  47. JsonData json = JsonMapper.ToObject(result);
  48. string applyment_id = json["applyment_id"].ToString();
  49. RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + applyment_id + "\"}");
  50. }
  51. else if (result.Contains("\"message\":"))
  52. {
  53. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  54. JsonData jsonObj = JsonMapper.ToObject(result);
  55. info.Status = -1;
  56. merchant.Status = -1;
  57. info.WeChatRemark = jsonObj["message"].ToString();
  58. db.SaveChanges();
  59. }
  60. db.Dispose();
  61. }
  62. catch(Exception ex)
  63. {
  64. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
  65. }
  66. }
  67. public void StartAlipay()
  68. {
  69. Thread th = new Thread(StartAlipayDo);
  70. th.IsBackground = true;
  71. th.Start();
  72. }
  73. private void StartAlipayDo()
  74. {
  75. while (true)
  76. {
  77. string content = RedisDbconn.Instance.RPop<string>("AlipayForHaoDaQueue");
  78. if (!string.IsNullOrEmpty(content))
  79. {
  80. AlipayAddInfo(int.Parse(content));
  81. }
  82. else
  83. {
  84. Thread.Sleep(10000);
  85. }
  86. }
  87. }
  88. public void AlipayAddInfo(int Id)
  89. {
  90. try
  91. {
  92. WebCMSEntities db = new WebCMSEntities();
  93. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  94. string result = AlipayFunctionForHD.Instance.AuthOrderCreate(info, info.AlipayAuthToken);
  95. JsonData jsonObj = JsonMapper.ToObject(result);
  96. if (jsonObj["alipay_merchant_indirect_authorder_create_response"]["code"].ToString() == "10000")
  97. {
  98. string order_no = jsonObj["alipay_merchant_indirect_authorder_create_response"]["order_no"].ToString();
  99. RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + order_no + "\"}");
  100. }
  101. else
  102. {
  103. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  104. info.QueryCount = -1;
  105. merchant.QueryCount = -1;
  106. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_create_response"]["msg"].ToString();
  107. db.SaveChanges();
  108. }
  109. db.Dispose();
  110. }
  111. catch(Exception ex)
  112. {
  113. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
  114. }
  115. }
  116. }