HaoDaHelper.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. }