add:初始化工程

This commit is contained in:
drygrass
2025-10-18 21:32:31 +08:00
parent f55b636faa
commit e1b57847f9
48 changed files with 67186 additions and 0 deletions

0
t2sdk/__init__.py Normal file
View File

0
t2sdk/cest.py Normal file
View File

1
t2sdk/client_license.dat Normal file
View File

@@ -0,0 +1 @@
yNIOaDT0jJZ2UXTBD45DExCndFsgThyb//ZDl2L9mkd603SwXFuRgwFgFg==

BIN
t2sdk/license.dat Normal file

Binary file not shown.

69
t2sdk/pyCallBack.py Normal file
View File

@@ -0,0 +1,69 @@
# coding=utf-8
from importlib import reload # Python 3 推荐方式
import traceback
import sys
reload(sys)
sys.path.append(r"F:\sescode_review\toolset\hstools\py-hstools\cest")
import py_t2sdk
def PrintUnpack(lpUnpack):
iDataSetCount = lpUnpack.GetDatasetCount()
index = 0
print('count '+str(iDataSetCount))
while index < iDataSetCount :
lpUnpack.SetCurrentDatasetByIndex(index)
iRowCount = lpUnpack.GetRowCount()
RowIndex = 0
while RowIndex < iRowCount:
iColCount = lpUnpack.GetColCount()
iColIndex = 0
while iColIndex < iColCount:
ColType = lpUnpack.GetColType(iColIndex)
if ColType == 'S':
print(lpUnpack.GetColName(iColIndex) + ':' + lpUnpack.GetStrByIndex(iColIndex))
elif ColType == 'I':
print(lpUnpack.GetColName(iColIndex) + ':' + str(lpUnpack.GetIntByIndex(iColIndex)))
elif ColType == 'C':
print(lpUnpack.GetColName(iColIndex) + ':' + lpUnpack.GetCharByIndex(iColIndex))
elif ((ColType == 'D') | (ColType == 'F')):
print(lpUnpack.GetColName(iColIndex) + ':' + str(lpUnpack.GetDoubleByIndex(iColIndex)))
iColIndex += 1
lpUnpack.Next()
RowIndex += 1
index += 1
class pyCallBack:
def __init__(self):
print('init')
def OnRegister(self):
print('OnRegister')
def OnClose(self):
print('OnClose')
def OnReceivedBiz(self):
print('OnReceivedBiz')
def OnReceivedBizEx(self):
print('OnReceivedBizEx')
def OnReceivedBizMsg(self,hSend,sBuff,iLenght):
try:
print('OnReceivedBizMsg')
lpBizMsg = py_t2sdk.pyIBizMessage()
iRet = lpBizMsg.SetBuff(sBuff,iLenght)
iRet = lpBizMsg.GetErrorNo()
print(iRet)
if iRet == 0:
buf,len = lpBizMsg.GetContent()
LoginUnPack = py_t2sdk.pyIF2UnPacker()
LoginUnPack.Open(buf,len)
PrintUnpack(LoginUnPack)
LoginUnPack.Release()
else:
print(iRet)
print(lpBizMsg.GetErrorInfo())
lpBizMsg.Release()
except:
traceback.print_exc()
finally:
print('pyCallBack finally')

BIN
t2sdk/t2sdk.dll Normal file

Binary file not shown.

30
t2sdk/t2sdk.ini Normal file
View File

@@ -0,0 +1,30 @@
[t2sdk]
;<3B><><EFBFBD>֤<EFBFBD>ļ<EFBFBD>
license_file=client_license.dat
;servers=192.168.39.82:9434
servers=10.20.163.102:14666
login_name=
init_recv_buf_size=102400
init_send_buf_size=102400
send_queue_size=100000
errormsg=errormsg.ini
sendcount=10
senddir=/home/hundsun/scanfile/test/
;lang=1033
[proxy]
proxy_type=
ip=127.0.0.1
port=
user_name=guest
password=888888
[safe]
safe_level=none
client_id=123456
comm_pwd=888888
cert_file=xxx.pem
cert_pwd=xxxxxxxx
;safe_level=ssl
;client_id=123456
;comm_pwd=888888
;cert_file=ufxclient.pfx
;cert_pwd=ufxclient

