PosPushDataNewHelper.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Library;
  5. using MySystem.Models.Main;
  6. namespace MySystem
  7. {
  8. public class PosPushDataNewHelper
  9. {
  10. public readonly static PosPushDataNewHelper Instance = new PosPushDataNewHelper();
  11. private PosPushDataNewHelper()
  12. { }
  13. //绑定数据
  14. public static void Bind(MerchantAddInfo mer, PosMachinesTwo pos)
  15. {
  16. try
  17. {
  18. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  19. dataContent.Add("pos_sn", pos.PosSn); //机具sn
  20. dataContent.Add("mer_no", mer.MchtNo); //商户号
  21. dataContent.Add("id_card", mer.IdCardNumber); //商户身份证
  22. dataContent.Add("mer_name", mer.CertMerchantName); //商户姓名
  23. dataContent.Add("mer_mobile", mer.MobilePhone); //商户手机号
  24. dataContent.Add("request_id", getRequestId(mer.Id, "bind")); //流水号
  25. dataContent.Add("bind_time", mer.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  26. dataContent.Add("brand", 101); //品牌
  27. Push("bind", dataContent);
  28. }
  29. catch (Exception ex)
  30. {
  31. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  32. }
  33. }
  34. public static void Bind(MerchantAddInfo mer, MySystem.Models.Main1.PosMachinesTwo pos)
  35. {
  36. Bind(mer, new PosMachinesTwo()
  37. {
  38. PosSn = pos.PosSn,
  39. });
  40. }
  41. public static void Push(string dataType, Dictionary<string, object> dataContent)
  42. {
  43. Dictionary<string, object> data = new Dictionary<string, object>();
  44. data.Add("data_type", dataType);
  45. data.Add("data_content", dataContent);
  46. KxsRedisDbconn.Instance.AddList("KxsPosDataQueue", Newtonsoft.Json.JsonConvert.SerializeObject(data));
  47. }
  48. public static string getRequestId(int id, string type)
  49. {
  50. if(id > 0)
  51. {
  52. return function.MD5_32(id.ToString() + type);
  53. }
  54. return DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  55. }
  56. }
  57. }