2017最新ios微信红包代码

本文仅供学习交流,请勿用于其他用途。
2017年年关将近,在此祝大家抢到的红包多多。
微信红包做了一些参数的变化,增加了timingIdentifier 来防止作弊,再打开红包前需要先获取此参数作为抢红包的必要参数。
大家可以增加其他功能比如延时,还有UI 的制作,以及重签名安装到未越狱的机器等,尽可能发挥您的才智。
请参考下面的代码:
git地址WeChatTweak

id redPacketParams = nil;
id logicMgr = nil;

static NSMutableArray *timingIdentifierArray = nil;

%hook CMessageMgr
- (void)AsyncOnAddMsg:(NSString *)msg MsgWrap:(id)wrap
{
    %log;
    %orig;
    if(timingIdentifierArray==nil) timingIdentifierArray = [[NSMutableArray alloc] init];
    id content = [wrap performSelector:@selector(m_nsContent)];
    int type = ((int (*)(id, SEL))objc_msgSend)(wrap,@selector(m_uiMessageType));
    if(type!=49)return;
    if([content rangeOfString:@"wxpay://"].location == NSNotFound) return;
    id nativeUrl = [[wrap  performSelector:@selector(m_oWCPayInfoItem)] performSelector:@selector(m_c2cNativeUrl)];
    id paramsUrl = [nativeUrl substringFromIndex:[@"wxpay://c2cbizmessagehandler/hongbao/receivehongbao?" length]];
    NSDictionary *params = [%c(WCBizUtil) performSelector:@selector(dictionaryWithDecodedComponets:separator:) withObject:paramsUrl withObject:@"&"];
    id agreeDuty = @"0";
    id channelId = @"1";
    id inWay =     @"0";
    id url = nativeUrl;
    id sendId = params[@"sendid"];
   //将红包需要的参数放入到 requestParams中
    NSMutableDictionary *requestParams = [@{} mutableCopy];
    [requestParams setValue:sendId forKey:@"sendId"];
    [requestParams setValue:agreeDuty forKey:@"agreeDuty"];
    [requestParams setValue:channelId forKey:@"channelId"];
    [requestParams setValue:inWay forKey:@"inWay"];
    [requestParams setValue:url forKey:@"nativeUrl"];
    [requestParams setValue:@"1" forKey:@"msgType"];
    
    id serviceCenter = [%c(MMServiceCenter) performSelector:@selector(defaultCenter)];
    logicMgr =[serviceCenter performSelector:@selector(getService:) withObject:%c(WCRedEnvelopesLogicMgr)];
     //发送请求获取 timingIdentifier 
     [logicMgr performSelector:@selector(ReceiverQueryRedEnvelopesRequest:) withObject:requestParams];
      redPacketParams = requestParams;

    id contactManager = [[%c(MMServiceCenter) performSelector:@selector(defaultCenter)] performSelector:@selector(getService:) withObject:%c(CContactMgr)];
    id selfContact = [contactManager performSelector:@selector(getSelfContact)];
    id sessionUserName = [wrap performSelector:@selector(m_nsFromUsr)];
    id headImg = [selfContact performSelector:@selector(m_nsHeadImgUrl)];
    id nickName = [selfContact performSelector:@selector(getContactDisplayName)];
    [redPacketParams setValue:sessionUserName forKey:@"sessionUserName"];
    [redPacketParams setValue:headImg forKey:@"headImg"];
    [redPacketParams setValue:nickName forKey:@"nickName"];
}

%end


%hook WCRedEnvelopesLogicMgr

- (void)OnWCToHongbaoCommonResponse:(id)arg1 Request:(id)arg2
{
    %log;
    %orig;
    //获取 timingIdentifier 参数
    id reponseString = [[NSString alloc] initWithData:[[arg1 performSelector:@selector(retText)] performSelector:@selector(buffer)] encoding:NSUTF8StringEncoding];
    NSDictionary *reponse =  [reponseString performSelector:@selector(JSONDictionary)];
    id timingIdentifier = reponse[@"timingIdentifier"];
    //抢过的红包就不再去抢了
    if (timingIdentifier&&![timingIdentifierArray containsObject:timingIdentifier]) {
        [redPacketParams setValue:timingIdentifier forKey:@"timingIdentifier"];
        [logicMgr performSelector:@selector(OpenRedEnvelopesRequest:) withObject:redPacketParams];
        [timingIdentifierArray addObject:timingIdentifier];
    }
}
%end

你可能感兴趣的:(2017最新ios微信红包代码)