提交 46f1c29b 编写于 作者: L ljc545w

优化停止服务接口

上级 bdee01c0
...@@ -174,15 +174,16 @@ DWORD StartRobotService() { ...@@ -174,15 +174,16 @@ DWORD StartRobotService() {
} }
DWORD StopRobotService() { DWORD StopRobotService() {
DWORD cpid = GetCurrentProcessId();
if (!hProcess) if (!hProcess)
return 1; return cpid;
DWORD wxPid = GetWeChatPid(); DWORD wxPid = GetWeChatPid();
CheckFriendStatusFinish(); CheckFriendStatusFinish();
StopReceiveMessage(); StopReceiveMessage();
RemoveDll(wxPid); RemoveDll(wxPid);
ZeroMemory((wchar_t*)SelfInfoString.c_str(), SelfInfoString.length() * 2 + 2); ZeroMemory((wchar_t*)SelfInfoString.c_str(), SelfInfoString.length() * 2 + 2);
CloseHandle(hProcess); CloseHandle(hProcess);
return 0; return cpid;
} }
wstring GetComWorkPath() { wstring GetComWorkPath() {
......
...@@ -64,19 +64,16 @@ class WeChatRobot(): ...@@ -64,19 +64,16 @@ class WeChatRobot():
self.myinfo = myinfo self.myinfo = myinfo
return self.myinfo return self.myinfo
# 这个可以再更新一下,CStopRobotService返回COM组件的pid
def StopService(self): def StopService(self):
import psutil import psutil
self.StopReceiveMessage() self.StopReceiveMessage()
status = self.robot.CStopRobotService() cpid = self.robot.CStopRobotService()
pids = psutil.pids() try:
for pid in pids: cprocess = psutil.Process(cpid)
p = psutil.Process(pid) cprocess.kill()
process_name = p.name() except psutil.NoSuchProcess:
if process_name == 'CWeChatRobot.exe': pass
p.kill() return cpid
break
return status
def GetAddressBook(self): def GetAddressBook(self):
try: try:
...@@ -218,17 +215,19 @@ def ReceiveMessageCallBack(robot,message): ...@@ -218,17 +215,19 @@ def ReceiveMessageCallBack(robot,message):
sender = wxSender['wxNickName'] if wxSender['wxNickName'] != 'null' else message['sender'] sender = wxSender['wxNickName'] if wxSender['wxNickName'] != 'null' else message['sender']
if '@chatroom' in message['sender']: if '@chatroom' in message['sender']:
wxUser = robot.GetWxUserInfo(message['wxid']) wxUser = robot.GetWxUserInfo(message['wxid'])
print("来自 {} {}".format(sender,wxUser['wxNickName'])) print("来自 {} {},type {}".format(sender,wxUser['wxNickName',message['type']]))
else: else:
print("来自 {}".format(sender)) print("来自 {},type {}".format(sender,message['type']))
if message['type'] == 1: if message['type'] == 1:
print(message['message']) print(message['message'])
elif message['type'] == 3: elif message['type'] == 3:
print(message['message'])
print(message['filepath']) print(message['filepath'])
elif message['type'] == 49: elif message['type'] == 49:
print(message['message']) print(message['message'])
if not message['filepath']: print(message['filepath'])
else: else:
print(message['type'],message['message']) print(message['message'])
def test_SendText(): def test_SendText():
import os import os
...@@ -284,4 +283,4 @@ def test_ReceiveMessage(): ...@@ -284,4 +283,4 @@ def test_ReceiveMessage():
wx.StopService() wx.StopService()
if __name__ == '__main__': if __name__ == '__main__':
test_ReceiveMessage() test_ReceiveMessage()
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册