BIN
t2sdk/t2sdk.lib Normal file

Binary file not shown.

200
t2sdk/t2sdk_demo_syn.py Normal file
View File

@@ -0,0 +1,200 @@
# coding=utf-8
from importlib import reload # Python 3 推荐方式
from datetime import datetime
from array import array
import time
import threading
import traceback
import sys
reload(sys)
# 添加.pyd文件所在的目录路径可以是绝对路径或相对路径
sys.path.append(r"F:\sescode_review\toolset\hstools\py-hstools\t2sdk")
import py_t2sdk
# 打包
def GetT2Pack(mdbsql):
pLoginPack = py_t2sdk.pyIF2Packer()
pLoginPack.BeginPack()
if mdbsql.endswith('.sql'):
with open('.\sql\\' + mdbsql, "r", encoding="utf-8") as file:
content = file.read() # 读取整个文件内容到字符串
# print(content)
# 获取当天日期格式YYYYMMDD
today = datetime.now().strftime("%Y%m%d") # 例如20250903
# 替换占位符
sql_final = content.format(init_date=today) # 替换 {init_date}
else:
sql_final = mdbsql
print('len:', len(sql_final))
# 添加包体
pLoginPack.AddField('sql', 'S', len(sql_final)*1.5, 0)
if 'show tables' not in sql_final:
pLoginPack.AddField('general', 'S')
pLoginPack.AddStr(sql_final)
if 'show' not in sql_final:
pLoginPack.AddStr(" ")
pLoginPack.EndPack()
return pLoginPack
def GetT2Msg(lpPack, t2FunctionNo, t2SystemNo):
pyMsg = py_t2sdk.pyIBizMessage()
pyMsg.SetFunction(t2FunctionNo)
pyMsg.SetSystemNo(t2SystemNo)
pyMsg.SetPacketType(0)
pyMsg.SetContent(lpPack.GetPackBuf(),lpPack.GetPackLen())
return pyMsg
def PrintUnpack(lpUnpack):
iDataSetCount = lpUnpack.GetDatasetCount()
index = 0
print('count ', iDataSetCount)
print('开始解包')
while index < iDataSetCount:
lpUnpack.SetCurrentDatasetByIndex(index)
iRowCount = lpUnpack.GetRowCount()
print('iRowCount:', iRowCount)
RowIndex = 0
while RowIndex < iRowCount:
iColCount = lpUnpack.GetColCount()
print('iColCount', iColCount)
iColIndex = 0
while iColIndex < iColCount:
ColType = lpUnpack.GetColType(iColIndex)
print('coltype', ColType)
if ColType == 'S':
print(lpUnpack.GetColName(iColIndex) + ':' + lpUnpack.GetStrByIndex(iColIndex))
elif ColType == 'I':
print(lpUnpack.GetColName(iColIndex) + ':' + str(lpUnpack.GetIntByIndex(iColIndex)))
elif ColType == 'C':
print(lpUnpack.GetColName(iColIndex) + ':' + lpUnpack.GetCharByIndex(iColIndex))
elif ((ColType == 'D') | (ColType == 'F')):
print(lpUnpack.GetColName(iColIndex) + ':' + str(lpUnpack.GetDoubleByIndex(iColIndex)))
iColIndex += 1
lpUnpack.Next()
RowIndex += 1
index += 1
print('结束解包')
# 将返回结果集转换字典数组
def UnpackToMapArr(lpUnpack):
iDataSetCount = lpUnpack.GetDatasetCount()
index = 0
print('count ', iDataSetCount)
print('开始解包')
result = []
while index < iDataSetCount:
lpUnpack.SetCurrentDatasetByIndex(index)
iRowCount = lpUnpack.GetRowCount()
print('iRowCount:', iRowCount)
RowIndex = 0
while RowIndex < iRowCount:
iColCount = lpUnpack.GetColCount()
# print('iColCount', iColCount)
iColIndex = 0
arr = {}
while iColIndex < iColCount:
ColType = lpUnpack.GetColType(iColIndex)
# print('coltype', ColType)
if ColType == 'S':
# print(lpUnpack.GetColName(iColIndex) + ':' + lpUnpack.GetStrByIndex(iColIndex))
arr[lpUnpack.GetColName(iColIndex)] = lpUnpack.GetStrByIndex(iColIndex)
elif ColType == 'I':
# print(lpUnpack.GetColName(iColIndex) + ':' + str(lpUnpack.GetIntByIndex(iColIndex)))
arr[lpUnpack.GetColName(iColIndex)] = str(lpUnpack.GetIntByIndex(iColIndex))
elif ColType == 'C':
# print(lpUnpack.GetColName(iColIndex) + ':' + lpUnpack.GetCharByIndex(iColIndex))
arr[lpUnpack.GetColName(iColIndex)] = lpUnpack.GetCharByIndex(iColIndex)
elif ((ColType == 'D') | (ColType == 'F')):
# print(lpUnpack.GetColName(iColIndex) + ':' + str(lpUnpack.GetDoubleByIndex(iColIndex)))
arr[lpUnpack.GetColName(iColIndex)] = str(lpUnpack.GetDoubleByIndex(iColIndex))
iColIndex += 1
result.append(arr)
lpUnpack.Next()
RowIndex += 1
index += 1
# print('结束解包')
return result
def execMdbSql(t2Host,t2Port,mdbNodeName,mdbSql):
py_t2sdk.PyT2sdkInitialize()
# 初始化配置
config = py_t2sdk.pyCConfigInterface()
config.Load('t2sdk.ini')
# 重新设置t2地址
config.SetString('t2sdk','servers', t2Host + ":" + t2Port)
connect = py_t2sdk.pyConnectionInterface(config)
pCallBack = py_t2sdk.pyCallbackInterface('pyCallBack', 'pyCallBack')
pCallBack.InitInstance()
ret = connect.Create2BizMsg(pCallBack)
result = []
if 'cbp' in mdbNodeName:
t2FunctionNo = 508901
else:
t2FunctionNo = 508902
last_two = mdbNodeName[-2:] # 提取最后两位字符
t2SystemNo = int(last_two) # 转换为整数
if ret != 0:
print('creat faild!!')
exit()
ret = connect.Connect(3000)
if ret != 0:
print('connect faild:')
ErrMsg = connect.GetErrorMsg(ret)
print(ErrMsg)
exit()
print('YES')
try:
# 设置pack包体
pLoginPack = GetT2Pack(mdbSql)
# 设置功能号,系统号等
pMsg = GetT2Msg(pLoginPack, t2FunctionNo, t2SystemNo)
pLoginPack.FreeMem()
pLoginPack.Release()
ret = connect.SendBizMsg(pMsg)
time.sleep(1)
pMsg.Release()
iRetAns, pyMsgAns = connect.RecvBizMsg(ret, 6000)
if iRetAns == 0:
if pyMsgAns.GetErrorNo() == 0:
buf, len = pyMsgAns.GetContent()
LoginUnPack = py_t2sdk.pyIF2UnPacker()
LoginUnPack.Open(buf, len)
# PrintUnpack(LoginUnPack)
result = UnpackToMapArr(LoginUnPack)
LoginUnPack.Release()
else:
# print(pyMsgAns.GetErrorNo())
# print(pyMsgAns.GetErrorInfo())
res = {}
res['error_no'] = pyMsgAns.GetErrorNo()
res['error_info'] = mdbNodeName + ':' + pyMsgAns.GetErrorInfo()
result.append(res)
else:
# print(iRetAns)
# print(connect.GetErrorMsg(iRetAns))
res = {}
res['error_no'] = iRetAns
res['error_info'] = mdbNodeName + ':' + connect.GetErrorMsg(iRetAns)
result.append(res)
pyMsgAns.Release()
except:
traceback.print_exc()
finally:
print('finally')
return result
py_t2sdk.PyT2sdkFinalize()
if __name__ == '__main__':
# py_t2sdk.PyT2sdkInitialize()
result = execMdbSql('10.20.163.101', '14007','usesbid92', "init_date.sql")
print(result)
# raw_input("Press Enter")
# py_t2sdk.PyT2sdkFinalize()