标签:
+(NSString *)jsonTokenString:(NSDictionary *)dic
{
myDic = [NSMutableDictionary dictionary];
for (NSString *key in dic) {
//判断类型
if ([dic[key] isKindOfClass:[NSDictionary class]]) {
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:dic[key] options:NSJSONWritingPrettyPrinted error:&error];
NSString *dicString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[myDic setValue:dicString forKey:key];
}
else
{
if ([dic[key] isKindOfClass:[NSArray class]]) {
//数组转化为字符串
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:dic[key] options:NSJSONWritingPrettyPrinted error:&error];
NSString *arrString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[myDic setValue:arrString forKey:key];
}
else
{
if ([dic[key] isKindOfClass:[NSString class]]) {
[myDic setValue:dic[key] forKey:key];
}
else
{
[myDic setValue:[NSString stringWithFormat:@"%ld",[dic[key] integerValue]] forKey:key];
}
}
}
}
myArray = [[myDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
NSString *string = @"";
for (NSString *key in myArray) {
string = [string stringByAppendingString:key];
string = [string stringByAppendingString:@"="];
string = [string stringByAppendingString:[myDic objectForKey:key]];
string = [string stringByAppendingString:@"&"];
}
string = [string stringByAppendingString:@"key="];
NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"userKey"];
string = [string stringByAppendingString:str];
string = [[string MD5]substringFromIndex:24];
return string;
}
发送网络请求时,字符串按字符顺序拼接,之后用MD5加密,去后8位
标签:
原文地址:http://www.cnblogs.com/xiaolingling1126/p/5076673.html