|
@@ -0,0 +1,119 @@
|
|
|
|
|
+import socket
|
|
|
|
|
+import time
|
|
|
|
|
+import re
|
|
|
|
|
+
|
|
|
|
|
+def send_recv(sock, hex_str, name, wait=0.05):
|
|
|
|
|
+ data = bytes.fromhex(hex_str)
|
|
|
|
|
+ print(f"\n[{name}] 发送: {len(data)}字节")
|
|
|
|
|
+ sock.send(data)
|
|
|
|
|
+ time.sleep(wait)
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ resp = sock.recv(65536)
|
|
|
|
|
+ print(f"[{name}] 收到: {len(resp)}字节")
|
|
|
|
|
+ return resp
|
|
|
|
|
+ except socket.timeout:
|
|
|
|
|
+ print(f"[{name}] 超时")
|
|
|
|
|
+ return None
|
|
|
|
|
+
|
|
|
|
|
+def main():
|
|
|
|
|
+ HOST = "47.108.151.236"
|
|
|
|
|
+ PORT = 211
|
|
|
|
|
+
|
|
|
|
|
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
|
+ sock.settimeout(10)
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ sock.connect((HOST, PORT))
|
|
|
|
|
+ print("连接成功")
|
|
|
|
|
+
|
|
|
|
|
+ # UUID
|
|
|
|
|
+ uuid = "04da00005400000008000000260000007b00430034003500460044003300330043002d0037003900300046002d0034003400450041002d0042003300410044002d003400300030003600410044003500310036003800370037007d00"
|
|
|
|
|
+ send_recv(sock, uuid, "UUID")
|
|
|
|
|
+
|
|
|
|
|
+ # 会话ID
|
|
|
|
|
+ session = "03da000018000000030000000000000008000000040000006900640030003200"
|
|
|
|
|
+ send_recv(sock, session, "会话")
|
|
|
|
|
+
|
|
|
|
|
+ # 查询时间
|
|
|
|
|
+ time_q = "02da00005e0000000300000000000000030000002e01000003000000010000000b000000ffff030000000200000003000000000000000800000010000000730065006c0065006300740020006700650074006400610074006500280029000300000063000000"
|
|
|
|
|
+ send_recv(sock, time_q, "时间查询")
|
|
|
|
|
+ send_recv(sock, session, "心跳1")
|
|
|
|
|
+
|
|
|
|
|
+ # 表结构
|
|
|
|
|
+ struct_q = "02da0000740000000300000000000000030000002e01000003000000010000000b000000ffff03000000020000000300000000000000084000001b000000730065006c0065006300740020002a002000660072006f006d0020007a0062006b00200077006800650072006500200031003d0030000300000063000000"
|
|
|
|
|
+ send_recv(sock, struct_q, "表结构")
|
|
|
|
|
+ send_recv(sock, session, "心跳2")
|
|
|
|
|
+
|
|
|
|
|
+ # 1500查询
|
|
|
|
|
+ query1 = "02da0000520000000300000000000000030000002e01000003000000010000000b000000ffff03000000020000000300000000000000080000000b0000003200360030003600300039003000330037004c004100020000001500"
|
|
|
|
|
+ resp1 = send_recv(sock, query1, "查询1(1500)")
|
|
|
|
|
+
|
|
|
|
|
+ if resp1:
|
|
|
|
|
+ text1 = resp1[4:].decode('gbk', errors='replace')
|
|
|
|
|
+
|
|
|
|
|
+ print("\n" + "=" * 70)
|
|
|
|
|
+ print("提取的客户信息")
|
|
|
|
|
+ print("=" * 70)
|
|
|
|
|
+
|
|
|
|
|
+ # 姓名
|
|
|
|
|
+ name_match = re.search(r'片([\u4e00-\u9fff]{2,3})', text1)
|
|
|
|
|
+ if name_match:
|
|
|
|
|
+ print(f"\n姓名: {name_match.group(1)}")
|
|
|
|
|
+
|
|
|
|
|
+ # 电话
|
|
|
|
|
+ phone_match = re.search(r'1[3-9]\d{9}', text1)
|
|
|
|
|
+ if phone_match:
|
|
|
|
|
+ print(f"电话: {phone_match.group()}")
|
|
|
|
|
+
|
|
|
|
|
+ # 验光数据
|
|
|
|
|
+ degree_pattern = r'(-?\d+\.\d+)(-?\d+\.\d+)'
|
|
|
|
|
+ degrees = re.findall(degree_pattern, text1)
|
|
|
|
|
+ optometry = []
|
|
|
|
|
+ for sph, cyl in degrees:
|
|
|
|
|
+ if sph.startswith('-') or cyl.startswith('-'):
|
|
|
|
|
+ if len(optometry) < 2:
|
|
|
|
|
+ optometry.append({'球镜': sph, '柱镜': cyl})
|
|
|
|
|
+
|
|
|
|
|
+ if optometry:
|
|
|
|
|
+ print(f"\n验光数据:")
|
|
|
|
|
+ for i, d in enumerate(optometry, 1):
|
|
|
|
|
+ eye = "右眼" if i == 1 else "左眼"
|
|
|
|
|
+ print(f" {eye}: 球镜 {d['球镜']}, 柱镜 {d['柱镜']}")
|
|
|
|
|
+
|
|
|
|
|
+ # 消费明细 - 直接从原始文本提取
|
|
|
|
|
+ print(f"\n消费明细:")
|
|
|
|
|
+
|
|
|
|
|
+ # 查找所有包含"镜片"的行
|
|
|
|
|
+ lines = text1.split('\n')
|
|
|
|
|
+ detail_count = 0
|
|
|
|
|
+
|
|
|
|
|
+ for line in lines:
|
|
|
|
|
+ if '镜片' in line:
|
|
|
|
|
+ detail_count += 1
|
|
|
|
|
+ # 提取完整的行(保留原始内容,只过滤掉太短的)
|
|
|
|
|
+ if len(line) > 20:
|
|
|
|
|
+ print(f" {detail_count}. {line.strip()}")
|
|
|
|
|
+ elif '镜架' in line:
|
|
|
|
|
+ detail_count += 1
|
|
|
|
|
+ if len(line) > 10:
|
|
|
|
|
+ print(f" {detail_count}. {line.strip()}")
|
|
|
|
|
+
|
|
|
|
|
+ # 1800查询
|
|
|
|
|
+ send_recv(sock, session, "心跳3")
|
|
|
|
|
+
|
|
|
|
|
+ query2 = "02da0000520000000300000000000000030000002e01000003000000010000000b000000ffff03000000020000000300000000000000080000000b0000003200360030003600300039003000330037004c004100020000001800"
|
|
|
|
|
+ resp2 = send_recv(sock, query2, "查询2(1800)")
|
|
|
|
|
+
|
|
|
|
|
+ # 关闭
|
|
|
|
|
+ close_pkt = "05da0000080000000300000000000000"
|
|
|
|
|
+ send_recv(sock, close_pkt, "关闭")
|
|
|
|
|
+
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ print(f"错误: {e}")
|
|
|
|
|
+ finally:
|
|
|
|
|
+ sock.close()
|
|
|
|
|
+ print("\n连接已关闭")
|
|
|
|
|
+
|
|
|
|
|
+if __name__ == "__main__":
|
|
|
|
|
+ main()
|