微信切换账号

365 阅读3分钟

转载请注明出处

平时用的微信号和王者荣耀游戏的号是两个,游园惊梦的时候需要每天都登陆游戏号, 天天要退出, 切换账号, 输入账号密码, 太麻烦了,所以写了一个插件, 用于切换

我是基于Tweak编写的

第一步, 在设置界面添加了一个切换账号的cell

#import "src/WeChatHeader.h"

#import "substrate.h"
int myValue = 0;
%hook NewSettingViewController

- (void)reloadTableData {

%orig;
MMTableViewInfo *tableViewInfo = MSHookIvar<id>(self, "m_tableViewInfo");

MMTableViewSectionInfo *sectionInfo = [%c(MMTableViewSectionInfo) sectionInfoDefaut];

MMTableViewCellInfo *settingCell = [%c(MMTableViewCellInfo) normalCellForSel:@selector(switchAccount) target:self title:@"切换账号" accessoryType:1];
[sectionInfo addCell:settingCell];

[tableViewInfo insertSection:sectionInfo At:0];

MMTableView *tableView = [tableViewInfo getTableView];
[tableView reloadData];
}

第二步,cell的点击事件
// 点击事件
%new
- (void)switchAccount {

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"确认切换?" preferredStyle:UIAlertControllerStyleAlert];


UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"确定");


myValue = 1;

WCActionSheet * sheet = MSHookIvar<id>(self,"m_logOutActionSheet");
NSLog(@"确定111");

[self actionSheet:sheet clickedButtonAtIndex:1];

NSLog(@"确定222");


}];

UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"取消");

}];

[alertController addAction:action1];
[alertController addAction:action2];

[self presentViewController:alertController animated:YES completion:nil];

}


%end
效果图:

6FC2B7D411982CB03816D8A75FE7F099.png

通过分析, 登陆界面的登陆按钮的事件是-(void)onNext 然后账号, 密码,手机号的输入都是通过WCAccountTextFieldItem这个控件的-(void)setText:(id)arg1方法进行赋值
第三步,在正常退出后的界面, 点击切换账号的方法, 提取出来了

value是干什么呢, 区分是正常退出切换和插件自动切换用的

%hook WCAccountLoginLastUserViewController

- (void)viewDidLoad
{
%orig;

NSLog(@"myvalue 🐦= %d",myValue);


if(myValue)
{


WCAccountLoginControlLogic * change = [[%c(WCAccountLoginControlLogic) alloc]init];

WCUIActionSheet * action = [[%c(WCUIActionSheet) alloc]init];

[change onLastUserChangeAccount:action];
}

}




%end


第四步,点击切换完成后输入手机号/qq账号

因为我自己的账号一个是qq和密码登陆, 一个是手机号+密码,所以会有判断,需要用哪个接口登陆

%hook WCAccountMainLoginViewController

- (void)viewDidLoad
{
%orig;
    if(myValue)
    {
//(CAppUtil) getLastPhoneNumber 获取当前账号绑定手机的,用于判定当前账号是哪个, 你们也可以用别的来判断
        if([[%c(CAppUtil) getLastPhoneNumber] isEqualToString:@"+8618201301234"])
        {
            WCAccountTextFieldItem * phone = MSHookIvar<id>(self,"_textFieldPhoneNumberItem");

            [phone setText:@"15000471234"];

            [self onNext];
        }
        else if([[%c(CAppUtil) getLastPhoneNumber] isEqualToString:@"+8615000471234"])
        {
            WCAccountTextFieldItem * username = MSHookIvar<id>(self,"_textFieldUserNameItem");
            WCAccountTextFieldItem * pwd = MSHookIvar<id>(self,"_textFieldUserPwdItem");

            [username setText:@"775931234"];
            [pwd setText:@"1234456"];
            [self switchToUserLogin];
            [self onNext];
        }

    }

}

%end
switchToUserLogin 是切换到qq号和密码界面, 然后调用那个界面的onNext
最后一步,登陆,myValue = 0; 恢复成正常状态, 以免影响正常退出之后的登陆
%hook WCAccountNewPhoneVerifyViewController

- (void)viewDidLoad
{
%orig;



if(myValue)
{
WCAccountTextFieldItem * phone = MSHookIvar<id>(self,"_textFieldPwdItem");

[phone setText:@"1234456"];

[self onNext];
myValue = 0;
}


}


%end
对了, 还有一个头文件WeChatHeader.h
@interface CAppUtil : NSObject
+ (id)getLastPhoneNumber;

@end


@interface WCAccountLoginControlLogic : UIViewController
- (void)onLastUserChangeAccount:(id)arg1;
@end


@interface WCAccountLoginLastUserViewController : UIViewController
- (void)actionSheet:(id)arg1 clickedButtonAtIndex:(long long)arg2;
- (void)showInView:(id)arg1;


@end


@interface WCActionSheet : UIActionSheet
- (void)showInView:(id)arg1;

@end
@interface WCUIActionSheet : WCActionSheet

@end

@interface WCAccountTextFieldItem : NSObject
- (void)setText:(id)arg1;
- (id)getTextField;

@end


@interface WCAccountMainLoginViewController : UIViewController
- (void)onNext;
- (void)switchToUserLogin;

@end

@interface WCAccountNewPhoneVerifyViewController : UIViewController
//@property (nonatomic ,strong) WCAccountTextFieldItem *textFieldPwdItem;
//
//@property (nonatomic ,strong) WCAccountTextFieldItem *textFieldVerifyCodeItem;

- (void)onNext;
@end
@interface NewSettingViewController: MMUIViewController

- (void)reloadTableData;
- (void)actionSheet:(id)arg1 clickedButtonAtIndex:(long long)arg2;

// 退出, 哪个都可以, 具体不知道是哪个
- (void)tryQuit;
- (void)finalQuit;

@end

最后,有可能会有bug,会不适用于你 , 思路就是这么个思路 ,和方法, 可以参考参考, 主要也是针对我的情况,非常方便, 切换很快