版权声明:转载请注明出处https://blog.csdn.net/weixin_42116406 https://blog.csdn.net/weixin_42116406/article/details/84339330
研究了我两天,主要是对这个dll的数据类型不了解 不知道如何转换,所以现在记下笔记。下面是调取win32接口工具的dll文件进行对接口返回报文进行解码并获取token值。。。。。。
#!user/bin/python2.7
#coding:utf-8
import re
import ctypes
def get_token(respons,key):
# 数据
Date = respons # 返回的报文
Key = key # 解密秘钥
Out_Text = '' # 输出结果
ErrorMsg = '' # 错误信息
# 定义参数类型
Out_Text = ctypes.c_wchar_p()
ErrorMsg = ctypes.c_wchar_p()
# 调用dll文件
dll = ctypes.windll.LoadLibrary('D:/DECODE.dll')
r = dll.Decode_Text(Date, Key, ctypes.byref(Out_Text), ctypes.byref(ErrorMsg)) # Decode_Text为DLL中的方法
# 取值
Date_text = Out_Text.value
ErrorMsg_text = ErrorMsg.value
try:
print(Date_text)
except:
print(ErrorMsg_text)
# 提取返回信息中的token
#token = re.findall(r'"token":"(.+?)","',Date_text)
token = Date_text[492:523]
a = token[0]
print('获取到的token值为:')
print(a)
return token
if __name__ == "__main__":
a = ' ' # 返回报文
b = '<L;*3Md7'# 秘钥
get_token(a,b)
接下来是对URL返回的信息做提取 。。。。。。
#!user/bin/python2.7
#coding:utf-8
import re
import urllib2
# 向地址发送请求
def get_date(url):
try:
data = urllib2.urlopen(url).read()
return data
except Exception,e:
print e
# 将返回信息写入文件
def join_File():
file = open("D:/date.txt","w")
file.write(get_date(url))
file.close()
def get_text():
# 读取返回文件
file = open("D:/date.txt",'r')
list = file.read()
# 提取返回信息中的token
text_list = re.findall(r'&token=(.+?)&nsrsbh',list)
text = text_list[0]
print('获取到的token列表为:')
print(text_list)
print
print('token值相同返回第一个值:')
print(text)
if __name__ == "__main__":
url = 'http://gdcsgj.test.jchl.com/web-bsgj/m32&provinceID=440000&menuId=bszx&sfdj=jcgjdlb'
get_date(url)
join_File()
get_text()