wx自动抢红包插件成品+源码
这个插件源码参考了别的git上的代码,自己测试实现并做成插件,仅供学习交流使用。
功能概述:全自动抢红包。
抢红包分为两步:
- 拉取红包信息 获取
timingIdentifier
参数 - 在拉取到红包信息后自动抢红包
适用微信版本:7.0.8
1.源码
#import "WCAHeader.h"
%hook CMessageMgr
- (void)AsyncOnAddMsg:(id)arg1 MsgWrap:(id)arg2{
%orig;
/*
// 普通消息
arg1 = can-mc
arg2 =
{
m_uiMesLocalID=197,
m_ui64MesSvrID=2824478158160742081,
m_nsFromUsr=ca*mc~6,
m_nsToUsr=wxi*t12~19,
m_uiStatus=3,
type=1,
createTime=1604302961
msgSource="
<msgsource>
<sequence_id>628803737</sequence_id>
</msgsource>"
}
// 红包消息
arg1=can-mc
arg2=
{
m_uiMesLocalID=198,
m_ui64MesSvrID=7203190142439524046,
m_nsFromUsr=ca*mc~6,
m_nsToUsr=wxi*t12~19,
m_uiStatus=3,
type=49,
createTime=1604303223
msgSource="
<msgsource>
<sequence_id>628803738</sequence_id>
<pushkey />
</msgsource>"
}
OpenRedEnvelopesRequest arg1={
channelId = 1;
headImg = "http://wx.qlogo.cn/mmhead/ver_1/gsEaDOciab4f5eYY4H5weGNXxNhnm0mMATMiaqqIibdiawMWaHKq5AY8nJ0ntWVDnbxeQRfN1oeofeNjEmUXq3k5Mk1n9zrdPRDbalBs2xFqsYA/132";
msgType = 1;
nativeUrl = "wxpay://c2cbizmessagehandler/hongbao/receivehongbao?msgtype=1&channelid=1&sendid=1000039901202011026343526263794&sendusername=can-mc&ver=6&sign=359817b91ad669e5fb7bc14ad6273a9543fda22b830b4da0dfa61a2b81d4f96e645382c7789a901bcbdeff6bb3a4febed7b32c73d1819209fed5721f18b13ab4e56df78b17b88c3b0ad5fb80008bb54f";
nickName = "\U5c0f\U9a6c\U7238\U7238";
sendId = 1000039901202011026343526263794;
sessionUserName = "can-mc";
timingIdentifier = B6DCF7967B0617E6C008679693E8FBEA;
}
content=
<msg>
<appmsg appid="" sdkver="">
<des><![CDATA[我给你发了一个红包,赶紧去拆!]]></des>
<url><![CDATA[https://wxapp.tenpay.com/mmpayhb/wxhb_personalreceive?showwxpaytitle=1&msgtype=1&channelid=1&sendid=1000039901202011026156324907879&ver=6&sign=cfd268f2186c0dbdce944b99fc1a26971eb30f5d9698470b19d921de2d04a87011dc7224e1dbdfaa14293b64c7b9c03cafd092930ea92ca0960d3d823e82ec1d45f2c26c5bf94bf567c85fec73626a35]]></url>
<type><![CDATA[2001]]></type>
<title><![CDATA[微信红包]]></title>
<thumburl><![CDATA[https://wx.gtimg.com/hongbao/1800/hb.png]]></thumburl>
<wcpayinfo>
<templateid><![CDATA[7a2a165d31da7fce6dd77e05c300028a]]></templateid>
<url>
<![CDATA[https://wxapp.tenpay.com/mmpayhb/wxhb_personalreceive?showwxpaytitle=1&msgtype=1&channelid=1&sendid=1000039901202011026156324907879&ver=6&sign=cfd268f2186c0dbdce944b99fc1a26971eb30f5d9698470b19d921de2d04a87011dc7224e1dbdfaa14293b64c7b9c03cafd092930ea92ca0960d3d823e82ec1d45f2c26c5bf94bf567c85fec73626a35]]></url>
<iconurl><![
*/
NSLog(@"+++++++++++++++++++++++++++++AsyncOnAddMsg arg1=%@, arg2=%@", arg1, arg2);
CMessageWrap *msg = arg2;
BOOL (^isRedEnvelopMessage)() = ^BOOL() {
return [msg.m_nsContent rangeOfString:@"wxpay://"].location != NSNotFound;
};
if(msg.m_uiMessageType == 49 && isRedEnvelopMessage()){
NSLog(@"+++++++++++++++++++++++++++++ isRedEnvelopMessage");
CContactMgr *contactManager = [[%c(MMServiceCenter) defaultCenter] getService:[%c(CContactMgr) class]];
CContact *selfContact = [contactManager getSelfContact];
NSDictionary *(^parseNativeUrl)(NSString *nativeUrl) = ^(NSString *nativeUrl) {
nativeUrl = [nativeUrl substringFromIndex:[@"wxpay://c2cbizmessagehandler/hongbao/receivehongbao?" length]];
return [%c(WCBizUtil) dictionaryWithDecodedComponets:nativeUrl separator:@"&"];
};
NSString *nativeUrl = [[msg m_oWCPayInfoItem] m_c2cNativeUrl];
NSDictionary *nativeUrlDict = parseNativeUrl(nativeUrl);
BOOL (^isSender)() = ^BOOL() {
return [msg.m_nsFromUsr isEqualToString:selfContact.m_nsUsrName];
};
BOOL (^isGroupSender)() = ^BOOL() {
return isSender() && [msg.m_nsToUsr rangeOfString:@"chatroom"].location != NSNotFound;
};
void (^queryRedEnvelopesReqeust)(NSDictionary *nativeUrlDict) = ^(NSDictionary *nativeUrlDict) {
WeChatRedEnvelopInstance* instance = [WeChatRedEnvelopInstance sharedInstance];
WeChatRedEnvelopParam* param = [[WeChatRedEnvelopParam alloc] init];
param.msgType = [nativeUrlDict stringForKey:@"msgtype"];
param.sendId = [nativeUrlDict stringForKey:@"sendid"];
param.channelId = [nativeUrlDict stringForKey:@"channelid"];
param.nickName = [selfContact getContactDisplayName];
param.headImg = [selfContact m_nsHeadImgUrl];
param.nativeUrl = [[msg m_oWCPayInfoItem] m_c2cNativeUrl];
param.sessionUserName = isGroupSender() ? msg.m_nsToUsr : msg.m_nsFromUsr;
param.sign = [nativeUrlDict stringForKey:@"sign"];
param.isGroupSender = isGroupSender();
instance.redEnvelopParam = param;
NSLog(@"+++++++++++++++++++++++++++++ param=%@", [instance.redEnvelopParam toParams]);
WCRedEnvelopesLogicMgr *logicMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:[objc_getClass("WCRedEnvelopesLogicMgr") class]];
[logicMgr ReceiverQueryRedEnvelopesRequest:[param toParams]];
};
queryRedEnvelopesReqeust(nativeUrlDict);
}
%log;
}
%end
%hook WCRedEnvelopesLogicMgr
- (void)OnWCToHongbaoCommonResponse:(id)arg1 Request:(id)arg2{
%orig;
NSLog(@"+++++++++++++++++++++++++++++OnWCToHongbaoCommonResponse arg1=%@, arg2=%@",arg1, arg2);
HongBaoRes * res = arg1;
HongBaoReq * req = arg2;
if (res.cgiCmdid != 3) { return; }
NSString *(^parseRequestSign)() = ^NSString *() {
NSString *requestString = [[NSString alloc] initWithData:req.reqText.buffer encoding:NSUTF8StringEncoding];
NSDictionary *requestDictionary = [%c(WCBizUtil) dictionaryWithDecodedComponets:requestString separator:@"&"];
NSString *nativeUrl = [[requestDictionary stringForKey:@"nativeUrl"] stringByRemovingPercentEncoding];
NSDictionary *nativeUrlDict = [%c(WCBizUtil) dictionaryWithDecodedComponets:nativeUrl separator:@"&"];
return [nativeUrlDict stringForKey:@"sign"];
};
NSDictionary *responseDict = [[[NSString alloc] initWithData:res.retText.buffer encoding:NSUTF8StringEncoding] JSONDictionary];
WeChatRedEnvelopInstance* instance = [WeChatRedEnvelopInstance sharedInstance];
BOOL (^shouldReceiveRedEnvelop)() = ^BOOL() {
if (!instance.redEnvelopParam) { return NO; }
if ([responseDict[@"receiveStatus"] integerValue] == 2) { return NO; }
if ([responseDict[@"hbStatus"] integerValue] == 4) { return NO; }
// 没有这个字段会被判定为使用外挂
if (!responseDict[@"timingIdentifier"]) { return NO; }
if (!instance.redEnvelopParam.isGroupSender) { // 自己发红包的时候没有 sign 字段
return [parseRequestSign() isEqualToString:instance.redEnvelopParam.sign];
}
return YES;
};
NSLog(@"+++++++++++++++++++++++++++++ receive: param=%@",[instance.redEnvelopParam toParams]);
if (shouldReceiveRedEnvelop()) {
instance.redEnvelopParam.timingIdentifier = responseDict[@"timingIdentifier"];
WCRedEnvelopesLogicMgr *logicMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:[objc_getClass("WCRedEnvelopesLogicMgr") class]];
[logicMgr OpenRedEnvelopesRequest:[instance.redEnvelopParam toParams]];
}
%log;
}
- (void)OpenRedEnvelopesRequest:(id)arg1{
NSLog(@"+++++++++++++++++++++++++++++OpenRedEnvelopesRequest arg1=%@",arg1);
%orig(arg1);
%log(arg1);
}
%end
2.下载安装方式
- cydia设置添加源:
http://lingo.bichonfrise.cn/cydia
- 找到
WeChatGrabHongBao
下载安装即可。 - 测试体验,有问题反馈即可。
3.问题反馈
有任何问题请联系vx:Nicholas_mc