CheckWeChatBindService.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using MySystem.Models.Main;
  6. using Library;
  7. using LitJson;
  8. using System.Text.RegularExpressions;
  9. using System.Threading;
  10. namespace MySystem
  11. {
  12. public class CheckWeChatBindService
  13. {
  14. public readonly static CheckWeChatBindService Instance = new CheckWeChatBindService();
  15. private CheckWeChatBindService()
  16. { }
  17. public void Start()
  18. {
  19. Thread th = new Thread(StartListen);
  20. th.IsBackground = true;
  21. th.Start();
  22. }
  23. public void StartListen()
  24. {
  25. while (true)
  26. {
  27. string CheckDate = DateTime.Now.AddMinutes(-15).ToString("yyyy-MM-dd HH:mm:ss");
  28. DataTable dt = CustomerSqlConn.dtable("select Id from MerchantAddInfo where HdStatus=3 and HdBindWeChat=0 and BrandId=0 and HdPassDate<'" + CheckDate + "' and OutMchtNo!='' and OutMchtNo is not null", AppConfig.Base.SqlConnStr);
  29. foreach (DataRow dr in dt.Rows)
  30. {
  31. StartDo(int.Parse(function.CheckInt(dr["Id"].ToString())));
  32. }
  33. Thread.Sleep(10000);
  34. }
  35. }
  36. public string StartDo(int MerchantId)
  37. {
  38. try
  39. {
  40. WebCMSEntities db = new WebCMSEntities();
  41. MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  42. if (merchantadd != null)
  43. {
  44. //绑定微信appid接口
  45. JsonData bindInfo = JsonMapper.ToObject(HaoDaHelper.Instance.BindWeChatAppId(merchantadd.OutMchtNo, merchantadd.StoreNo, AppConfig.Haoda.SubAppId, merchantadd.BrandId));
  46. //失败
  47. if (bindInfo["resultCode"].ToString() == "0")
  48. {
  49. merchantadd.WeChatRemark = bindInfo["errorDesc"].ToString();
  50. }
  51. else
  52. {
  53. merchantadd.HdBindWeChat = 1;
  54. }
  55. db.SaveChanges();
  56. }
  57. db.Dispose();
  58. }
  59. catch (Exception ex)
  60. {
  61. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "好哒商户进件状态查询异常");
  62. }
  63. return "";
  64. }
  65. }
  66. }