Files
peko-ios/YuMi/Network/MSParamsDecode.m
2024-10-12 19:30:41 +08:00

65 lines
2.1 KiB
Objective-C

//
// MSParamsDecode.m
// YuMi
//
// Created by duoban on 2024/4/23.
//
#import "MSParamsDecode.h"
@implementation MSParamsDecode
+ (NSMutableDictionary *)msDecodeParams:(NSMutableDictionary *)params {
if (!params) {
params = [NSMutableDictionary dictionary];
}
[params setObject:[MSParamsDecode msSign:[params mutableCopy]] forKey:@"pub_sign"];
return params;
}
+ (NSString *)msSign:(NSMutableDictionary *)dic {
[dic removeObjectForKey:@"Accept-Language"];
[dic removeObjectForKey:@"pub_uid"];
[dic removeObjectForKey:@"appVersion"];
[dic removeObjectForKey:@"appVersionCode"];
[dic removeObjectForKey:@"channel"];
[dic removeObjectForKey:@"deviceId"];
[dic removeObjectForKey:@"ispType"];
[dic removeObjectForKey:@"netType"];
[dic removeObjectForKey:@"os"];
[dic removeObjectForKey:@"osVersion"];
[dic removeObjectForKey:@"app"];
[dic removeObjectForKey:@"ticket"];
[dic removeObjectForKey:@"client"];
[dic removeObjectForKey:@"channel"];
[dic removeObjectForKey:@"deviceId"];
[dic removeObjectForKey:@"lang"];
[dic removeObjectForKey:@"mcc"];
NSMutableString *stringA = [NSMutableString string];
//按字典key升序排序
NSArray *sortKeys = [[dic allKeys] sortedArrayUsingSelector:@selector(compare:)];
//拼接格式 “key0=value0&key1=value1&key2=value2”
for (NSString *key in sortKeys) {
[stringA appendString:[NSString stringWithFormat:@"%@=%@&", key, dic[key]]];
}
//拼接参数加密签名 PARAMSSECRET
[stringA appendString:[NSString stringWithFormat:@"key=%@", KeyWithType(KeyType_Sign)]];
//MD5加密签名
NSString *stringB = [stringA MD5String];
//返回大写字母
return stringB.uppercaseString;
}
+ (NSString *)uuidString{
CFUUIDRef uuid_ref = CFUUIDCreate(NULL);
CFStringRef uuid_string_ref= CFUUIDCreateString(NULL, uuid_ref);
NSString *uuid = [NSString stringWithString:(__bridge NSString *)uuid_string_ref];
CFRelease(uuid_ref);
CFRelease(uuid_string_ref);
return [uuid lowercaseString];
}
@end