Python语言调用Demo
<p><strong><em>Python调用说明</em></strong></p>
<p>必须是python 32位版本,因为微信是32位的</p>
<p>代码:</p>
<pre><code>#-*- coding: utf8 -*-
import binascii
from ctypes import *
from ctypes import wintypes
import win32gui
from win32con import *
import time
import pythoncom
import win32gui
import json
pythoncom.CoInitialize()
WxLoader = WinDLL(&quot;WxLoader.dll&quot;)
@WINFUNCTYPE(None, c_ulong)
def connect_callback(client_id):
#print(client_id)
print(&quot;connect&quot;)
@WINFUNCTYPE(None, c_ulong, c_char_p, c_int)
def recev_callback(client_id, json_data, n):
print(&quot;Received from client_id: %d, size: %d&quot; % (client_id, n))
print(json_data)
jsonObj = json.loads(json_data.decode('gbk').encode('utf8'))
if jsonObj['type'] == 11025:
time.sleep(5)
send_data = dict()
send_data[&quot;type&quot;] = 11036
send_data[&quot;data&quot;] = {&quot;to_wxid&quot;: &quot;filehelper&quot;, &quot;content&quot;: &quot;中文测试 from Python.&quot;}
print(json.dumps(send_data))
WxLoader.SendWeChatData(client_id,
c_char_p(json.dumps(send_data).decode('utf8').encode('gbk')))
#print(client_id)
#print(n)
@WINFUNCTYPE(None, c_ulong)
def close_callback(client_id):
#print(client_id)
print(&quot;close&quot;)
out = create_string_buffer(10)
WxLoader.GetUserWeChatVersion(out)
print(&quot;WeChatVersion is %s&quot; % out.value)
ret = WxLoader.InitWeChatSocket(connect_callback, recev_callback, close_callback)
WxLoader.InjectWeChat(c_char_p(&quot;WeChatHelper.dll&quot;))
while True:
time.sleep(0.5)
pass</code></pre>