HaoDaAuthQueryHelper.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. using System.Data;
  13. public class HaoDaAuthQueryHelper
  14. {
  15. public readonly static HaoDaAuthQueryHelper Instance = new HaoDaAuthQueryHelper();
  16. private HaoDaAuthQueryHelper()
  17. {
  18. }
  19. public void Start()
  20. {
  21. Thread th = new Thread(StartDo);
  22. th.IsBackground = true;
  23. th.Start();
  24. }
  25. private void StartDo()
  26. {
  27. while (true)
  28. {
  29. DataTable dt = CustomerSqlConn.dtable("select Id,OutMchtNo,StoreNo from MerchantAddInfo where HdStatus=3 and BrandId=0 and OutMchtNo is not null and StoreNo is not null and ((`Status`=1 and WeChatMerchantId is null) or (`QueryCount`=1 and AliMerchantId is null)) order by Id desc", AppConfig.Base.SqlConnStr);
  30. foreach (DataRow dr in dt.Rows)
  31. {
  32. QueryAuthStatus(dr["Id"].ToString(), dr["OutMchtNo"].ToString(), dr["StoreNo"].ToString());
  33. Thread.Sleep(2000);
  34. }
  35. Thread.Sleep(10000);
  36. }
  37. }
  38. public void QueryAuthStatus(string MerchantId, string MchtNo, string StoreNo)
  39. {
  40. try
  41. {
  42. var Id = int.Parse(MerchantId);
  43. WebCMSEntities db = new WebCMSEntities();
  44. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  45. var jsonObj = JsonMapper.ToObject(HaoDaHelper.Instance.QueryAuthStatus(MchtNo, StoreNo, info.BrandId));
  46. //成功(已认证)
  47. if (jsonObj["resultCode"].ToString() == "1")
  48. {
  49. // MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  50. var wxcheck = jsonObj["wechatVerifyState"].ToString();
  51. var alicheck = jsonObj["aliVerifyState"].ToString();
  52. info.WeChatMerchantId = jsonObj["wechatMerchantId"].ToString();
  53. info.AliMerchantId = jsonObj["aliMerchantId"].ToString();
  54. // if (wxcheck == "1")
  55. // {
  56. // info.Status = 2;
  57. // info.WeChatMerchantId = jsonObj["wechatMerchantId"].ToString();
  58. // merchant.Status = 2;
  59. // info.WeChatRemark = "";
  60. // }
  61. // if (alicheck == "1")
  62. // {
  63. // info.QueryCount = 2;
  64. // info.AliMerchantId = jsonObj["aliMerchantId"].ToString();
  65. // merchant.QueryCount = 2;
  66. // info.AlipayRemark = "";
  67. // }
  68. // if (wxcheck != "1" || alicheck != "1")
  69. // {
  70. // RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + MerchantId + "\",\"MchtNo\":\"" + info.OutMchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
  71. // }
  72. db.SaveChanges();
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "查询实名认证状态异常");
  78. }
  79. }
  80. }