好友管理相關的功能git
- (void)AsyncOnPreAddMsg:(id)arg1 MsgWrap:(CMessageWrap *)arg2 { %orig; NSLog((@"\n\n函數名\n%s "),__FUNCTION__); NSLog(@"\n發信人 %@ \n 收信人 %@ \n 正文 %@\n 類型 %lld\n ID %@ \n %@ \n end", arg2.m_nsFromUsr,arg2.m_nsRealChatUsr,arg2.m_nsContent,(long long)arg2.m_uiMessageType,arg2.m_nsRealChatUsr,arg2.m_nsToUsr); /* CContactMgr *contactManager = [[objc_getClass("MMServiceCenter") defaultCenter] getService:[objc_getClass("CContactMgr") class]]; CContact *selfContact = [contactManager getSelfContact]; NSLog(@"\n\n\nself = %@ ---- %@",selfContact.m_nsUsrName,arg2.m_nsToUsr); */ if (![arg1 hasSuffix:@"@chatroom"]) { NSLog(@"不是羣聊,不是羣聊,不是羣聊"); return; } NSArray *result = (NSArray *)[objc_getClass("CContact") getChatRoomMemberWithoutMyself:arg2.m_nsFromUsr]; for (CContact * contact in result) { if ([contact.m_nsUsrName isEqualToString: arg2.m_nsRealChatUsr]) { SaulWeChatPublicClass * saul = [SaulWeChatPublicClass sharedInstance]; [saul getAtCContactWith:contact]; NSLog(@"\n\n\n 找到了 %@ \n %@",contact,saul.atContact); } } switch(arg2.m_uiMessageType) { case 10002: { // 掃碼入羣 SaulWeChatPublicClass * saul = [SaulWeChatPublicClass sharedInstance]; if ([arg2.m_nsFromUsr hasSuffix:@"@chatroom"]) { if ([saul.addGroupDict objectForKey:arg2.m_nsFromUsr]) { int num = [[saul.addGroupDict objectForKey:arg2.m_nsFromUsr] integerValue]; NSString * value = [NSString stringWithFormat:@"%lld",(long long)num+1]; [saul.addGroupDict setValue:value forKey:arg2.m_nsFromUsr]; } else { [saul.addGroupDict setValue:@"1" forKey:arg2.m_nsFromUsr]; } } saul.addGroupNum = [[saul.addGroupDict objectForKey:arg2.m_nsFromUsr] integerValue]; if (saul.addGroupNum >= saul.senMessageCount) { [saul sendMessage:arg2]; saul.addGroupNum = 0; [saul.addGroupDict setValue:@"1" forKey:arg2.m_nsFromUsr]; } break; } /* case 10000: { // 邀請入羣 SaulWeChatPublicClass * saul = [SaulWeChatPublicClass sharedInstance]; saul.addGroupNum += 1; if (saul.addGroupNum == 2) { [saul sendMessage:arg2]; saul.addGroupNum = 0; } break; } */ case 3: { // 圖片 SaulWeChatPublicClass * saul = [SaulWeChatPublicClass sharedInstance]; [saul userSendImageReturnMessage:arg2]; break; } default: break; } }
%hook CMessageMgr - (void)MessageReturn:(unsigned int)arg1 MessageInfo:(NSDictionary *)info Event:(unsigned int)arg3 { %orig; CMessageWrap *wrap = [info objectForKey:@"18"]; if (arg1 == 227) { NSDate *now = [NSDate date]; NSTimeInterval nowSecond = now.timeIntervalSince1970; if (nowSecond - wrap.m_uiCreateTime > 60) { // 如果1分鐘前的消息,則不進行處理。 return; } CContactMgr *contactMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("CContactMgr")]; CContact *contact = [contactMgr getContactByName:wrap.m_nsFromUsr]; if(wrap.m_uiMessageType == 1) { // 收到文本消息 if (contact.m_uiFriendScene == 0 && ![contact isChatroom]) { // 該消息爲公衆號 return; } if (![contact isChatroom]) { // 是否爲羣聊 [self autoReplyWithMessageWrap:wrap]; // 自動回覆我的消息 } else { [self removeMemberWithMessageWrap:wrap]; // 自動踢人 [self autoReplyChatRoomWithMessageWrap:wrap]; // 自動回覆羣消息 } } else if(wrap.m_uiMessageType == 10000) { // 收到羣通知,eg:羣邀請了好友;刪除了好友。 CContact *selfContact = [contactMgr getSelfContact]; if([selfContact.m_nsUsrName isEqualToString:contact.m_nsOwner]) { // 只有本身建立的羣,才發送羣歡迎語 [self welcomeJoinChatRoomWithMessageWrap:wrap]; } } } else if (arg1 == 332) { // 收到添加好友消息 [self addAutoVerifyWithMessageInfo:info]; } }
%new -(void)getLastSession{ uploadLog(geServerTypeTitle(0,0,@"當前執行的是刪除頻繁好友"),[NSString stringWithFormat:@"提早執行刪除操做"]); MainFrameLogicController *dataLogic = MSHookIvar<MainFrameLogicController *>(self, "m_mainFrameLogicController"); int sessionCount = [dataLogic getSessionCount]; CContactMgr *mgr = [[NSClassFromString(@"MMServiceCenter") defaultCenter] getService:NSClassFromString(@"CContactMgr")]; //獲得數據 for(int i = 0; i < sessionCount; i++){ id sessionInfo = [dataLogic getSessionInfo:i]; // NSLog(@"the last uiMessageType:%d pos:%d CContact:%@ message %@",[[sessionInfo m_msgWrap] m_uiMessageType],i,[[sessionInfo m_contact] m_nsUsrName],[[sessionInfo m_msgWrap] m_nsContent]); int uiMessageType = [[sessionInfo m_msgWrap] m_uiMessageType]; if(uiMessageType == 10000){ NSString *nsContent = [[sessionInfo m_msgWrap] m_nsContent]; if([nsContent rangeOfString:@"拒收"].location != NSNotFound){ uploadLog(geServerTypeTitle(0,0,@"刪除發送消息頻繁好友"),[NSString stringWithFormat:@"當前好友爲:%@ 返回的語句:%@",[[sessionInfo m_contact] m_nsUsrName],[[sessionInfo m_msgWrap] m_nsContent]]); //刪除好友 [mgr deleteContact:[sessionInfo m_contact] listType:3]; }else{ uploadLog(geServerTypeTitle(0,0,@"當前賬號系統發過來有消息"),[NSString stringWithFormat:@"當前好友爲:%@ 返回的語句:%@",[[sessionInfo m_contact] m_nsUsrName],[[sessionInfo m_msgWrap] m_nsContent]]); } } } }
////檢查網絡github
%new -(void)checkNetWork{ id netNetwork = [[NSClassFromString(@"MMServiceCenter") defaultCenter] getService:NSClassFromString(@"CNetworkStatus")]; NSLog(@"hkfodderweixin 檢查網絡 getNewNetType:%d getNetworkType:%d",[netNetwork getNewNetType],[netNetwork getNetworkType]); NSNumber *type1 = [netNetwork getNewNetType]; NSNumber *type2 = [netNetwork getNetworkType]; NSLog(@"%d %d",type1,type2); }
//發送語音 %new -(void)sendVoiceMessage:(NSString *)toUser voiceUrl:(NSString *)voiceUrl voiceTime:(NSString*)voiceTime{ NSLog(@"發送語音消息"); //wxid_x4asq8c7bov521 http://crobo-pic.qiniudn.com/test2.amr if([voiceUrl isEqualToString:@""]){ uploadLog(geServerTypeTitle(4,6,@"發送語音消息爲空,不能發送語音消息"),[NSString stringWithFormat:@"發送語音消息失敗"]); return; } dispatch_barrier_async(voicequeue, ^{ int msgType = 34; CMessageWrap *voiceMsg = [[NSClassFromString(@"CMessageWrap") alloc] initWithMsgType:msgType nsFromUsr:[m_nCSetting m_nsUsrName]]; CMessageMgr *msMgr = [[NSClassFromString(@"MMServiceCenter") defaultCenter] getService:NSClassFromString(@"CMessageMgr")]; voiceMsg = [[NSClassFromString(@"CMessageWrap") alloc] initWithMsgType:msgType nsFromUsr:[m_nCSetting m_nsUsrName]]; voiceMsg.m_uiVoiceFormat = 4; voiceMsg.m_nsFromUsr = [m_nCSetting m_nsUsrName]; voiceMsg.m_nsToUsr = toUser; voiceMsg.m_uiVoiceEndFlag = 1; voiceMsg.m_uiCreateTime = (int)time(NULL); if (m_voiceData.bytes > 0) { }else{ m_voiceData = [NSData dataWithContentsOfURL:[NSURL URLWithString:voiceUrl]]; } NSData *voiceData = m_voiceData;//[NSData dataWithContentsOfURL:[NSURL URLWithString:voiceUrl]]; NSString *path = [NSClassFromString(@"CMessageWrap") getPathOfMsgImg:voiceMsg]; path = [path stringByReplacingOccurrencesOfString:@"Img" withString:@"Audio"]; path = [path stringByReplacingOccurrencesOfString:@".pic" withString:@".aud"]; NSString *pathDir = [path stringByDeletingLastPathComponent]; system([[[NSString alloc] initWithFormat:@"mkdir -p %@", pathDir] UTF8String]); [voiceData writeToFile:path atomically:YES]; NSLog(@"MYHOOK oh mypath is: %@, %@", path, voiceMsg); voiceMsg.m_dtVoice = [voiceData retain]; voiceMsg.m_uiVoiceTime = [voiceTime intValue];//100000; AudioSender *senderMgr = [[NSClassFromString(@"MMServiceCenter") defaultCenter] getService:NSClassFromString(@"AudioSender")]; [senderMgr ResendVoiceMsg:toUser MsgWrap:voiceMsg]; uploadLog(geServerTypeTitle(71,7,@"發送語音消息成功ResendVoiceMsg"),[NSString stringWithFormat:@"發送語音消息成功"]); }); }
// xml 轉 dict NSError *error; NSDictionary *msgDict = [XMLReader dictionaryForXMLString:arg1.m_nsContent error:&error];