AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSDictionary *dict = @{@"userId":@"11", @"name":@"zs", @"portraitUri":@"http://www.baidu.com/a.png"};
NSString *timestamp = [[NSString alloc] initWithFormat:@"%ld",(NSInteger)[NSDate timeIntervalSinceReferenceDate]];
NSString *nonce = [NSString stringWithFormat:@"%d",arc4random()];
#warning 从你的控制台获得
NSString *appkey = @"从你的控制台获得";
NSString *SignatureWillMD5 = [NSString stringWithFormat:@"%@%@%@",appkey,nonce,timestamp];
NSString *Signature = [self MD5String:SignatureWillMD5];
[manager.requestSerializer setValue:appkey forHTTPHeaderField:@"App-Key"];
[manager.requestSerializer setValue:nonce forHTTPHeaderField:@"Nonce"];
[manager.requestSerializer setValue:timestamp forHTTPHeaderField:@"Timestamp"];
[manager.requestSerializer setValue:Signature forHTTPHeaderField:@"Signature"];
#warning 从你的控制台查看
[manager.requestSerializer setValue:@"从你的控制台获得" forHTTPHeaderField:@"appSecret"];
[manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[manager POST:RONGCLOUD_URL parameters:dict success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if ([responseObject[@"code"] integerValue] == 200)
{
// 获取到token
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
if (error)
{
// token失效等
}
}];
iOS 融云获取token
最新推荐文章于 2021-07-14 14:33:11 发布