HaoDaExtHelper.cs 4.1 KB

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