赞
踩
- (NSString *)generate:(NSString *)secretKey {
NSString *counter = @"1527866554";
NSData *counterBytes = [counter dataUsingEncoding:NSUTF8StringEncoding];
NSData *keyBytes = [secretKey dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData *macOut = [NSMutableData dataWithLength:CC_SHA512_DIGEST_LENGTH];
CCHmac( kCCHmacAlgSHA512,
keyBytes.bytes,
keyBytes.length,
counterBytes.bytes,
counterBytes.length,
macOut.mutableBytes);
unsigned long long hash = 0;
[macOut getBytes:&hash length:sizeof(unsigned long)];
unsigned long long token = hash % (unsigned long)pow(10, 15);
NSString *strToken = [NSString stringWithFormat:@"%015lld", token];
NSLog(@"secret key = %@, counter = %@, payment code = %@", secretKey, counter, strToken);
return strToken;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。