Commit 419a5b42 authored by 李远洪's avatar 李远洪

完成终端鉴权消息开发

parent a5c34dcc
#encoding:utf-8
'''
定义终端鉴权消息
'''
from lib.protocol.message.MessageBase import MessageBase
class TerminalAuthenticate_msg(MessageBase):
def __init__(self):
super().__init__() #不执行该方法,无法使用父类里面定义的属性
pass
#######################################################
# 生成一条完整的消息
#######################################################
def generateMsg(self):
msg = ""
msgHeader = self.getMsgHeader()
msgBody = self.getMsgBody()
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
info = self.replace7e7d(info)
msg = msg + info
msg = msg + self.IDENTIFY
return msg
#######################################################
# 获取消息体
#######################################################
def getMsgBody(self):
msg = ""
#鉴权码
authenticateCode = str("asuyx7".encode("gbk"))
authenticateCode = authenticateCode[2:len(authenticateCode) - 1]
authenticateCode = self.str2Hex(authenticateCode)
msg = authenticateCode
return msg
#######################################################
# 获取消息头
#######################################################
def getMsgHeader(self):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID = "0102"
msgBodyProperty = self.getMsgBodyProperty(len(self.getMsgBody())) #消息体属性
phoneNum = self.int2BCD(13146201119) #终端手机号
msgWaterCode = self.int2BCD(1) #消息流水号
subPkgContent = "" #消息包封装项
data = msgID + msgBodyProperty + phoneNum + msgWaterCode + subPkgContent
return data
#获取消息体属性
def getMsgBodyProperty(self,msgBodyLen=128,encryptionType=0,subPkg=0):
if msgBodyLen >= 512:
raise RuntimeError('消息体长度超长!')
msgBodyLen = msgBodyLen #消息体长度
encryptionType = encryptionType #加密方式
subPkg = subPkg #分包
retain = 0 #保留位
data = msgBodyLen + encryptionType + subPkg + retain
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
\ No newline at end of file
...@@ -42,7 +42,9 @@ class TerminalRegister_msg(MessageBase): ...@@ -42,7 +42,9 @@ class TerminalRegister_msg(MessageBase):
#车牌颜色 (车牌颜色,按照 JT/T415-2006 的 5.4.12。未上牌时,取值 为 0) 1:蓝色 2:黄色 3:黑色 4:白色 9:其他 #车牌颜色 (车牌颜色,按照 JT/T415-2006 的 5.4.12。未上牌时,取值 为 0) 1:蓝色 2:黄色 3:黑色 4:白色 9:其他
licencePlateColor = self.int2hexStringByBytes(1) licencePlateColor = self.int2hexStringByBytes(1)
#车辆标识 (车牌颜色为 0 时,表示车辆 VIN;否则,表示公安交通管理 部门颁发的机动车号牌) #车辆标识 (车牌颜色为 0 时,表示车辆 VIN;否则,表示公安交通管理 部门颁发的机动车号牌)
carSign = self.str2Hex(str("渝B23CX".encode("gbk"))) carSign = str("渝B23CX".encode("gbk"))
carSign = carSign[2:len(carSign) - 1]
carSign = self.str2Hex(carSign)
msg = msg + provinceId + manufacturerId + terminalType + terminalId + licencePlateColor + carSign msg = msg + provinceId + manufacturerId + terminalType + terminalId + licencePlateColor + carSign
return msg return msg
......
...@@ -4,6 +4,7 @@ import socket ...@@ -4,6 +4,7 @@ import socket
from lib.protocol.message.Location_msg import Location_msg from lib.protocol.message.Location_msg import Location_msg
from lib.protocol.message.MessageBase import MessageBase from lib.protocol.message.MessageBase import MessageBase
from lib.protocol.message.TerminalAuthenticate_msg import TerminalAuthenticate_msg
from lib.protocol.message.TerminalHeartbeat_msg import TerminalHeartbeat_msg from lib.protocol.message.TerminalHeartbeat_msg import TerminalHeartbeat_msg
from lib.protocol.message.TerminalRegister_msg import TerminalRegister_msg from lib.protocol.message.TerminalRegister_msg import TerminalRegister_msg
from lib.protocol.message.data.TerminalCancle_msg import TerminalCancle_msg from lib.protocol.message.data.TerminalCancle_msg import TerminalCancle_msg
...@@ -15,7 +16,8 @@ port = 9001 ...@@ -15,7 +16,8 @@ port = 9001
# msg = MessageBase().generateMsg() # msg = MessageBase().generateMsg()
# msg = TerminalHeartbeat_msg().generateMsg() #终端心跳 # msg = TerminalHeartbeat_msg().generateMsg() #终端心跳
# msg = TerminalRegister_msg().generateMsg() #终端注册 # msg = TerminalRegister_msg().generateMsg() #终端注册
msg = TerminalCancle_msg().generateMsg() #终端注销 # msg = TerminalCancle_msg().generateMsg() #终端注销
msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = Location_msg().generateMsg() #位置信息汇报 # msg = Location_msg().generateMsg() #位置信息汇报
print(msg) print(msg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment