HaoDaHelper.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using System.Threading;
  6. using Common;
  7. using Infrastructure;
  8. using LitJson;
  9. using Microsoft.AspNetCore.Mvc;
  10. using Model;
  11. using Services;
  12. using Util;
  13. public class HaoDaHelper
  14. {
  15. public readonly static HaoDaHelper Instance = new HaoDaHelper();
  16. private HaoDaHelper()
  17. { }
  18. public void Start()
  19. {
  20. Thread th = new Thread(DoWorks);
  21. th.IsBackground = true;
  22. th.Start();
  23. }
  24. public void DoWorks()
  25. {
  26. while (true)
  27. {
  28. string content = RedisServer.Cache.RPop<string>("hd:notice:order");
  29. if(!string.IsNullOrEmpty(content))
  30. {
  31. DoQueue(content);
  32. }
  33. else
  34. {
  35. Thread.Sleep(5000);
  36. }
  37. }
  38. }
  39. public void DoQueue(string content)
  40. {
  41. try
  42. {
  43. string[] dataArray = content.Split(new string[]{ "#cut#" }, StringSplitOptions.None);
  44. JsonData header = JsonMapper.ToObject(dataArray[0]);
  45. content = dataArray[1];
  46. string signstr = header["X-Sign"][0].ToString();
  47. SortedList<string, string> dic = Newtonsoft.Json.JsonConvert.DeserializeObject<SortedList<string, string>>(content);
  48. string sign = Function.BuildQueryString(dic);
  49. bool checkSign = HaoDa.Instance.VerifySign(sign, signstr);
  50. if(checkSign)
  51. {
  52. var item = Newtonsoft.Json.JsonConvert.DeserializeObject<HdTradeRecord>(content);
  53. var tradeService = App.GetService<IHdTradeRecordService>();
  54. tradeService.addHdTradeRecord(item);
  55. // 商户号,设备号,终端类型,订单号,支付方式,交易类型,交易金额,交易手续费,交易时间,结算周期,费率
  56. // {"agentId": "039034", "merchId": "015110201559354", "merchName": "测试商户号", "ordId": "20230324H00030016535Y", "transAmt": "100.0", "feeAmt": "0.65", "feeRate": "0.65", "cardType": "C", "devId": "00000002213MDE119333", "transStat": "S", "transType": "51", "paymentMethod": "0", "settleType": "0", "transDate": "20230324", "transTime": "20230324111954", "quickPassFlag": "0", "simFee": "36.00", "servFee": "36.65"}
  57. if(item.transType == "31")
  58. {
  59. string paymentMethod = item.paymentMethod;
  60. if(paymentMethod == "0") paymentMethod = "刷卡";
  61. if(paymentMethod == "1") paymentMethod = "微信";
  62. if(paymentMethod == "2") paymentMethod = "支付宝";
  63. if(paymentMethod == "7") paymentMethod = "银联二维码";
  64. string settleType = item.settleType;
  65. if(settleType == "0") settleType = "S0";
  66. if(settleType == "1") settleType = "T1";
  67. if(settleType == "2") settleType = "D1";
  68. string data = item.merchId + "," + item.devId + ",好哒设备," + item.ordId + "," + paymentMethod + "," + item.transType + "," + item.transAmt + "," + item.feeAmt + "," + item.transTime + "," + settleType + "," + item.feeRate;
  69. RedisServer.Cache.LPush("ListenTradeDataByOneQueue", data);
  70. }
  71. // else if(item.transType == "40")
  72. // {
  73. // string data = item.devId + "," + item.merchId + ",好哒设备," + item.transDate + "," + item.transAmt + ",0," + item.transDate + ",蒲晓敏," + item.merchName + "," + item.transDate + ",待定,None";
  74. // RedisServer.Cache.LPush("ListenDepositDataByOneQueue", data);
  75. // }
  76. }
  77. }
  78. catch (Exception ex)
  79. {
  80. Function.WriteLog(DateTime.Now.ToString() + "\n" + ex, "好哒订单入库异常");
  81. }
  82. }
  83. public void StartDeposit()
  84. {
  85. Thread th = new Thread(DoWorksDeposit);
  86. th.IsBackground = true;
  87. th.Start();
  88. }
  89. public void DoWorksDeposit()
  90. {
  91. while (true)
  92. {
  93. string content = RedisServer.Cache.RPop<string>("hd:notice:deposit");
  94. if(!string.IsNullOrEmpty(content))
  95. {
  96. DoQueueDeposit(content);
  97. }
  98. else
  99. {
  100. Thread.Sleep(5000);
  101. }
  102. }
  103. }
  104. public void DoQueueDeposit(string content)
  105. {
  106. try
  107. {
  108. string[] dataArray = content.Split(new string[]{ "#cut#" }, StringSplitOptions.None);
  109. JsonData header = JsonMapper.ToObject(dataArray[0]);
  110. content = dataArray[1];
  111. string signstr = header["X-Sign"][0].ToString();
  112. SortedList<string, string> dic = Newtonsoft.Json.JsonConvert.DeserializeObject<SortedList<string, string>>(content);
  113. string sign = Function.BuildQueryString(dic);
  114. bool checkSign = HaoDa.Instance.VerifySign(sign, signstr);
  115. if(checkSign)
  116. {
  117. var item = Newtonsoft.Json.JsonConvert.DeserializeObject<HdDepositRecord>(content);
  118. var depositService = App.GetService<IHdDepositRecordService>();
  119. depositService.addHdDepositRecord(item);
  120. string data = item.snNo + "," + item.mchtNo + "," + item.deviceType + "," + item.effectiveTime + "," + item.depositAmount + ",0," + item.effectiveTime + ",蒲晓敏," + item.mchtNm + "," + item.effectiveTime + "," + item.channelKind + "," + item.activityId;
  121. RedisServer.Cache.LPush("ListenDepositDataByOneQueue", data);
  122. }
  123. }
  124. catch (Exception ex)
  125. {
  126. Function.WriteLog(DateTime.Now.ToString() + "\n" + ex, "好哒订单入库异常");
  127. }
  128. }
  129. }