Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
m0_71398851
ComWeChatRobot
提交
98fcc768
C
ComWeChatRobot
项目概览
m0_71398851
/
ComWeChatRobot
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ComWeChatRobot
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
98fcc768
编写于
8月 18, 2022
作者:
A
amchii
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
微信消息添加根据唯一id去重功能
上级
f494d14a
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
3747 addition
and
3809 deletion
+3747
-3809
CWeChatRobot/RobotEvent.cpp
CWeChatRobot/RobotEvent.cpp
+9
-6
CWeChatRobot/RobotEvent.h
CWeChatRobot/RobotEvent.h
+31
-37
CWeChatRobot/WeChatRobotCOM.idl
CWeChatRobot/WeChatRobotCOM.idl
+1
-1
CWeChatRobot/WeChatRobotCOM.vcxproj
CWeChatRobot/WeChatRobotCOM.vcxproj
+1
-0
CWeChatRobot/WeChatRobotCOM.vcxproj.filters
CWeChatRobot/WeChatRobotCOM.vcxproj.filters
+3
-0
CWeChatRobot/WeChatRobotCOM.vcxproj.user
CWeChatRobot/WeChatRobotCOM.vcxproj.user
+3
-0
CWeChatRobot/WeChatRobotCOM_i.h
CWeChatRobot/WeChatRobotCOM_i.h
+566
-594
CWeChatRobot/WeChatRobotCOM_p.c
CWeChatRobot/WeChatRobotCOM_p.c
+3082
-3127
CWeChatRobot/_IRobotEventEvents_CP.h
CWeChatRobot/_IRobotEventEvents_CP.h
+15
-10
DWeChatRobot/ReceiveMessage.cpp
DWeChatRobot/ReceiveMessage.cpp
+15
-15
DWeChatRobot/comclient.cpp
DWeChatRobot/comclient.cpp
+18
-16
DWeChatRobot/comclient.h
DWeChatRobot/comclient.h
+3
-3
Release/CWeChatRobot.exe
Release/CWeChatRobot.exe
+0
-0
Release/DWeChatRobot.dll
Release/DWeChatRobot.dll
+0
-0
未找到文件。
CWeChatRobot/RobotEvent.cpp
浏览文件 @
98fcc768
...
...
@@ -8,17 +8,20 @@
// CRobotEvent
STDMETHODIMP
CRobotEvent
::
CPostMessage
(
DWORD
pid
,
int
msgtype
,
VARIANT
*
msg
,
int
*
__result
)
STDMETHODIMP
CRobotEvent
::
CPostMessage
(
DWORD
pid
,
int
msgtype
,
unsigned
long
long
msgid
,
VARIANT
*
msg
,
int
*
__result
)
{
// TODO: 在此处添加实现代码
// 将收到的消息广播给所有用户
switch
(
msgtype
)
{
case
WX_MESSAGE
:
{
Fire_OnGetMessageEvent
(
pid
,
msg
);
switch
(
msgtype
)
{
case
WX_MESSAGE
:
{
Fire_OnGetMessageEvent
(
pid
,
msgid
,
msg
);
break
;
}
case
WX_LOG_MESSAGE
:{
case
WX_LOG_MESSAGE
:
{
break
;
}
default:
...
...
@@ -32,7 +35,7 @@ STDMETHODIMP CRobotEvent::CPostMessage(DWORD pid,int msgtype,VARIANT* msg, int*
* \param pid 微信PID
* \param cookie Cookie
*/
STDMETHODIMP
CRobotEvent
::
CRegisterWxPidWithCookie
(
DWORD
pid
,
DWORD
cookie
,
int
*
__result
)
STDMETHODIMP
CRobotEvent
::
CRegisterWxPidWithCookie
(
DWORD
pid
,
DWORD
cookie
,
int
*
__result
)
{
WxPidToEventCookie
[
pid
].
insert
(
cookie
);
*
__result
=
0
;
...
...
CWeChatRobot/RobotEvent.h
浏览文件 @
98fcc768
// RobotEvent.h: CRobotEvent 的声明
#pragma once
#include "resource.h" // 主符号
#include "resource.h" // 主符号
#include "WeChatRobotCOM_i.h"
#include "_IRobotEventEvents_CP.h"
using
namespace
ATL
;
// CRobotEvent
class
ATL_NO_VTABLE
CRobotEvent
:
public
CComObjectRootEx
<
CComMultiThreadModel
>
,
public
CComCoClass
<
CRobotEvent
,
&
CLSID_RobotEvent
>
,
public
IConnectionPointContainerImpl
<
CRobotEvent
>
,
public
CProxy_IRobotEventEvents
<
CRobotEvent
>
,
public
IDispatchImpl
<
IRobotEvent
,
&
IID_IRobotEvent
,
&
LIBID_WeChatRobotCOMLib
,
/*wMajor =*/
1
,
/*wMinor =*/
0
>
class
ATL_NO_VTABLE
CRobotEvent
:
public
CComObjectRootEx
<
CComMultiThreadModel
>
,
public
CComCoClass
<
CRobotEvent
,
&
CLSID_RobotEvent
>
,
public
IConnectionPointContainerImpl
<
CRobotEvent
>
,
public
CProxy_IRobotEventEvents
<
CRobotEvent
>
,
public
IDispatchImpl
<
IRobotEvent
,
&
IID_IRobotEvent
,
&
LIBID_WeChatRobotCOMLib
,
/*wMajor =*/
1
,
/*wMinor =*/
0
>
{
public:
CRobotEvent
()
{
}
DECLARE_REGISTRY_RESOURCEID
(
107
)
DECLARE_CLASSFACTORY_SINGLETON
(
CRobotEvent
)
CRobotEvent
()
{
}
BEGIN_COM_MAP
(
CRobotEvent
)
COM_INTERFACE_ENTRY
(
IRobotEvent
)
COM_INTERFACE_ENTRY
(
IDispatch
)
COM_INTERFACE_ENTRY
(
IConnectionPointContainer
)
END_COM_MAP
()
DECLARE_REGISTRY_RESOURCEID
(
107
)
DECLARE_CLASSFACTORY_SINGLETON
(
CRobotEvent
)
BEGIN_CONNECTION_POINT_MAP
(
CRobotEvent
)
CONNECTION_POINT_ENTRY
(
__uuidof
(
_IRobotEventEvents
))
END_CONNECTION_POINT_MAP
()
BEGIN_COM_MAP
(
CRobotEvent
)
COM_INTERFACE_ENTRY
(
IRobotEvent
)
COM_INTERFACE_ENTRY
(
IDispatch
)
COM_INTERFACE_ENTRY
(
IConnectionPointContainer
)
END_COM_MAP
()
BEGIN_CONNECTION_POINT_MAP
(
CRobotEvent
)
CONNECTION_POINT_ENTRY
(
__uuidof
(
_IRobotEventEvents
))
END_CONNECTION_POINT_MAP
()
DECLARE_PROTECT_FINAL_CONSTRUCT
()
DECLARE_PROTECT_FINAL_CONSTRUCT
()
HRESULT
FinalConstruct
()
{
return
S_OK
;
}
HRESULT
FinalConstruct
()
{
return
S_OK
;
}
void
FinalRelease
()
{
}
void
FinalRelease
()
{
}
public:
STDMETHOD
(
CPostMessage
)(
DWORD
pid
,
int
msgtype
,
VARIANT
*
msg
,
int
*
__result
);
STDMETHOD
(
CRegisterWxPidWithCookie
)(
DWORD
pid
,
DWORD
cookie
,
int
*
__result
);
STDMETHOD
(
CPostMessage
)
(
DWORD
pid
,
int
msgtype
,
unsigned
long
long
msgid
,
VARIANT
*
msg
,
int
*
__result
);
STDMETHOD
(
CRegisterWxPidWithCookie
)
(
DWORD
pid
,
DWORD
cookie
,
int
*
__result
);
};
OBJECT_ENTRY_AUTO
(
__uuidof
(
RobotEvent
),
CRobotEvent
)
CWeChatRobot/WeChatRobotCOM.idl
浏览文件 @
98fcc768
...
...
@@ -68,7 +68,7 @@ interface IWeChatRobot : IDispatch
]
interface
IRobotEvent
:
IDispatch
{
[
id
(
1
),
helpstring
(
"用于微信主动推送消息"
)
]
HRESULT
CPostMessage
(
[
in
]
DWORD
pid
,
[
in
]
int
msgtype
,
[
in
]
VARIANT
*
msg
,
[
out
,
retval
]
int
*
__result
)
;
[
id
(
1
),
helpstring
(
"用于微信主动推送消息"
)
]
HRESULT
CPostMessage
(
[
in
]
DWORD
pid
,
[
in
]
int
msgtype
,
[
in
]
unsigned
long
long
msgid
,
[
in
]
VARIANT
*
msg
,
[
out
,
retval
]
int
*
__result
)
;
[
id
(
2
),
helpstring
(
"用于客户端通过微信PID注册消息接收服务"
)
]
HRESULT
CRegisterWxPidWithCookie
(
[
in
]
DWORD
pid
,
[
in
]
DWORD
cookie
,
[
out
,
retval
]
int
*
__result
)
;
}
;
[
...
...
CWeChatRobot/WeChatRobotCOM.vcxproj
浏览文件 @
98fcc768
...
...
@@ -245,6 +245,7 @@
<ClInclude
Include=
"targetver.h"
/>
<ClInclude
Include=
"SearchContact.h"
/>
<ClInclude
Include=
"templatefunc.h"
/>
<ClInclude
Include=
"utils.h"
/>
<ClInclude
Include=
"VerifyFriendApply.h"
/>
<ClInclude
Include=
"WeChatRobot.h"
/>
<ClInclude
Include=
"WeChatRobotCOM_i.h"
/>
...
...
CWeChatRobot/WeChatRobotCOM.vcxproj.filters
浏览文件 @
98fcc768
...
...
@@ -238,6 +238,9 @@
<ClInclude
Include=
"templatefunc.h"
>
<Filter>
template
</Filter>
</ClInclude>
<ClInclude
Include=
"utils.h"
>
<Filter>
头文件
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"WeChatRobotCOM.cpp"
>
...
...
CWeChatRobot/WeChatRobotCOM.vcxproj.user
浏览文件 @
98fcc768
...
...
@@ -5,4 +5,7 @@
<DebuggerFlavor>
WindowsLocalDebugger
</DebuggerFlavor>
<LocalDebuggerWorkingDirectory>
D:\VS2019C++\MyWeChatRobot\Debug\
</LocalDebuggerWorkingDirectory>
</PropertyGroup>
<PropertyGroup>
<ShowAllFiles>
false
</ShowAllFiles>
</PropertyGroup>
</Project>
\ No newline at end of file
CWeChatRobot/WeChatRobotCOM_i.h
浏览文件 @
98fcc768
此差异已折叠。
点击以展开。
CWeChatRobot/WeChatRobotCOM_p.c
浏览文件 @
98fcc768
此差异已折叠。
点击以展开。
CWeChatRobot/_IRobotEventEvents_CP.h
浏览文件 @
98fcc768
#
pragma
once
#include <map>
#include <set>
#include "utils.h"
/**
* 微信PID与客户端事件ConnectionPoint的cookie的映射,客户端使用自己关心的微信PID和cookie进行注册,
...
...
@@ -8,33 +9,37 @@
*/
map
<
DWORD
,
set
<
DWORD
>>
WxPidToEventCookie
;
template
<
class
T
>
class
CProxy_IRobotEventEvents
:
public
ATL
::
IConnectionPointImpl
<
T
,
&
__uuidof
(
_IRobotEventEvents
)
>
template
<
class
T
>
class
CProxy_IRobotEventEvents
:
public
ATL
::
IConnectionPointImpl
<
T
,
&
__uuidof
(
_IRobotEventEvents
)
>
{
public:
HRESULT
Fire_OnGetMessageEvent
(
DWORD
pid
,
VARIANT
*
msg
)
HRESULT
Fire_OnGetMessageEvent
(
DWORD
pid
,
unsigned
long
long
msgid
,
VARIANT
*
msg
)
{
HRESULT
hr
=
S_OK
;
T
*
pThis
=
static_cast
<
T
*>
(
this
);
if
(
WxPidToEventCookie
.
count
(
pid
)
==
0
)
static
ExpireSet
es
(
2000
);
if
(
!
es
.
CheckIfDuplicatedAndAdd
(
msgid
))
{
return
hr
;
}
T
*
pThis
=
static_cast
<
T
*>
(
this
);
if
(
WxPidToEventCookie
.
count
(
pid
)
==
0
)
{
return
hr
;
}
const
set
<
DWORD
>
cookies
=
WxPidToEventCookie
[
pid
];
for
(
DWORD
cookie
:
cookies
)
for
(
DWORD
cookie
:
cookies
)
{
pThis
->
Lock
();
ATL
::
CComPtr
<
IUnknown
>
punkConnection
=
this
->
m_vec
.
GetUnknown
(
cookie
);
ATL
::
CComPtr
<
IUnknown
>
punkConnection
=
this
->
m_vec
.
GetUnknown
(
cookie
);
pThis
->
Unlock
();
if
(
punkConnection
)
{
IDispatch
*
pConnection
=
static_cast
<
IDispatch
*>
(
punkConnection
.
p
);
IDispatch
*
pConnection
=
static_cast
<
IDispatch
*>
(
punkConnection
.
p
);
if
(
pConnection
)
{
ATL
::
CComVariant
varResult
;
DISPPARAMS
params
=
{
msg
,
nullptr
,
1
,
0
};
DISPPARAMS
params
=
{
msg
,
nullptr
,
1
,
0
};
hr
=
pConnection
->
Invoke
(
1
,
IID_NULL
,
LOCALE_USER_DEFAULT
,
DISPATCH_METHOD
,
&
params
,
&
varResult
,
nullptr
,
nullptr
);
}
else
...
...
DWeChatRobot/ReceiveMessage.cpp
浏览文件 @
98fcc768
...
...
@@ -200,7 +200,7 @@ static void dealMessage(DWORD messageAddr)
VARIANT
vsaValue
;
vsaValue
.
vt
=
VT_ARRAY
|
VT_VARIANT
;
V_ARRAY
(
&
vsaValue
)
=
psaValue
;
PostComMessage
(
message
->
pid
,
WX_MESSAGE
,
&
vsaValue
);
PostComMessage
(
message
->
pid
,
WX_MESSAGE
,
message
->
msgid
,
&
vsaValue
);
#endif
HANDLE
hThread
=
CreateThread
(
NULL
,
0
,
(
LPTHREAD_START_ROUTINE
)
SendSocketMessage
,
message
,
NULL
,
0
);
if
(
hThread
)
...
...
@@ -210,10 +210,10 @@ static void dealMessage(DWORD messageAddr)
}
/*
* 消息处理函数,根据消息缓冲区组装结构并存入容器
* messageAddr:保存消息的缓冲区地址
* return:void
*/
* 消息处理函数,根据消息缓冲区组装结构并存入容器
* messageAddr:保存消息的缓冲区地址
* return:void
*/
VOID
ReceiveMessage
(
DWORD
messagesAddr
)
{
// 此处用于区别是发送的还是接收的消息
...
...
@@ -225,8 +225,8 @@ VOID ReceiveMessage(DWORD messagesAddr)
}
/*
* HOOK的具体实现,接收到消息后调用处理函数
*/
* HOOK的具体实现,接收到消息后调用处理函数
*/
_declspec
(
naked
)
void
dealReceiveMessage
()
{
__asm
{
...
...
@@ -244,8 +244,8 @@ _declspec(naked) void dealReceiveMessage()
}
/*
* HOOK的具体实现,发送消息后调用处理函数
*/
* HOOK的具体实现,发送消息后调用处理函数
*/
_declspec
(
naked
)
void
dealSendMessage
()
{
__asm
{
...
...
@@ -262,9 +262,9 @@ _declspec(naked) void dealSendMessage()
}
/*
* 开始接收消息HOOK
* return:void
*/
* 开始接收消息HOOK
* return:void
*/
VOID
HookReceiveMessage
(
int
port
)
{
SRVPORT
=
port
;
...
...
@@ -283,9 +283,9 @@ VOID HookReceiveMessage(int port)
}
/*
* 停止接收消息HOOK
* return:void
*/
* 停止接收消息HOOK
* return:void
*/
VOID
UnHookReceiveMessage
()
{
SRVPORT
=
0
;
...
...
DWeChatRobot/comclient.cpp
浏览文件 @
98fcc768
...
...
@@ -10,21 +10,20 @@
// CComModule m_commodule;
class
CSink
:
public
CComObjectRoot
,
public
_IRobotEventEvents
class
CSink
:
public
CComObjectRoot
,
public
_IRobotEventEvents
{
BEGIN_COM_MAP
(
CSink
)
COM_INTERFACE_ENTRY
(
IDispatch
)
COM_INTERFACE_ENTRY
(
_IRobotEventEvents
)
COM_INTERFACE_ENTRY
(
IDispatch
)
COM_INTERFACE_ENTRY
(
_IRobotEventEvents
)
END_COM_MAP
()
public:
virtual
~
CSink
()
{}
STDMETHODIMP
GetTypeInfoCount
(
UINT
*
pctinfo
)
{
return
E_NOTIMPL
;
}
STDMETHODIMP
GetTypeInfo
(
UINT
iTInfo
,
LCID
lcid
,
ITypeInfo
**
ppTInfo
)
{
return
E_NOTIMPL
;
}
STDMETHODIMP
GetIDsOfNames
(
REFIID
riid
,
LPOLESTR
*
rgszNames
,
UINT
cNames
,
LCID
lcid
,
DISPID
*
rgDispId
)
{
return
E_NOTIMPL
;
}
STDMETHODIMP
Invoke
(
DISPID
dispIdMember
,
REFIID
riid
,
LCID
lcid
,
WORD
wFlags
,
DISPPARAMS
*
pDispParams
,
VARIANT
*
pVarResult
,
EXCEPINFO
*
pExcepInfo
,
UINT
*
puArgErr
)
STDMETHODIMP
GetTypeInfoCount
(
UINT
*
pctinfo
)
{
return
E_NOTIMPL
;
}
STDMETHODIMP
GetTypeInfo
(
UINT
iTInfo
,
LCID
lcid
,
ITypeInfo
**
ppTInfo
)
{
return
E_NOTIMPL
;
}
STDMETHODIMP
GetIDsOfNames
(
REFIID
riid
,
LPOLESTR
*
rgszNames
,
UINT
cNames
,
LCID
lcid
,
DISPID
*
rgDispId
)
{
return
E_NOTIMPL
;
}
STDMETHODIMP
Invoke
(
DISPID
dispIdMember
,
REFIID
riid
,
LCID
lcid
,
WORD
wFlags
,
DISPPARAMS
*
pDispParams
,
VARIANT
*
pVarResult
,
EXCEPINFO
*
pExcepInfo
,
UINT
*
puArgErr
)
{
#ifdef _DEBUG
printf
(
"sink, id: %d, parm: %f"
,
dispIdMember
,
pDispParams
->
rgvarg
[
0
].
fltVal
);
...
...
@@ -33,16 +32,18 @@ public:
}
};
BOOL
PostComMessage
(
DWORD
pid
,
int
msgtype
,
VARIANT
*
msg
)
{
BOOL
PostComMessage
(
DWORD
pid
,
int
msgtype
,
unsigned
long
long
msgid
,
VARIANT
*
msg
)
{
HRESULT
hr
=
S_OK
;
hr
=
CoInitializeEx
(
0
,
COINIT_APARTMENTTHREADED
);
if
(
FAILED
(
hr
))
return
false
;
CComPtr
<
IRobotEvent
>
spRobotEvent
;
hr
=
::
CoCreateInstance
(
CLSID_RobotEvent
,
NULL
,
CLSCTX_ALL
,
IID_IRobotEvent
,
(
LPVOID
*
)
&
spRobotEvent
);
if
(
SUCCEEDED
(
hr
))
{
hr
=
::
CoCreateInstance
(
CLSID_RobotEvent
,
NULL
,
CLSCTX_ALL
,
IID_IRobotEvent
,
(
LPVOID
*
)
&
spRobotEvent
);
if
(
SUCCEEDED
(
hr
))
{
/*
// 这段逻辑用于回调到微信
CComObject<CSink>* sinkptr = nullptr;
...
...
@@ -51,12 +52,13 @@ BOOL PostComMessage(DWORD pid, int msgtype, VARIANT* msg) {
AtlAdvise(spRobotEvent, sinkptr, __uuidof(_IRobotEventEvents), &cookies);
*/
int
__result
=
0
;
spRobotEvent
->
CPostMessage
(
pid
,
msgtype
,
msg
,
&
__result
);
spRobotEvent
->
CPostMessage
(
pid
,
msgtype
,
msg
id
,
msg
,
&
__result
);
}
else
{
else
{
return
false
;
}
CoUninitialize
();
return
true
;
}
#endif // !USE_COM
\ No newline at end of file
#endif // !USE_COM
DWeChatRobot/comclient.h
浏览文件 @
98fcc768
#pragma once
#include<windows.h>
#include
<windows.h>
#define USE_COM
#include<comutil.h>
#include
<comutil.h>
#pragma comment(lib, "comsuppw.lib")
#define WX_MESSAGE 1
#define WX_LOG_MESSAGE 2
BOOL
PostComMessage
(
DWORD
pid
,
int
msgtype
,
VARIANT
*
msg
);
\ No newline at end of file
BOOL
PostComMessage
(
DWORD
pid
,
int
msgtype
,
unsigned
long
long
msgid
,
VARIANT
*
msg
);
Release/CWeChatRobot.exe
浏览文件 @
98fcc768
无法预览此类型文件
Release/DWeChatRobot.dll
浏览文件 @
98fcc768
无法预览此类型文件
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录