#pragma mark -- 参数的排序
+ (NSMutableString*)postSignParamet:(NSString*)method privateParam:(NSMutableDictionary*)param {
NSMutableString* lastParam = [[NSMutableString alloc]init];
//排序
NSArray* sortKeys = [[param allKeys] sortedArrayUsingSelector:@selector(compare:)];
for (NSString *key in sortKeys) {
[lastParam appendString:[NSString stringWithFormat:@"%@=%@&",key,[param objectForKey:key]]];
}
//appKey 作为排序的结尾字符,
[lastParam appendString:[NSString stringWithFormat:@"%@=%@",appkey,PARTNER_ID]];
return lastParam;
}
//生成签名
+ (NSString*)postSign:(NSString *)sign {
NSData *data = [sign dataUsingEncoding:NSUTF8StringEncoding];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(data.bytes, (CC_LONG)data.length, result);
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];
for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
[ret appendFormat:@"%02X",result[i]];
}
return ret;
}
#pragma mark -- 获取随机数
+ (NSString *)getNonceStr
{
NSString *string = [[NSString alloc]init];
for (int i = 0; i < 32; i++) {
int number = arc4random() % 32; //随机数的长度 32
if (number < 10) {
int figure = (arc4random() % 10) + 48; //数字
NSString *tempString = [NSString stringWithFormat:@"%d", figure];
string = [string stringByAppendingString:tempString];
}
else if (number > 10 && number < 20)
{
int figure = (arc4random() % 26) + 65; //大写
char character = figure;
NSString *tempString = [NSString stringWithFormat:@"%c", character];
string = [string stringByAppendingString:tempString];
}
else {
int figure = (arc4random() % 26) + 97; //小写
char character = figure;
NSString *tempString = [NSString stringWithFormat:@"%c", character];
string = [string stringByAppendingString:tempString];
}
}
NSLog(@"%@", string);
return string;
}
#pragma mark -- 获取唯一标识符
+ (NSString*)getDeviceInfo {
NSString *identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
return identifier;
}