SendAuthorization.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using Edge.Core.Parser.BinaryParser.MessageEntity;
  2. using Org.BouncyCastle.Asn1.Ocsp;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace HengshanPaymentTerminal.MessageEntity.Outgoing
  9. {
  10. /// <summary>
  11. /// 发送授权请求给油机数据对象
  12. /// </summary>
  13. public class SendAuthorization : CommonMessage
  14. {
  15. /// <summary>
  16. /// 请求授权的枪号
  17. /// </summary>
  18. public int NozzleNum { get; set; }
  19. /// <summary>
  20. /// 请求授权时间
  21. /// </summary>
  22. private DateTime AuthorizationTime { get; set; }
  23. /// <summary>
  24. /// 授权类型:01:定金额,02:定升数
  25. /// </summary>
  26. private int AuthorizationType { get; set; }
  27. /// <summary>
  28. /// 定值量
  29. /// </summary>
  30. private decimal Value { get; set; }
  31. public SendAuthorization(int nozzleNum, DateTime authorizationTime, int authorizationType, decimal value,byte frame)
  32. {
  33. this.Handle = (byte)Command.ACCREDIT;
  34. NozzleNum = nozzleNum;
  35. AuthorizationTime = authorizationTime;
  36. AuthorizationType = authorizationType;
  37. Value = value;
  38. this.FrameNum = frame;
  39. }
  40. public override byte[] ToCommonByteArray()
  41. {
  42. List<Byte> list = new List<Byte>();
  43. byte[] commandAndNozzle = { this.Handle, (byte)this.NozzleNum };
  44. byte[] authorizationTimeBytes = ConvertDateTimeToByteArray(this.AuthorizationTime);
  45. //将小数点后移两位,因为油机只支持两位小数点,这边传过去的3位字节转为int后取后两位为十分位和百分位
  46. int value = (int)this.Value * 100;
  47. byte[] valueBytes = NumberToByteArrayWithPadding(value, 3);
  48. list.AddRange(commandAndNozzle);
  49. list.AddRange(authorizationTimeBytes);
  50. list.Add((byte)this.AuthorizationType);
  51. list.AddRange(valueBytes);
  52. byte[] sendBytes = content2data(list.ToArray());
  53. return sendBytes;
  54. }
  55. public override CommonMessage ToObject(byte[] datas)
  56. {
  57. return this;
  58. }
  59. }
  60. }