Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
new-socketemulator
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李远洪
new-socketemulator
Commits
c2a364ff
Commit
c2a364ff
authored
Apr 24, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改了中文转GBK的方法
parent
48049a07
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
3 deletions
+16
-3
lib/protocol/message/MessageBase.py
lib/protocol/message/MessageBase.py
+16
-3
No files found.
lib/protocol/message/MessageBase.py
View file @
c2a364ff
#encoding:utf-8
#encoding:utf-8
import
datetime
import
datetime
import
random
import
random
import
re
import
time
import
time
from
lib.protocol.Base
import
Base
from
lib.protocol.Base
import
Base
...
@@ -214,9 +215,21 @@ class MessageBase(Base):
...
@@ -214,9 +215,21 @@ class MessageBase(Base):
# 字符串转换为GBK的16进制
# 字符串转换为GBK的16进制
#######################################################
#######################################################
def
GBKString2Hex
(
self
,
data
):
def
GBKString2Hex
(
self
,
data
):
'''
data = str(data.encode("gbk"))
data = str(data.encode("gbk"))
dataHex = self.str2Hex(data[2:len(data) - 1])
dataHex = self.str2Hex(data[2:len(data) - 1])
return dataHex
return dataHex
'''
dataHex
=
""
strLen
=
len
(
data
)
for
i
in
range
(
0
,
strLen
):
if
re
.
search
(
"[0-9a-zA-Z]"
,
data
[
i
])
!=
None
:
dataHex
=
dataHex
+
self
.
str2Hex
(
data
[
i
])
else
:
temp
=
str
(
data
[
i
]
.
encode
(
"gbk"
))
.
replace
(
"
\\
x"
,
""
)
dataHex
=
dataHex
+
temp
[
2
:
len
(
temp
)
-
1
]
return
dataHex
#######################################################
#######################################################
# 16进制转换为GBK字符串
# 16进制转换为GBK字符串
...
@@ -303,7 +316,7 @@ if __name__ == "__main__":
...
@@ -303,7 +316,7 @@ if __name__ == "__main__":
# print(MessageBase().str2Ascsii("uvwxyz"))
# print(MessageBase().str2Ascsii("uvwxyz"))
# print(MessageBase().int2hexStringByBytes(220400566542345564784802,20))
# print(MessageBase().int2hexStringByBytes(220400566542345564784802,20))
# print(MessageBase().str2Hex("a865h643gfdj64fd7432"))
# print(MessageBase().str2Hex("a865h643gfdj64fd7432"))
# print(MessageBase().hex2Str("
61383635683634336766646a3634666437343332
"))
# print(MessageBase().hex2Str("
d4c1423939383838
"))
# print(MessageBase().GBKString2Hex("KZP200_V201001"))
# print(MessageBase().GBKString2Hex("KZP200_V201001"))
# print(MessageBase().hex2GBKString("4b5a503230305f56323031303031"))
# print(MessageBase().hex2GBKString("4b5a503230305f56323031303031"))
# print(MessageBase().str2Hex("\xd3\xe5B23CX"))
# print(MessageBase().str2Hex("\xd3\xe5B23CX"))
...
@@ -312,8 +325,8 @@ if __name__ == "__main__":
...
@@ -312,8 +325,8 @@ if __name__ == "__main__":
# print(MessageBase().getCheckCode("8001000501314620111800000000000200"))
# print(MessageBase().getCheckCode("8001000501314620111800000000000200"))
# print(MessageBase().getMsgHeader())
# print(MessageBase().getMsgHeader())
# print(MessageBase().generateMsg())
# print(MessageBase().generateMsg())
#
print(MessageBase().GBKString2Hex("渝B23CX"))
print
(
MessageBase
()
.
GBKString2Hex
(
"渝B23CX"
))
# print(MessageBase().hex2GBKString("5c7864335c78653
54232334358"))
print
(
MessageBase
()
.
hex2GBKString
(
"d3e
54232334358"
))
# print(MessageBase().int2BCD(123456789012345,10))
# print(MessageBase().int2BCD(123456789012345,10))
# print(MessageBase().getRandomNum(3000,5000,[2,4,6,8,10,12],4))
# print(MessageBase().getRandomNum(3000,5000,[2,4,6,8,10,12],4))
# print(MessageBase().getRandomStr(10))
# print(MessageBase().getRandomStr(10))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment