PumpNotifyTransactionDoneRequest.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 LanTian_Sinopec_PumpIcCardReader
  9. {
  10. public class PumpNotifyTransactionDoneRequest : 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 string Raw_TIME { get; private set; }
  124. public DateTime TIME
  125. {
  126. get { return DateTime.Parse(this.Raw_TIME); }
  127. set { this.Raw_TIME = value.ToString("yyyyMMddHHmmss"); }
  128. }
  129. [Format(10, EncodingType.BcdString, 4)]
  130. public string ASN卡应用号 { get; set; }
  131. /// <summary>
  132. /// 正常成交:成交后余额;
  133. /// 正常成交:成交后余额; 逃卡或卡错:交易前的原额,单位同UNIT的规定 。
  134. /// </summary>
  135. [Format(4, EncodingType.BIN, 5)]
  136. public int BAL余额 { get; set; }
  137. [Format(3, EncodingType.BIN, 6)]
  138. public int AMN数额 { get; set; }
  139. /// <summary>
  140. /// 卡交易序号
  141. /// </summary>
  142. [Format(2, EncodingType.BIN, 7)]
  143. public int CTC { get; set; }
  144. /// <summary>
  145. /// 电子签名 , 加油、补扣、补充交易时为TAC,逃卡时为GTAC
  146. /// </summary>
  147. [Format(4, EncodingType.BIN, 8)]
  148. public int TAC电子签名 { get; set; }
  149. /// <summary>
  150. /// 解灰认证码 , 逃卡/卡错时有效
  151. /// </summary>
  152. [Format(4, EncodingType.BIN, 9)]
  153. public int GMAC电子签名 { get; set; }
  154. /// <summary>
  155. /// 解灰认证码 , 逃卡/卡错时有效
  156. /// </summary>
  157. [Format(4, EncodingType.BIN, 10)]
  158. public int PSAM_TAC灰锁签名 { get; set; }
  159. /// <summary>
  160. /// PSAM卡号,右8个字节用于PSAM-TAC的密钥分散算 法
  161. /// </summary>
  162. [Format(10, EncodingType.BcdString, 11)]
  163. public string PSAM_ASN_PSAM应用号 { get; set; }
  164. /// <summary>
  165. /// 用于TAC,GTAC运算
  166. /// </summary>
  167. [EnumerableFormat(6, 12, EncodingType = EncodingType.BIN)]
  168. public List<byte> PSAM_TID_PSAM编号 { get; set; }
  169. /// <summary>
  170. /// 由PSAM卡产生的终端交易序号,签名以此为准
  171. /// </summary>
  172. [Format(4, EncodingType.BIN, 13)]
  173. public int PSAM_TTC { get; set; }
  174. /// <summary>
  175. /// 0=石油卡电子油票; 1=石油积分区积分; 2=金融卡电子钱包; 3=金融卡电子存折
  176. /// </summary>
  177. [Format(1, EncodingType.BIN, 14)]
  178. public byte DS_扣款来源 { get; set; }
  179. /// <summary>
  180. /// Bit1-0 (单位) =0:金额(分); =1:点数(0.01点) Bit7-4 (方式) =0:现金; =1:油票; =2:记帐 =3:银行卡;=4:其他; =5:其他1
  181. /// </summary>
  182. [Format(1, EncodingType.BIN, 15)]
  183. public byte UNIT_结算单位_方式 { get; set; }
  184. /// <summary>
  185. /// b0= 0 = 石化规范卡;1 = PBOC金融卡;
  186. /// </summary>
  187. [Format(1, EncodingType.BIN, 16)]
  188. public byte C_TYPE_卡类 { get; set; }
  189. /// <summary>
  190. /// b7-4:卡密钥索引号;b3-0:卡密钥版本号
  191. /// </summary>
  192. [Format(1, EncodingType.BIN, 17)]
  193. public byte VER_版本 { get; set; }
  194. /// <summary>
  195. ///
  196. /// </summary>
  197. [Format(1, EncodingType.BIN, 18)]
  198. public byte NZN_枪号 { get; set; }
  199. // Fu Ren Pump have the issue of pass in this code, at least in lab environment.
  200. [Format(2, EncodingType.BcdString, 19)]
  201. public string G_CODE_油品代码 { get; set; }
  202. //[Format(2, EncodingType.BIN, 19)]
  203. //public int G_CODE_油品代码 { get; set; }
  204. [Format(3, EncodingType.BIN, 20)]
  205. public int VOL_升数 { get; set; }
  206. [Format(2, EncodingType.BIN, 21)]
  207. public int PRC_成交价格 { get; set; }
  208. /// <summary>
  209. /// 255:没有员工上班
  210. /// </summary>
  211. [Format(1, EncodingType.BIN, 22)]
  212. public byte EMP_员工号 { get; set; }
  213. [Format(4, EncodingType.BIN, 23)]
  214. public int V_TOT_升累计 { get; set; }
  215. /// <summary>
  216. /// 全部填零
  217. /// </summary>
  218. [EnumerableFormat(11, 24, EncodingType = EncodingType.BIN)]
  219. public List<byte> RFU_备用 { get; set; }
  220. /// <summary>
  221. /// PBOC 标准3DES算法 计算范围:从POS-TTC开始(含POS-TTC)
  222. /// </summary>
  223. [Format(4, EncodingType.BIN, 25)]
  224. public int T_MAC_终端数据认证码 { get; set; }
  225. }
  226. }