准备好SDK中的以下DLL:Sdtapi.dll,SavePhoto.dll,Dewlt.dll,后面两个dll用于解码图片
import ctypes
fields = ['name', 'gender', 'folk', 'birthday', 'address', 'code', 'agency', 'expire_start', 'expire_end']
dll_path = 'Sdtapi.dll'
sdtapi = ctypes.WinDLL(dll_path)
ret1 = sdtapi.InitComm(1001)
if ret1 != 1:print('initComm Error')
ret2 = sdtapi.Authenticate()
if ret2 != 1:print('getCard Error')
msg = ctypes.create_string_buffer(b'\x00'*256)
ret3 = sdtapi.ReadBaseMsg(msg, None)
ret4 = dict(zip(fields, list(filter(None, msg.raw.decode('gbk').strip().split('\x00')))))
print(ret4)
sdtapi.CloseComm()
调用ReadBaseMsg方法后,会在本地目录生成photo.bmp头像文件。