PosPushDataNewHelper.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using MySystem.SpModels;
  5. namespace MySystem
  6. {
  7. public class PosPushDataNewHelper
  8. {
  9. public readonly static PosPushDataNewHelper Instance = new PosPushDataNewHelper();
  10. private PosPushDataNewHelper()
  11. { }
  12. //绑定数据
  13. public static void Bind(Merchants mer)
  14. {
  15. try
  16. {
  17. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  18. dataContent.Add("pos_sn", mer.SnNo); //机具sn
  19. dataContent.Add("mer_no", mer.MerNo); //商户号
  20. dataContent.Add("id_card", mer.MerIdcardNo); //商户身份证
  21. dataContent.Add("mer_name", mer.MerName); //商户姓名
  22. dataContent.Add("mer_mobile", mer.MerMobile); //商户手机号
  23. dataContent.Add("request_id", getRequestId(mer.Id, "bind")); //流水号
  24. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  25. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  26. Push("bind", dataContent);
  27. }
  28. catch (Exception ex)
  29. {
  30. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  31. }
  32. }
  33. public static void Bind(MerchantRecord mer)
  34. {
  35. try
  36. {
  37. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  38. dataContent.Add("pos_sn", mer.MerSnNo); //机具sn
  39. dataContent.Add("mer_no", mer.MerNo); //商户号
  40. dataContent.Add("id_card", mer.LegalIdCard); //商户身份证
  41. dataContent.Add("mer_name", mer.MerName); //商户姓名
  42. dataContent.Add("mer_mobile", ""); //商户手机号
  43. dataContent.Add("request_id", getRequestId(mer.Id, "merchant")); //流水号
  44. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  45. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  46. Push("bind", dataContent);
  47. }
  48. catch (Exception ex)
  49. {
  50. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  51. }
  52. }
  53. //解绑数据
  54. public static void UnBind(UnBindRecord mer)
  55. {
  56. try
  57. {
  58. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  59. dataContent.Add("pos_sn", mer.MerSnNo); //机具sn
  60. dataContent.Add("mer_no", mer.MerNo); //商户号
  61. dataContent.Add("request_id", getRequestId(mer.Id, "unbind")); //流水号
  62. dataContent.Add("un_bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  63. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  64. Push("un_bind", dataContent);
  65. }
  66. catch (Exception ex)
  67. {
  68. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送解绑数据异常");
  69. }
  70. }
  71. //换绑数据
  72. public static void ChangeBind(ChangeBindRecord mer)
  73. {
  74. try
  75. {
  76. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  77. dataContent.Add("request_id", getRequestId(mer.Id, "changebind")); //流水号
  78. dataContent.Add("mer_no", mer.MerNo); //商户号
  79. dataContent.Add("source_pos_sn", mer.MerSnNo); //来源机具sn
  80. dataContent.Add("source_brand", int.Parse(function.CheckInt(mer.ProductType))); //来源品牌
  81. dataContent.Add("to_pos_sn", mer.MerNewSnNo); //兑换机具sn
  82. dataContent.Add("to_brand", int.Parse(function.CheckInt(mer.ProductType))); //兑换品牌
  83. dataContent.Add("change_bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //换绑时间
  84. Push("change_bind", dataContent);
  85. }
  86. catch (Exception ex)
  87. {
  88. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送换绑数据异常");
  89. }
  90. }
  91. //押金数据
  92. public static void Deposit(ActivateRecord act)
  93. {
  94. try
  95. {
  96. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  97. dataContent.Add("pos_sn", act.SnNo); //机具sn
  98. dataContent.Add("mer_no", act.MerNo); //商户号
  99. dataContent.Add("request_id", getRequestId(act.Id, "deposit")); //流水号
  100. dataContent.Add("deposit_amount", act.SeoTitle); //押金金额
  101. dataContent.Add("trade_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  102. dataContent.Add("card_type", 1); //卡类型
  103. dataContent.Add("brand", int.Parse(function.CheckInt(act.ProductType))); //品牌
  104. Push("deposit", dataContent);
  105. }
  106. catch (Exception ex)
  107. {
  108. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送押金数据异常");
  109. }
  110. }
  111. public static void Deposit(TradeRecord trade)
  112. {
  113. try
  114. {
  115. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  116. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  117. dataContent.Add("mer_no", trade.MerNo); //商户号
  118. dataContent.Add("request_id", getRequestId(trade.Id, "deposit1")); //流水号
  119. dataContent.Add("deposit_amount", trade.TradeAmount); //押金金额
  120. dataContent.Add("trade_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  121. dataContent.Add("card_type", 1); //卡类型
  122. dataContent.Add("brand", int.Parse(function.CheckInt(trade.ProductType))); //品牌
  123. Push("deposit", dataContent);
  124. }
  125. catch (Exception ex)
  126. {
  127. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送押金数据异常");
  128. }
  129. }
  130. //激活数据
  131. public static void Active(ActivateRecord act)
  132. {
  133. try
  134. {
  135. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  136. dataContent.Add("pos_sn", act.SnNo); //机具sn
  137. dataContent.Add("mobile", act.MerMobile); //商户号
  138. dataContent.Add("request_id", getRequestId(act.Id, "active")); //流水号
  139. dataContent.Add("activation_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  140. dataContent.Add("brand", int.Parse(function.CheckInt(act.ProductType))); //品牌
  141. Push("active", dataContent);
  142. }
  143. catch (Exception ex)
  144. {
  145. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送激活数据异常");
  146. }
  147. }
  148. //交易数据
  149. public static void Trade(TradeRecord trade)
  150. {
  151. try
  152. {
  153. int QrPayFlag = 0;
  154. int BankCardType = 1;
  155. if (trade.ProductType == "1")
  156. {
  157. if (trade.TradeType == "02") QrPayFlag = 1;
  158. BankCardType = int.Parse(trade.BankCardType);
  159. }
  160. else if (trade.ProductType == "2")
  161. {
  162. if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  163. if (trade.TradeType == "CREDIT_BY_CARD")
  164. {
  165. BankCardType = 1;
  166. }
  167. else
  168. {
  169. BankCardType = 0;
  170. }
  171. }
  172. else if (trade.ProductType == "4")
  173. {
  174. if (trade.TradeType == "200") QrPayFlag = 1;
  175. if (trade.BankCardType == "100")
  176. {
  177. BankCardType = 1;
  178. }
  179. else if (trade.BankCardType == "200")
  180. {
  181. BankCardType = 0;
  182. }
  183. }
  184. else if (trade.ProductType == "6")
  185. {
  186. if (trade.BankCardType == "02" || trade.BankCardType == "12")
  187. {
  188. BankCardType = 1;
  189. }
  190. else
  191. {
  192. BankCardType = 0;
  193. }
  194. }
  195. else if (trade.ProductType == "7")
  196. {
  197. if (trade.BankCardType == "OA" || trade.BankCardType == "CC" || trade.BankCardType == "SCC")
  198. {
  199. BankCardType = 1;
  200. }
  201. else
  202. {
  203. BankCardType = 0;
  204. }
  205. }
  206. else if (trade.ProductType == "8" || trade.ProductType == "9")
  207. {
  208. if (trade.TradeType == "200") QrPayFlag = 1;
  209. if (trade.BankCardType == "100")
  210. {
  211. BankCardType = 1;
  212. }
  213. else if (trade.BankCardType == "200")
  214. {
  215. BankCardType = 0;
  216. }
  217. }
  218. else if (trade.ProductType == "10" || trade.ProductType == "11")
  219. {
  220. if (trade.TradeType == "F010") QrPayFlag = 1;
  221. if (trade.BankCardType == "01")
  222. {
  223. BankCardType = 1;
  224. }
  225. else if (trade.BankCardType == "00")
  226. {
  227. BankCardType = 0;
  228. }
  229. }
  230. else if (trade.ProductType == "12") //盒易付
  231. {
  232. if (trade.Field3 == "1") QrPayFlag = 1;
  233. if (trade.BankCardType == "C")
  234. {
  235. BankCardType = 1;
  236. }
  237. else if (trade.BankCardType == "D")
  238. {
  239. BankCardType = 0;
  240. }
  241. }
  242. else if (trade.ProductType == "15")
  243. {
  244. if (trade.BankCardType == "02")
  245. {
  246. BankCardType = 1;
  247. }
  248. else
  249. {
  250. BankCardType = 0;
  251. }
  252. }
  253. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  254. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  255. dataContent.Add("mer_no", trade.MerNo); //商户号
  256. dataContent.Add("request_id", trade.TradeSerialNo); //流水号
  257. dataContent.Add("trade_amount", trade.TradeAmount); //交易金额
  258. dataContent.Add("trade_time", trade.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  259. dataContent.Add("brand", int.Parse(function.CheckInt(trade.ProductType))); //品牌
  260. dataContent.Add("card_type", BankCardType); //卡类型
  261. dataContent.Add("qr_pay_flag", QrPayFlag); //云闪付标记
  262. Push("trade", dataContent);
  263. }
  264. catch (Exception ex)
  265. {
  266. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送交易数据异常");
  267. }
  268. }
  269. public static void Push(string dataType, Dictionary<string, object> dataContent)
  270. {
  271. Dictionary<string, object> data = new Dictionary<string, object>();
  272. data.Add("data_type", dataType);
  273. data.Add("data_content", dataContent);
  274. RedisDbconn.Instance.AddList("KxsPosDataQueue", Newtonsoft.Json.JsonConvert.SerializeObject(data));
  275. }
  276. public static string getRequestId(int id, string type)
  277. {
  278. if(id > 0)
  279. {
  280. return function.MD5_32(id.ToString() + type);
  281. }
  282. return DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  283. }
  284. }
  285. }