MD5签名中参数首字母升序排列

MD5签名:按网络请求参数首字母升序排列(获取到的字符串MD5处理)

- (NSString*)stringWithDict:(NSDictionary *) dict{
    
    NSArray * keys = [dict allKeys];
    
    NSArray * sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1,id obj2) {
        
        return[obj1 compare:obj2 options:NSNumericSearch];
        
    }];
    
    NSString * str =@"";
    
    for(NSString * categoryId in sortedArray) {
        
        id value = [dict objectForKey:categoryId];
        
        if([value isKindOfClass:[NSDictionary class]]) {
            
            value = [self stringWithDict:value];
        }
        
        if([str length] != 0) {
            
            str = [str stringByAppendingString:@""];
        }
        
        str = [str stringByAppendingFormat:@"%@",value];        
    }
    
    return str;
}

你可能感兴趣的:(MD5签名中参数首字母升序排列)