解决了语音上传到问题,接下来要解决下载播放问题
This commit is contained in:
@@ -43,6 +43,8 @@
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
#import <AdSupport/ASIdentifierManager.h>
|
||||
#import "XianliaoApiManager.h"
|
||||
#import "QiniuManager.h"
|
||||
#import "QiniuConfig.h"
|
||||
@interface gameController ()
|
||||
<WKNavigationDelegate,WXApiManagerDelegate,VoiceRecorderBaseVCDelegate,AVAudioPlayerDelegate,ASIHTTPRequestDelegate,AMapLocationManagerDelegate,UIActionSheetDelegate,AgoraRtcEngineDelegate>
|
||||
{
|
||||
@@ -844,7 +846,7 @@
|
||||
CTTelephonyNetworkInfo *telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];
|
||||
CTCarrier *carrier = [telephonyInfo subscriberCellularProvider];
|
||||
NSString *currentCountry=[carrier carrierName];
|
||||
// NSLog(@"[carrier isoCountryCode]==%@,[carrier allowsVOIP]=%d,[carrier mobileCountryCode=%@,[carrier mobileCountryCode]=%@",[carrier isoCountryCode],[carrier allowsVOIP],[carrier mobileCountryCode],[carrier mobileNetworkCode]);
|
||||
// NSLog(@"[carrier isoCountryCode]==%@,[carrier allowsVOIP]=%d,[carrier mobileCountryCode=%@,[carrier mobileNetworkCode]=%@",[carrier isoCountryCode],[carrier allowsVOIP],[carrier mobileCountryCode],[carrier mobileNetworkCode]);
|
||||
UIDevice *device = [[UIDevice alloc] init];
|
||||
// NSString *name = device.name; //获取设备所有者的名称
|
||||
NSString *model = device.model; //获取设备的类别
|
||||
@@ -2194,6 +2196,15 @@
|
||||
NSLog(@"录音时长过短,可能无效: %.2f秒", interval);
|
||||
return;
|
||||
}
|
||||
|
||||
//4.播放
|
||||
if (play == nil)
|
||||
{
|
||||
NSLog(@"ERror creating player: %@", [play description]);
|
||||
}else{
|
||||
[play play];
|
||||
}
|
||||
|
||||
|
||||
NSString *amrPath = [FuncPublic GetPathByFileName:_fileName ofType:@"amr"];
|
||||
NSLog(@"尝试转换WAV到AMR,源文件: %@,目标文件: %@", _filePath, amrPath);
|
||||
@@ -2223,23 +2234,67 @@
|
||||
NSLog(@"转换WAV到AMR成功");
|
||||
NSData *amrData = [NSData dataWithContentsOfFile:amrPath];
|
||||
if (amrData && amrData.length > 0) {
|
||||
// 数据有效,继续上传流程
|
||||
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
|
||||
//接收类型不一致请替换一致text/html或别的
|
||||
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
|
||||
@"text/html",
|
||||
@"image/jpeg",
|
||||
@"image/png",
|
||||
@"application/octet-stream",
|
||||
@"text/json",
|
||||
@"audio/amr",
|
||||
nil];
|
||||
NSString *string=@"http://gameapi.0791ts.cn/api/UpLoad/PostFile";
|
||||
|
||||
|
||||
|
||||
|
||||
// 数据有效,使用QiniuManager上传到七牛云
|
||||
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
||||
formatter.dateFormat =@"yyyyMMddHHmmss";
|
||||
NSString *str = [formatter stringFromDate:[NSDate date]];
|
||||
NSString *fileName = [NSString stringWithFormat:@"%@%08X.amr", str, arc4random()];
|
||||
// 继续原有的上传逻辑...
|
||||
formatter.dateFormat = @"yyyyMMddHHmmss";
|
||||
NSString *timeStr = [formatter stringFromDate:[NSDate date]];
|
||||
NSString *uniqueFileName = [NSString stringWithFormat:@"%@_%08X.amr", timeStr, arc4random()];
|
||||
|
||||
// 显示上传状态提示
|
||||
// UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示"
|
||||
// message:@"正在上传录音文件..."
|
||||
// preferredStyle:UIAlertControllerStyleAlert];
|
||||
// [self presentViewController:alertController animated:YES completion:nil];
|
||||
|
||||
// 调用七牛云管理器上传文件
|
||||
[[QiniuManager sharedManager] uploadAudioFile:amrPath
|
||||
fileName:uniqueFileName
|
||||
progressHandler:^(float progress) {
|
||||
// 更新上传进度提示
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// alertController.message = [NSString stringWithFormat:@"正在上传录音文件... %.0f%%", progress * 100];
|
||||
// });
|
||||
}
|
||||
completionHandler:^(NSString *key, NSError *error) {
|
||||
// 关闭上传进度提示
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// [alertController dismissViewControllerAnimated:YES completion:nil];
|
||||
|
||||
if (error) {
|
||||
// 上传失败处理
|
||||
// UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:@"上传失败"
|
||||
// message:error.localizedDescription
|
||||
// preferredStyle:UIAlertControllerStyleAlert];
|
||||
// UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
|
||||
// [errorAlert addAction:okAction];
|
||||
// [self presentViewController:errorAlert animated:YES completion:nil];
|
||||
//
|
||||
NSLog(@"七牛云上传失败: %@", error);
|
||||
} else {
|
||||
// 上传成功,获取文件URL
|
||||
NSString *fileUrl = [[QiniuManager sharedManager] getFileUrlWithKey:key];
|
||||
NSString *audiourl=[NSString stringWithFormat:@"%@/%@",kQiniuDomain,uniqueFileName];
|
||||
[_bridge callHandler:@"getaudiourl" data:@{ @"audiourl":audiourl,@"time":[NSString stringWithFormat:@"%ld",(long)time]} ];
|
||||
NSLog(@"七牛云上传成功,文件URL: %@", fileUrl);
|
||||
|
||||
// 将录音文件URL传递给JS接口
|
||||
if (self->_bridge) {
|
||||
[self->_bridge callHandler:@"recordSuccess" data:@{
|
||||
@"fileUrl": fileUrl,
|
||||
@"fileName": uniqueFileName,
|
||||
@"fileKey": key
|
||||
}];
|
||||
}
|
||||
}
|
||||
});
|
||||
}];
|
||||
|
||||
// 原有的上传流程代码注释掉或删除
|
||||
|
||||
} else {
|
||||
NSLog(@"AMR文件无效或为空");
|
||||
}
|
||||
@@ -2476,3 +2531,5 @@
|
||||
}}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
25
msext/Class/Utils/QiniuConfig.h
Normal file
25
msext/Class/Utils/QiniuConfig.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// QiniuConfig.h
|
||||
// msext
|
||||
//
|
||||
// Created on June 15, 2025.
|
||||
//
|
||||
|
||||
#ifndef QiniuConfig_h
|
||||
#define QiniuConfig_h
|
||||
|
||||
/* 七牛云相关配置常量 */
|
||||
// AccessKey 和 SecretKey,从七牛云控制台获取
|
||||
extern NSString *const kQiniuAccessKey;
|
||||
extern NSString *const kQiniuSecretKey;
|
||||
|
||||
// 存储空间名称
|
||||
extern NSString *const kQiniuBucketName;
|
||||
|
||||
// 七牛云默认域名
|
||||
extern NSString *const kQiniuDomain;
|
||||
|
||||
// 录音文件目录
|
||||
extern NSString *const kQiniuRecordingDirectory;
|
||||
|
||||
#endif /* QiniuConfig_h */
|
||||
22
msext/Class/Utils/QiniuConfig.m
Normal file
22
msext/Class/Utils/QiniuConfig.m
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// QiniuConfig.m
|
||||
// msext
|
||||
//
|
||||
// Created on June 15, 2025.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "QiniuConfig.h"
|
||||
|
||||
// 七牛云 AccessKey 和 SecretKey
|
||||
NSString *const kQiniuAccessKey = @"dQbQLUm1jIuL9PEq4jd6VKB-6pPxPEdg7le9KeBm";
|
||||
NSString *const kQiniuSecretKey = @"RCZpwLhAPoQ2sQQyWXzMJc7Po2MyZWfUJeW4Jmfq";
|
||||
|
||||
// 存储空间名称
|
||||
NSString *const kQiniuBucketName = @"iosaudio";
|
||||
|
||||
// 七牛云默认域名,用于访问上传后的文件
|
||||
NSString *const kQiniuDomain = @"iosaudio.daoqi88.cn";
|
||||
|
||||
// 录音文件在七牛云中的目录
|
||||
NSString *const kQiniuRecordingDirectory = @"";
|
||||
76
msext/Class/Utils/QiniuManager.h
Normal file
76
msext/Class/Utils/QiniuManager.h
Normal file
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// QiniuManager.h
|
||||
// msext
|
||||
//
|
||||
// Created on June 15, 2025.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* 上传完成后的回调
|
||||
* @param key 文件在七牛云中的key
|
||||
* @param error 错误信息,如果上传成功则为nil
|
||||
*/
|
||||
typedef void(^QiniuUploadCompletionHandler)(NSString * _Nullable key, NSError * _Nullable error);
|
||||
|
||||
/**
|
||||
* 下载完成后的回调
|
||||
* @param filePath 下载文件的本地路径
|
||||
* @param error 错误信息,如果下载成功则为nil
|
||||
*/
|
||||
typedef void(^QiniuDownloadCompletionHandler)(NSString * _Nullable filePath, NSError * _Nullable error);
|
||||
|
||||
/**
|
||||
* 进度回调
|
||||
* @param progress 进度值,范围0-1
|
||||
*/
|
||||
typedef void(^QiniuProgressHandler)(float progress);
|
||||
|
||||
@interface QiniuManager : NSObject
|
||||
|
||||
/**
|
||||
* 获取QiniuManager的单例
|
||||
* @return QiniuManager实例
|
||||
*/
|
||||
+ (instancetype)sharedManager;
|
||||
|
||||
/**
|
||||
* 初始化七牛云SDK
|
||||
*/
|
||||
- (void)setupQiniuSDK;
|
||||
|
||||
/**
|
||||
* 上传本地音频文件到七牛云
|
||||
* @param filePath 本地文件路径
|
||||
* @param fileName 上传后的文件名(不含路径)
|
||||
* @param progressHandler 上传进度回调
|
||||
* @param completionHandler 上传完成回调
|
||||
*/
|
||||
- (void)uploadAudioFile:(NSString *)filePath
|
||||
fileName:(NSString *)fileName
|
||||
progressHandler:(nullable QiniuProgressHandler)progressHandler
|
||||
completionHandler:(QiniuUploadCompletionHandler)completionHandler;
|
||||
|
||||
/**
|
||||
* 从七牛云下载音频文件
|
||||
* @param key 文件在七牛云中的key
|
||||
* @param progressHandler 下载进度回调
|
||||
* @param completionHandler 下载完成回调
|
||||
*/
|
||||
- (void)downloadAudioFile:(NSString *)key
|
||||
progressHandler:(nullable QiniuProgressHandler)progressHandler
|
||||
completionHandler:(QiniuDownloadCompletionHandler)completionHandler;
|
||||
|
||||
/**
|
||||
* 根据key获取七牛云文件的URL
|
||||
* @param key 文件在七牛云中的key
|
||||
* @return 完整的URL字符串
|
||||
*/
|
||||
- (NSString *)getFileUrlWithKey:(NSString *)key;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
256
msext/Class/Utils/QiniuManager.m
Normal file
256
msext/Class/Utils/QiniuManager.m
Normal file
@@ -0,0 +1,256 @@
|
||||
//
|
||||
// QiniuManager.m
|
||||
// msext
|
||||
//
|
||||
// Created on June 15, 2025.
|
||||
//
|
||||
|
||||
#import "QiniuManager.h"
|
||||
#import <QiniuSDK.h>
|
||||
#import "QiniuConfig.h"
|
||||
#import <objc/runtime.h>
|
||||
#import <CommonCrypto/CommonHMAC.h>
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
@implementation QiniuManager
|
||||
|
||||
+ (instancetype)sharedManager {
|
||||
static QiniuManager *instance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
instance = [[self alloc] init];
|
||||
[instance setupQiniuSDK];
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
|
||||
- (void)setupQiniuSDK {
|
||||
// Qiniu SDK doesn't require explicit initialization
|
||||
// The configuration will be applied when creating the QNUploadManager instance
|
||||
}
|
||||
|
||||
- (void)uploadAudioFile:(NSString *)filePath
|
||||
fileName:(NSString *)fileName
|
||||
progressHandler:(QiniuProgressHandler)progressHandler
|
||||
completionHandler:(QiniuUploadCompletionHandler)completionHandler {
|
||||
|
||||
// 检查文件是否存在
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
|
||||
NSError *error = [NSError errorWithDomain:@"QiniuManager" code:-1 userInfo:@{NSLocalizedDescriptionKey: @"上传文件不存在"}];
|
||||
if (completionHandler) {
|
||||
completionHandler(nil, error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建上传配置
|
||||
QNConfiguration *config = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
|
||||
builder.zone = [QNFixedZone zone2]; // 使用华东区域
|
||||
builder.timeoutInterval = 60; // 超时设置,单位为秒
|
||||
}];
|
||||
|
||||
// 生成上传策略
|
||||
QNUploadManager *uploadManager = [[QNUploadManager alloc] initWithConfiguration:config];
|
||||
NSString *token = [self generateUploadToken];
|
||||
|
||||
// 文件在七牛云存储中的完整路径
|
||||
NSString *key = [NSString stringWithFormat:@"%@%@", kQiniuRecordingDirectory, fileName];
|
||||
|
||||
// 配置上传选项
|
||||
QNUploadOption *option = [[QNUploadOption alloc] initWithMime:@"audio/amr"
|
||||
progressHandler:^(NSString *key, float percent) {
|
||||
if (progressHandler) {
|
||||
progressHandler(percent);
|
||||
}
|
||||
} params:nil checkCrc:NO cancellationSignal:nil];
|
||||
|
||||
// 执行上传
|
||||
[uploadManager putFile:filePath
|
||||
key:key
|
||||
token:token
|
||||
complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
|
||||
if (info.statusCode == 200) {
|
||||
if (completionHandler) {
|
||||
completionHandler(key, nil);
|
||||
}
|
||||
} else {
|
||||
NSError *error = [NSError errorWithDomain:@"QiniuManager"
|
||||
code:info.statusCode
|
||||
userInfo:@{NSLocalizedDescriptionKey: info.error.localizedDescription ?: @"上传失败"}];
|
||||
if (completionHandler) {
|
||||
completionHandler(nil, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
option:option];
|
||||
}
|
||||
|
||||
- (void)downloadAudioFile:(NSString *)key
|
||||
progressHandler:(QiniuProgressHandler)progressHandler
|
||||
completionHandler:(QiniuDownloadCompletionHandler)completionHandler {
|
||||
|
||||
// 获取完整的下载URL
|
||||
NSString *urlString = [self getFileUrlWithKey:key];
|
||||
NSURL *url = [NSURL URLWithString:urlString];
|
||||
|
||||
// 创建下载任务
|
||||
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||||
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
|
||||
|
||||
NSURLSessionDownloadTask *downloadTask = [session downloadTaskWithURL:url completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
|
||||
if (error) {
|
||||
if (completionHandler) {
|
||||
completionHandler(nil, error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取临时文件URL
|
||||
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
|
||||
if (httpResponse.statusCode != 200) {
|
||||
NSError *downloadError = [NSError errorWithDomain:@"QiniuManager"
|
||||
code:httpResponse.statusCode
|
||||
userInfo:@{NSLocalizedDescriptionKey: @"下载失败"}];
|
||||
if (completionHandler) {
|
||||
completionHandler(nil, downloadError);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 从URL中获取文件名
|
||||
NSString *fileName = [key lastPathComponent];
|
||||
if ([fileName length] == 0) {
|
||||
fileName = [NSString stringWithFormat:@"qiniu_download_%@", [[NSUUID UUID] UUIDString]];
|
||||
}
|
||||
|
||||
// 创建目标路径
|
||||
NSString *cachesDirectory = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
|
||||
NSString *downloadDirectory = [cachesDirectory stringByAppendingPathComponent:@"QiniuDownloads"];
|
||||
|
||||
// 确保目录存在
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
if (![fileManager fileExistsAtPath:downloadDirectory]) {
|
||||
[fileManager createDirectoryAtPath:downloadDirectory withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
}
|
||||
|
||||
// 构建最终路径
|
||||
NSString *destinationPath = [downloadDirectory stringByAppendingPathComponent:fileName];
|
||||
|
||||
// 移动文件到目标路径
|
||||
if ([fileManager fileExistsAtPath:destinationPath]) {
|
||||
[fileManager removeItemAtPath:destinationPath error:nil];
|
||||
}
|
||||
|
||||
NSError *moveError = nil;
|
||||
[fileManager moveItemAtURL:location toURL:[NSURL fileURLWithPath:destinationPath] error:&moveError];
|
||||
|
||||
if (moveError) {
|
||||
if (completionHandler) {
|
||||
completionHandler(nil, moveError);
|
||||
}
|
||||
} else {
|
||||
if (completionHandler) {
|
||||
completionHandler(destinationPath, nil);
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
// 添加进度追踪
|
||||
if (progressHandler) {
|
||||
[downloadTask addObserver:self forKeyPath:@"countOfBytesReceived" options:NSKeyValueObservingOptionNew context:NULL];
|
||||
objc_setAssociatedObject(downloadTask, "progressHandler", [progressHandler copy], OBJC_ASSOCIATION_COPY);
|
||||
objc_setAssociatedObject(downloadTask, "totalBytes", @(0), OBJC_ASSOCIATION_RETAIN);
|
||||
}
|
||||
|
||||
// 启动下载任务
|
||||
[downloadTask resume];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
||||
if ([object isKindOfClass:[NSURLSessionDownloadTask class]]) {
|
||||
NSURLSessionDownloadTask *task = (NSURLSessionDownloadTask *)object;
|
||||
|
||||
if ([keyPath isEqualToString:@"countOfBytesReceived"]) {
|
||||
NSNumber *totalBytes = objc_getAssociatedObject(task, "totalBytes");
|
||||
if ([totalBytes longLongValue] == 0 && task.countOfBytesExpectedToReceive > 0) {
|
||||
objc_setAssociatedObject(task, "totalBytes", @(task.countOfBytesExpectedToReceive), OBJC_ASSOCIATION_RETAIN);
|
||||
}
|
||||
|
||||
float progress = 0;
|
||||
if (task.countOfBytesExpectedToReceive > 0) {
|
||||
progress = (float)task.countOfBytesReceived / (float)task.countOfBytesExpectedToReceive;
|
||||
}
|
||||
|
||||
QiniuProgressHandler progressHandler = objc_getAssociatedObject(task, "progressHandler");
|
||||
if (progressHandler) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
progressHandler(progress);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)getFileUrlWithKey:(NSString *)key {
|
||||
return [NSString stringWithFormat:@"%@/%@", kQiniuDomain, key];
|
||||
}
|
||||
|
||||
#pragma mark - Private Methods
|
||||
|
||||
- (NSString *)generateUploadToken {
|
||||
// 构建上传策略(putPolicy)
|
||||
NSMutableDictionary *policy = [NSMutableDictionary dictionary];
|
||||
|
||||
// 指定上传的目标资源空间(确保完整格式为bucketName或bucketName:keyPrefix)
|
||||
NSString *scope = [NSString stringWithFormat:@"%@", kQiniuBucketName];
|
||||
[policy setObject:scope forKey:@"scope"];
|
||||
|
||||
// 上传策略的过期时间(1小时)
|
||||
NSInteger deadline = (NSInteger)[[NSDate dateWithTimeIntervalSinceNow:3600] timeIntervalSince1970];
|
||||
[policy setObject:@(deadline) forKey:@"deadline"];
|
||||
|
||||
// 将上传策略转换为JSON
|
||||
NSError *error = nil;
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:policy options:0 error:&error];
|
||||
if (error) {
|
||||
NSLog(@"生成JSON数据失败: %@", error);
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Base64编码JSON数据
|
||||
NSString *encodedPolicy = [self urlsafeBase64EncodeData:jsonData];
|
||||
|
||||
// 使用HMAC-SHA1算法进行签名(注意签名的内容只是encodedPolicy)
|
||||
NSData *signData = [encodedPolicy dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSString *encodedSign = [self hmacSha1:kQiniuSecretKey data:signData];
|
||||
|
||||
// 构造上传凭证 - 格式为: accessKey:encodedSign:encodedPolicy
|
||||
NSString *uploadToken = [NSString stringWithFormat:@"%@:%@:%@", kQiniuAccessKey, encodedSign, encodedPolicy];
|
||||
|
||||
// NSLog(@"七牛云配置信息 - AccessKey: %@, BucketName: %@, Domain: %@",
|
||||
// kQiniuAccessKey, kQiniuBucketName, kQiniuDomain);
|
||||
// NSLog(@"生成的上传凭证: %@", uploadToken);
|
||||
return uploadToken;
|
||||
}
|
||||
|
||||
#pragma mark - Utility Methods
|
||||
|
||||
- (NSString *)urlsafeBase64EncodeData:(NSData *)data {
|
||||
NSString *base64 = [data base64EncodedStringWithOptions:0];
|
||||
base64 = [base64 stringByReplacingOccurrencesOfString:@"+" withString:@"-"];
|
||||
base64 = [base64 stringByReplacingOccurrencesOfString:@"/" withString:@"_"];
|
||||
return base64;
|
||||
}
|
||||
|
||||
- (NSString *)hmacSha1:(NSString *)key data:(NSData *)data {
|
||||
const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
const char *cData = [data bytes];
|
||||
unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH];
|
||||
|
||||
CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, [data length], cHMAC);
|
||||
|
||||
NSData *hmacData = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)];
|
||||
return [self urlsafeBase64EncodeData:hmacData];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user