baseStr = [[NSString alloc] initWithData:[QNUrlSafeBase64 decodeString:HIMAStr] encoding:NSUTF8StringEncoding]; [QNUrlSafeBase64 decodeString:HIMAStr]是有值的 但是返回出来却是nil这是为什么呀?这是我的代码 请大神们指点下!感激不尽!!!
运气好,正好最近也用到七牛:
- (NSString *)genToken { static NSUInteger expireTime = 0; static NSString *cachedSign = nil; NSUInteger now = (NSUInteger)[NSDate date].timeIntervalSince1970; if (now > expireTime) { expireTime = now + 3600 - 60; NSDictionary *policy = @{ @"scope": _bucket, @"deadline": @(expireTime + 60), @"returnBody": @"{\"key\":$(key),\"name\":$(fname),\"size\":$(fsize),\"w\":$(imageInfo.width),\"h\":$(imageInfo.height),\"hash\":$(etag)}" }; NSString *encodedPolicy = [[NSJSONSerialization dataWithJSONObject:policy options:0 error:NULL] base64EncodedStringWithOptions:0]; encodedPolicy = [encodedPolicy stringByReplacingOccurrencesOfString:@"+" withString:@"-"]; encodedPolicy = [encodedPolicy stringByReplacingOccurrencesOfString:@"/" withString:@"_"]; const char *text = [encodedPolicy cStringUsingEncoding:NSASCIIStringEncoding]; const char *key = [_secretKey cStringUsingEncoding:NSASCIIStringEncoding]; char cHMAC[CC_SHA1_DIGEST_LENGTH]; CCHmac(kCCHmacAlgSHA1, key, strlen(key), text, strlen(text), cHMAC); NSString *sign = [[NSString alloc] initWithData:[NSData dataWithBytes:cHMAC length:sizeof(cHMAC)] encoding:NSASCIIStringEncoding]; NSString *encodedSign = sign.toBase64String; encodedSign = [encodedSign stringByReplacingOccurrencesOfString:@"+" withString:@"-"]; encodedSign = [encodedSign stringByReplacingOccurrencesOfString:@"/" withString:@"_"]; cachedSign = [NSString stringWithFormat:@"%@:%@:%@", _accessKey, encodedSign, encodedPolicy]; } return cachedSign; }
运气好,正好最近也用到七牛: