码迷,mamicode.com
首页 > 其他好文 > 详细

发送网络请求时,字符串按字符顺序拼接,之后用MD5加密,去后8位

时间:2015-12-25 19:17:08      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:

+(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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!