PumpNotifyTransactionDoneCommand.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. using Edge.Core.Parser.BinaryParser.Attributes;
  2. using Edge.Core.Parser.BinaryParser.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Text;
  8. namespace FuRen_Sinopec_IcCardReader
  9. {
  10. public class PumpNotifyTransactionDoneCommand : KaJiLianDongV11MessageTemplateBase
  11. {
  12. public override string ToLogString()
  13. {
  14. return base.ToLogString() + ", Friendly T_Type_交易类型:" + GetFriendlyT_Type_交易类型(this.T_Type_交易类型).Select(s => s.ToString()).Aggregate((acc, n) => acc + "--" + n);
  15. }
  16. //[Format(1, EncodingType.BIN, 0)]
  17. //public byte POS_P终端机身号 { get; set; }
  18. /// <summary>
  19. /// 每一个通讯终端内部必须有一个独立的递增的交易流水号 POS-TTC,从此通讯终端送出
  20. /// 的每笔交易流水号都必须不相同,而且是连续递增的;
  21. /// </summary>
  22. [Format(4, EncodingType.BIN, 1)]
  23. public int POS_TTC { get; set; }
  24. /// <summary>
  25. /// b7=1:卡错;
  26. /// b6=0/1:使用后台黑(白)名单/使用油机内黑(白)名单
  27. /// b4 = 1:扣款签名有效(无法判断用户卡 TAC 标记是否清除);
  28. /// b3-b0:0=正常加油;
  29. ///1=逃卡;
  30. ///2=错卡;
  31. ///3=补扣;
  32. ///4=补充
  33. ///5=员工上班(每条枪一条记录;对于一个IC卡终端有多条油枪时,每枪一条记录)
  34. ///6=员工下班(每条枪一条记录;一个IC卡终端有多条油枪时,每枪一条记录)
  35. ///7=非卡机联动加油
  36. ///8=对油价信息的回应
  37. ///9=卡片交易出错记录(出错后在TAC即电子签名字段填写出错原因,出错原因代码见附录9)
  38. /// </summary>
  39. /// <param name="raw"></param>
  40. /// <returns></returns>
  41. public static IEnumerable<PumpTransactionType> GetFriendlyT_Type_交易类型(byte raw)
  42. {
  43. var result = new List<PumpTransactionType>();
  44. if (raw.GetBit(7) == 1) result.Add(PumpTransactionType.卡错);
  45. result.Add(raw.GetBit(6) == 0 ? PumpTransactionType.使用后台黑or白名单 : PumpTransactionType.使用油机内黑or白名单);
  46. if (raw.GetBit(4) == 1) result.Add(PumpTransactionType.扣款签名有效);
  47. var bit0To3 = raw & 15;
  48. switch (bit0To3)
  49. {
  50. case 0:
  51. result.Add(PumpTransactionType.正常加油);
  52. break;
  53. case 1:
  54. result.Add(PumpTransactionType.逃卡);
  55. break;
  56. case 2:
  57. result.Add(PumpTransactionType.错卡);
  58. break;
  59. case 3:
  60. result.Add(PumpTransactionType.补扣);
  61. break;
  62. case 4:
  63. result.Add(PumpTransactionType.补充);
  64. break;
  65. case 5:
  66. result.Add(PumpTransactionType.员工上班);
  67. break;
  68. case 6:
  69. result.Add(PumpTransactionType.员工下班);
  70. break;
  71. case 7:
  72. result.Add(PumpTransactionType.非卡机联动加油);
  73. break;
  74. case 8:
  75. result.Add(PumpTransactionType.对修改油价信息的回应);
  76. break;
  77. case 9:
  78. result.Add(PumpTransactionType.卡片交易出错记录);
  79. break;
  80. }
  81. return result.ToArray();
  82. }
  83. public enum PumpTransactionType
  84. {
  85. 卡错,
  86. 使用后台黑or白名单,
  87. 使用油机内黑or白名单,
  88. 扣款签名有效,
  89. 正常加油,
  90. 逃卡,
  91. 错卡,
  92. 补扣,
  93. 补充,
  94. 员工上班,
  95. 员工下班,
  96. 非卡机联动加油,
  97. 对修改油价信息的回应,
  98. 卡片交易出错记录
  99. }
  100. /// <summary>
  101. /// call function GetFriendlyT_Type_交易类型() to get more friendly result.
  102. /// 交易类型
  103. /// b7=1:卡错;
  104. /// b6=0/1:使用后台黑(白)名单/使用油机内黑(白)名单
  105. /// b4=1:扣款签名有效(无法判断用户卡 TAC 标记是否清除);
  106. /// b3-b0:0=正常加油;
  107. /// 1=逃卡;
  108. /// 2=错卡;
  109. /// 3=补扣;
  110. /// 4=补充
  111. /// 5=员工上班(每条枪一条记录;对于一个IC卡终端有多条油枪时,每枪一条记录)
  112. /// 6=员工下班(每条枪一条记录;一个IC卡终端有多条油枪时,每枪一条记录)
  113. /// 7=非卡机联动加油
  114. /// 8=对油价信息的回应
  115. /// 9=卡片交易出错记录(出错后在TAC即电子签名字段填写出错原因,出错原因代码见附录9)
  116. /// </summary>
  117. [Format(1, EncodingType.BIN, 2)]
  118. public byte T_Type_交易类型 { get; set; }
  119. /// <summary>
  120. /// 日期及时间
  121. /// </summary>
  122. [Format(7, EncodingType.BcdString, 3)]
  123. public long TIME_Raw { get; private set; }
  124. public DateTime GetTime()
  125. {
  126. CultureInfo culture = new CultureInfo("zh-CN");
  127. var dd = this.TIME_Raw.ToString();
  128. var dt = DateTime.ParseExact(dd, "yyyyMMddHHmmss", culture);
  129. return dt;
  130. }
  131. public void SetTime(DateTime dateTime)
  132. {
  133. var str = dateTime.ToString("yyyyMMddHHmmss");
  134. this.TIME_Raw = long.Parse(str);
  135. }
  136. [Format(10, EncodingType.BcdString, 4)]
  137. public string ASN卡应用号 { get; set; }
  138. /// <summary>
  139. /// 正常成交:成交后余额;
  140. /// 正常成交:成交后余额; 逃卡或卡错:交易前的原额,单位同UNIT的规定 。
  141. /// </summary>
  142. [Format(4, EncodingType.BIN, 5)]
  143. public int BAL余额 { get; set; }
  144. [Format(3, EncodingType.BIN, 6)]
  145. public int AMN数额 { get; set; }
  146. /// <summary>
  147. /// 卡交易序号
  148. /// </summary>
  149. [Format(2, EncodingType.BIN, 7)]
  150. public int CTC { get; set; }
  151. /// <summary>
  152. /// 电子签名 , 加油、补扣、补充交易时为TAC,逃卡时为GTAC
  153. /// </summary>
  154. [Format(4, EncodingType.BIN, 8)]
  155. public int TAC电子签名 { get; set; }
  156. /// <summary>
  157. /// 解灰认证码 , 逃卡/卡错时有效
  158. /// </summary>
  159. [Format(4, EncodingType.BIN, 9)]
  160. public int GMAC电子签名 { get; set; }
  161. /// <summary>
  162. /// 解灰认证码 , 逃卡/卡错时有效
  163. /// </summary>
  164. [Format(4, EncodingType.BIN, 10)]
  165. public int PSAM_TAC灰锁签名 { get; set; }
  166. /// <summary>
  167. /// PSAM卡号,右8个字节用于PSAM-TAC的密钥分散算 法
  168. /// </summary>
  169. [Format(10, EncodingType.BcdString, 11)]
  170. public string PSAM_ASN_PSAM应用号 { get; set; }
  171. /// <summary>
  172. /// 用于TAC,GTAC运算
  173. /// </summary>
  174. [EnumerableFormat(6, 12, EncodingType = EncodingType.BIN)]
  175. public List<byte> PSAM_TID_PSAM编号 { get; set; }
  176. /// <summary>
  177. /// 由PSAM卡产生的终端交易序号,签名以此为准
  178. /// </summary>
  179. [Format(4, EncodingType.BIN, 13)]
  180. public int PSAM_TTC { get; set; }
  181. /// <summary>
  182. /// 0=石油卡电子油票; 1=石油积分区积分; 2=金融卡电子钱包; 3=金融卡电子存折
  183. /// </summary>
  184. [Format(1, EncodingType.BIN, 14)]
  185. public byte DS_扣款来源 { get; set; }
  186. /// <summary>
  187. /// Bit1-0 (单位) =0:金额(分); =1:点数(0.01点) Bit7-4 (方式) =0:现金; =1:油票; =2:记帐 =3:银行卡;=4:其他; =5:其他1
  188. /// </summary>
  189. [Format(1, EncodingType.BIN, 15)]
  190. public byte UNIT_结算单位_方式 { get; set; }
  191. /// <summary>
  192. /// b0= 0 = 石化规范卡;1 = PBOC金融卡;
  193. /// </summary>
  194. [Format(1, EncodingType.BIN, 16)]
  195. public byte C_TYPE_卡类 { get; set; }
  196. /// <summary>
  197. /// b7-4:卡密钥索引号;b3-0:卡密钥版本号
  198. /// </summary>
  199. [Format(1, EncodingType.BIN, 17)]
  200. public byte VER_版本 { get; set; }
  201. /// <summary>
  202. ///
  203. /// </summary>
  204. [Format(1, EncodingType.BIN, 18)]
  205. public byte NZN_枪号 { get; set; }
  206. // Fu Ren Pump have the issue of pass in this code, at least in lab environment.
  207. [Format(2, EncodingType.BcdString, 19)]
  208. public string G_CODE_油品代码 { get; set; }
  209. //[Format(2, EncodingType.BIN, 19)]
  210. //public int G_CODE_油品代码 { get; set; }
  211. [Format(3, EncodingType.BIN, 20)]
  212. public int VOL_升数 { get; set; }
  213. [Format(2, EncodingType.BIN, 21)]
  214. public int PRC_成交价格 { get; set; }
  215. /// <summary>
  216. /// 255:没有员工上班
  217. /// </summary>
  218. [Format(1, EncodingType.BIN, 22)]
  219. public byte EMP_员工号 { get; set; }
  220. [Format(4, EncodingType.BIN, 23)]
  221. public int V_TOT_升累计 { get; set; }
  222. /// <summary>
  223. /// 全部填零
  224. /// </summary>
  225. [EnumerableFormat(11, 24, EncodingType = EncodingType.BIN)]
  226. public List<byte> RFU_备用 { get; set; }
  227. /// <summary>
  228. /// PBOC 标准3DES算法 计算范围:从POS-TTC开始(含POS-TTC)
  229. /// </summary>
  230. [Format(4, EncodingType.BIN, 25)]
  231. public int T_MAC_终端数据认证码 { get; set; }
  232. }
  233. }