目录
实现步骤
1.获取自己的UID
2.根据自己UID创建群聊
获取UID
//获取自己的UID
%hook TBSDKConnection
- (void)addRequestHeader:(id)arg1 value:(id)arg2{
%log;//addRequestHeader:x-uid value:2795xxxxxx]
if([arg1 isEqualToString:@"x-uid"]){
[xddCode sharedInstance].myUserID = arg2;
}
%orig;//call
}
%end
创建群Call
+(void)addQun{
NSString *groupDTO = [NSString stringWithFormat:@"{\"namespace\":0,\"entityId\":\"\",\"name\":\"qun\",\"notice\":\"notice\",\"summary\":\"summary\",\"type\":\"G\",\"accountIds\":[\"%@#3\"],\"headPic\":\"\",\"createTime\":6256017216,\"modifyTime\":7521904624,\"bizType\":\"0\",\"linkGroups\":[],\"attributes\":\"\",\"isDeleted\":false,\"bizExt\":{},\"ampExt\":{}}",[xddCode sharedInstance].myUserID];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"{}", @"bizCtx",
@"taobao-ios", @"accessKey",
@"taobao-ios-secret", @"accessSecret",
groupDTO, @"groupDTO",
nil];
MPMAPIRequest*req = [[NSClassFromString(@"MPMAPIRequest") alloc] init];
req.bPost = true;
req.needAccount = false;
req.onMainThreadCallback = false;
req.version = @"1.0";
req.userId = [xddCode sharedInstance].myUserID;
req.param = params;
req.retryCount = 1;
req.timeOut = 30;
req.api = @"mtop.taobao.wireless.amp2.im.group.createGroup";
[NSClassFromString(@"MPMRequestHelper") asyncRequest:req successCallback:^(NSDictionary* dic) {
NSDictionary*data = dic[@"data"];
// [0] @"actionCode" : @"DIS_ERR_ADD_USER"
// [1] @"success" : @"false" [0] @"success" : @"true"
// [2] @"actionInfo" : @"入群失败,请重新尝试"
NSString*success = data[@"success"];
NSString*actionInfo = data[@"actionInfo"];
NSDictionary*value = data[@"value"];
if([@"true" isEqualToString:success]){
// [1] @"value" : 13 key/value pairs
// [1] @"entityId" : @"0_G_2xxxx31#3_15xxxx093_0"
actionInfo = value[@"entityId"];
}
dispatch_async(dispatch_get_main_queue(), ^{
[PayeeUtils showHint:actionInfo];
});
} failCallback:^(NSError*err){
// [0] @"mtopResponse" : @"{\"api\":\"mtop.taobao.wireless.amp2.im.group.creategroup\",\"data\":{},\"ret\":[\"3::服务器竟然出错了!\"],\"v\":\"1.0\"}"
// [1] @"NSLocalizedDescription" : @"服务器竟然出错了!"
// [2] @"mtopErrorCode" : @"3"
NSDictionary*info = err.userInfo;
NSString*mtopResponse = info[@"mtopResponse"];
NSString*NSLocalizedDescription = info[@"NSLocalizedDescription"];
dispatch_async(dispatch_get_main_queue(), ^{
[PayeeUtils showHint:NSLocalizedDescription];
});
}];
}