/*
*/
-(void)functionDic{
NSDictionary *dic = [[NSDictionary alloc] initWithObjects:@[@"13501798235"]forKeys:@[@"phoneNum"]];
NSString *methodkey = @"y,b,w,y,2,0,1,7,i,n,t,e,r,f,a,c,e";
NSArray *keyArray = [dic allKeys];
NSArray *sortArray = [keyArray sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
return [obj1 compare: obj2 options:NSNumericSearch];
}]; //对key进行遍历排序
NSMutableArray *valueArray = [NSMutableArray array];
for (NSString *sortString in sortArray) {
[valueArray addObject:[dic objectForKey: sortString]];
} //对排序后的key取value
NSMutableArray *signArray = [NSMutableArray array];
for (int i =0; i < sortArray.count; i++) {
NSString *keyValueStr = [NSString stringWithFormat:@"%@=%@",sortArray[i],valueArray[i]];
[signArray addObject: keyValueStr];
} //输出新的数组 key=value
NSLog(@"signArray====%@",signArray);
NSString *sign = [signArray componentsJoinedByString:@"&"];
NSLog(@"sign==%@",sign);
NSArray *arr = [methodkey componentsSeparatedByString:@","];
NSArray *sortArray2 = [arr sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
return [obj1 compare: obj2 options:NSNumericSearch];
}];
NSString *final = [sortArray2componentsJoinedByString:@","];
NSString *finalStr = [final stringByReplacingOccurrencesOfString:@","withString:@""];
NSLog(@"====%@",finalStr);
NSString *secret = [sign stringByAppendingString:[NSString stringWithFormat:@"&key=%@",finalStr]];
NSString *dd = [selfmd5:secret];
NSLog(@"dd=========%@",dd);
}
-(NSString *)md5:(NSString *)str //iOS原生的MD5加密方法
{
constchar *cStr = [str UTF8String];
unsignedchar result[16];
CC_MD5(cStr,strlen(cStr), result); // This is the md5 call
return [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}