标签:
NSMutableDictionary *signParams = [NSMutableDictionary dictionary];
[signParams setObject: req.openID forKey:@"appid"];
[signParams setObject: req.nonceStr forKey:@"noncestr"];
[signParams setObject: req.package forKey:@"package"];
[signParams setObject: req.partnerId forKey:@"partnerid"];
[signParams setObject: @(req.timeStamp) forKey:@"timestamp"];
[signParams setObject: req.prepayId forKey:@"prepayid"];
NSMutableString *contentString =[NSMutableString string];
NSArray *keys = [signParams allKeys];
//按字母顺序排序
NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [obj1 compare:obj2 options:NSNumericSearch];
}];
//拼接字符串
for (NSString *categoryId in sortedArray) {
if ( ![[dict objectForKey:categoryId] isEqualToString:@""]
&& ![categoryId isEqualToString:@"sign"]
&& ![categoryId isEqualToString:@"key"]
)
{
[contentString appendFormat:@"%@=%@&", categoryId, [signParams objectForKey:categoryId]];
}
}
//添加key字段
[contentString appendFormat:@"key=%@", @"商户api密钥"];
req.sign = [contentString MD5];
标签:
原文地址:http://www.cnblogs.com/heiheihei/p/5139849.html