QCloud文件传输

This commit is contained in:
liyuhua
2024-03-26 14:56:55 +08:00
parent 348e2b14a4
commit 51887239ca
30 changed files with 322 additions and 664 deletions

10
Podfile
View File

@@ -46,14 +46,10 @@ target 'YuMi' do
#上传音乐
pod 'CocoaAsyncSocket',:modular_headers => true
#声网
pod 'AgoraRtcEngine_iOS', '~> 4.2.2'
#上传图片
pod 'Qiniu'
#内购
pod 'IAPHelper'
pod 'AgoraRtcEngine_iOS', '~> 4.2.2'
#持久化存储
pod 'SSKeychain'
pod 'Base64'
pod 'SSKeychain'
pod 'Base64'
#pop动画
pod 'pop', '~> 1.0.12'
#云信

View File

@@ -1263,7 +1263,6 @@
E89D60BA271D643A001F8895 /* Api+Room.m in Sources */ = {isa = PBXBuildFile; fileRef = E89D60B9271D643A001F8895 /* Api+Room.m */; };
E89D60BD271D647A001F8895 /* XPRoomPresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = E89D60BC271D647A001F8895 /* XPRoomPresenter.m */; };
E89D60C1271D64B9001F8895 /* RoomInfoModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E89D60C0271D64B9001F8895 /* RoomInfoModel.m */; };
E89DA66427005932008483C1 /* XPIAPHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = E89DA66327005932008483C1 /* XPIAPHelper.m */; };
E89DA66727006443008483C1 /* RechargeStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = E89DA66627006443008483C1 /* RechargeStorage.m */; };
E89DA67227008D59008483C1 /* WalletInfoModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E89DA67127008D59008483C1 /* WalletInfoModel.m */; };
E89DA67527009ACD008483C1 /* XPMineRechargeNavView.m in Sources */ = {isa = PBXBuildFile; fileRef = E89DA67427009ACD008483C1 /* XPMineRechargeNavView.m */; };
@@ -1341,12 +1340,10 @@
E8B825C726EA0D9A009E8E9F /* LoginVerifCodeProtocol.h in Sources */ = {isa = PBXBuildFile; fileRef = E8B825C626EA0995009E8E9F /* LoginVerifCodeProtocol.h */; };
E8B825CA26EA1231009E8E9F /* LoginVerifCodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B825C826EA1231009E8E9F /* LoginVerifCodeViewController.m */; };
E8B825CD26EA18C8009E8E9F /* DJDKMIMOMColor.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B825CC26EA18C8009E8E9F /* DJDKMIMOMColor.m */; };
E8B846BC26FD7C1200A777FE /* UploadImage.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B846BB26FD7C1200A777FE /* UploadImage.m */; };
E8B846BF26FD827900A777FE /* XPMineUserInfoAlbumViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B846BE26FD827900A777FE /* XPMineUserInfoAlbumViewController.m */; };
E8B846C226FD82DC00A777FE /* XPMineUserInfoAlbumCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B846C126FD82DC00A777FE /* XPMineUserInfoAlbumCollectionViewCell.m */; };
E8B846C526FDB41A00A777FE /* XPMineUserInfolbumPresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B846C426FDB41A00A777FE /* XPMineUserInfolbumPresenter.m */; };
E8B846C726FDB45000A777FE /* XPMineUserInfoAlbumProtocol.h in Sources */ = {isa = PBXBuildFile; fileRef = E8B846C626FDB44100A777FE /* XPMineUserInfoAlbumProtocol.h */; };
E8B846CB26FDD7CD00A777FE /* XPMineRechargeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B846CA26FDD7CD00A777FE /* XPMineRechargeViewController.m */; };
E8B846CF26FDD96100A777FE /* XPMineRechageHeadView.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B846CE26FDD96100A777FE /* XPMineRechageHeadView.m */; };
E8B846D326FDDBE600A777FE /* XPMineRechargeTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B846D226FDDBE600A777FE /* XPMineRechargeTableViewCell.m */; };
E8B846D626FDE01B00A777FE /* XPMineRechargePresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B846D526FDE01B00A777FE /* XPMineRechargePresenter.m */; };
@@ -3852,8 +3849,6 @@
E89D60BE271D648D001F8895 /* XPRoomProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPRoomProtocol.h; sourceTree = "<group>"; };
E89D60BF271D64B9001F8895 /* RoomInfoModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoomInfoModel.h; sourceTree = "<group>"; };
E89D60C0271D64B9001F8895 /* RoomInfoModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoomInfoModel.m; sourceTree = "<group>"; };
E89DA66227005931008483C1 /* XPIAPHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPIAPHelper.h; sourceTree = "<group>"; };
E89DA66327005932008483C1 /* XPIAPHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPIAPHelper.m; sourceTree = "<group>"; };
E89DA66527006443008483C1 /* RechargeStorage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RechargeStorage.h; sourceTree = "<group>"; };
E89DA66627006443008483C1 /* RechargeStorage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RechargeStorage.m; sourceTree = "<group>"; };
E89DA67027008D59008483C1 /* WalletInfoModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WalletInfoModel.h; sourceTree = "<group>"; };
@@ -4012,8 +4007,6 @@
E8B825C926EA1231009E8E9F /* LoginVerifCodeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoginVerifCodeViewController.h; sourceTree = "<group>"; };
E8B825CB26EA18C8009E8E9F /* DJDKMIMOMColor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DJDKMIMOMColor.h; sourceTree = "<group>"; };
E8B825CC26EA18C8009E8E9F /* DJDKMIMOMColor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DJDKMIMOMColor.m; sourceTree = "<group>"; };
E8B846BA26FD7C1200A777FE /* UploadImage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UploadImage.h; sourceTree = "<group>"; };
E8B846BB26FD7C1200A777FE /* UploadImage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UploadImage.m; sourceTree = "<group>"; };
E8B846BD26FD827900A777FE /* XPMineUserInfoAlbumViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineUserInfoAlbumViewController.h; sourceTree = "<group>"; };
E8B846BE26FD827900A777FE /* XPMineUserInfoAlbumViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineUserInfoAlbumViewController.m; sourceTree = "<group>"; };
E8B846C026FD82DC00A777FE /* XPMineUserInfoAlbumCollectionViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineUserInfoAlbumCollectionViewCell.h; sourceTree = "<group>"; };
@@ -4021,8 +4014,6 @@
E8B846C326FDB41A00A777FE /* XPMineUserInfolbumPresenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineUserInfolbumPresenter.h; sourceTree = "<group>"; };
E8B846C426FDB41A00A777FE /* XPMineUserInfolbumPresenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineUserInfolbumPresenter.m; sourceTree = "<group>"; };
E8B846C626FDB44100A777FE /* XPMineUserInfoAlbumProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineUserInfoAlbumProtocol.h; sourceTree = "<group>"; };
E8B846C926FDD7CD00A777FE /* XPMineRechargeViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineRechargeViewController.h; sourceTree = "<group>"; };
E8B846CA26FDD7CD00A777FE /* XPMineRechargeViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineRechargeViewController.m; sourceTree = "<group>"; };
E8B846CD26FDD96100A777FE /* XPMineRechageHeadView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineRechageHeadView.h; sourceTree = "<group>"; };
E8B846CE26FDD96100A777FE /* XPMineRechageHeadView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineRechageHeadView.m; sourceTree = "<group>"; };
E8B846D126FDDBE600A777FE /* XPMineRechargeTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineRechargeTableViewCell.h; sourceTree = "<group>"; };
@@ -4836,7 +4827,6 @@
E82D5C77276B25B000858D6D /* SpriteSheetManager */,
E865964E2701A1A900846EBD /* StatisticsService */,
E89DA6612700590A008483C1 /* IAPHelper */,
E8B846B926FD7BE600A777FE /* UploadImage */,
E8EEB8EA26FC2050007C6EBA /* SDPhotoBrowser */,
2331C1BA2A60F67F00E1D940 /* UILabel */,
E81366E426F0A4820076364C /* NSString */,
@@ -9407,8 +9397,6 @@
E89DA6612700590A008483C1 /* IAPHelper */ = {
isa = PBXGroup;
children = (
E89DA66227005931008483C1 /* XPIAPHelper.h */,
E89DA66327005932008483C1 /* XPIAPHelper.m */,
E89DA66527006443008483C1 /* RechargeStorage.h */,
E89DA66627006443008483C1 /* RechargeStorage.m */,
);
@@ -9868,20 +9856,9 @@
path = Model;
sourceTree = "<group>";
};
E8B846B926FD7BE600A777FE /* UploadImage */ = {
isa = PBXGroup;
children = (
E8B846BA26FD7C1200A777FE /* UploadImage.h */,
E8B846BB26FD7C1200A777FE /* UploadImage.m */,
);
path = UploadImage;
sourceTree = "<group>";
};
E8B846C826FDD79700A777FE /* Recharge */ = {
isa = PBXGroup;
children = (
E8B846C926FDD7CD00A777FE /* XPMineRechargeViewController.h */,
E8B846CA26FDD7CD00A777FE /* XPMineRechargeViewController.m */,
1464C5F129A4C18000AF7C94 /* XPIAPRechargeViewController.h */,
1464C5F229A4C18000AF7C94 /* XPIAPRechargeViewController.m */,
1464C5F429A4CA8C00AF7C94 /* XPIAPRechargeCollectionViewCell.h */,
@@ -10880,7 +10857,6 @@
E85E7B112A4EB0D200B6D00A /* GuildPersonIncomeRecordModel.m in Sources */,
9BD2ECD2288F833B00F5CD9A /* XPMineFootPrintModel.m in Sources */,
E824546626F5FF6000BE8163 /* XPMineResetPayPasswordProtocol.h in Sources */,
E89DA66427005932008483C1 /* XPIAPHelper.m in Sources */,
23D321E22ADFD0FB006B259C /* PIRedPacketChooseTypeCell.m in Sources */,
E824545E26F5EF2200BE8163 /* XPMineVerifIdentityProtocol.h in Sources */,
E824545326F5CEAD00BE8163 /* XPMineModifPayProtocol.h in Sources */,
@@ -11048,7 +11024,6 @@
238B37BD2AC55A2C00BFC9D5 /* XPTreasureFairyTrialsContentView.m in Sources */,
E85E7B262A4EB0D300B6D00A /* XPMineGuildViewController.m in Sources */,
E85E7B672A4EC35A00B6D00A /* XPBindExtractInfoModel.m in Sources */,
E8B846CB26FDD7CD00A777FE /* XPMineRechargeViewController.m in Sources */,
E86596512701A1C000846EBD /* StatisticsService.m in Sources */,
23CEFC5E2AFB8FC100576D89 /* BSRealTimeView.m in Sources */,
E824544026F58F9400BE8163 /* XPMinePayPwdViewController.m in Sources */,
@@ -11818,7 +11793,6 @@
E81060E229876E9100B772F0 /* MessageImageModel.m in Sources */,
E839533F276A0CDB00CF2F24 /* XPMineNameplateTableViewCell.m in Sources */,
E80E09AE2A41336500CD2BE7 /* XPWebViewNavView.m in Sources */,
E8B846BC26FD7C1200A777FE /* UploadImage.m in Sources */,
E85E7B2D2A4EB0D300B6D00A /* XPGuildHeaderView.m in Sources */,
E85E7B542A4EB4AD00B6D00A /* XPMineGuildListModel.m in Sources */,
9BCE6144277D657600CC0358 /* XPReleaseRadioTableViewCell.m in Sources */,

View File

@@ -7,7 +7,6 @@
#import "AppDelegate+ThirdConfig.h"
///Third
#import <QCloudCOSXML/QCloudCOSXML.h>
#import <NIMSDK/NIMSDK.h>
#import <ShareSDK/ShareSDK.h>
#import <UserNotifications/UNUserNotificationCenter.h>
@@ -28,7 +27,6 @@
#import <Adjust/Adjust.h>
#import <UserNotifications/UserNotifications.h>
#import <Bugly/Bugly.h>
#import "YuMi-swift.h"
@@ -50,6 +48,7 @@ UIKIT_EXTERN NSString * adImageName;
[self configAdjust];
[self configBugly];
[self registerNot];
}
-(void)registerNot{
if (@available(iOS 10.0, *)) {
@@ -68,9 +67,7 @@ UIKIT_EXTERN NSString * adImageName;
}
}
-(void)initQCloud{
}
/**
Bugly
*/

View File

@@ -53,4 +53,5 @@ typedef NS_ENUM(NSUInteger, GradientType) {
-(UIImage *)compressWithMaxLength:(NSUInteger)maxLength;
- (UIImage *)roundedImageWithCornerRadius:(CGFloat)cornerRadius size:(CGSize)size;
+(UIImage *)getImageFromView:(UIView *)view;
+ (NSString *)getImageTypeWithImageData: (NSData *)data;
@end

View File

@@ -451,4 +451,52 @@ UIGraphicsEndImageContext();
// 6.
return image;
}
+ (NSString *)getImageTypeWithImageData:(NSData *)data {
uint8_t c;
[data getBytes:&c length:1];
switch (c) {
case 0xFF:
return @"jpeg";
case 0x89:
return @"png";
case 0x47:
return @"gif";
case 0x49:
case 0x4D:
return @"tiff";
case 0x52:
if ([data length] < 12) {
return nil;
}
NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
return @"webp";
}
return nil;
}
return nil;
}
@end

View File

@@ -25,7 +25,7 @@
///View
#import "XPRoomViewController.h"
#import "XPWebViewController.h"
#import "XPMineRechargeViewController.h"
#import "XPIAPRechargeViewController.h"
#import "XPMineUserInfoViewController.h"
#import "XPMineSimpleUserInfoViewController.h"
@@ -143,7 +143,6 @@
case SecretaryRouterType_Purse:
case SecretaryRouterType_Recharge:
{
// XPMineRechargeViewController * rechargeVC = [[XPMineRechargeViewController alloc] init];
XPIAPRechargeViewController * rechargeVC = [[XPIAPRechargeViewController alloc] init];
rechargeVC.type = @"4";
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:rechargeVC animated:YES];

View File

@@ -112,9 +112,7 @@ NS_ASSUME_NONNULL_BEGIN
password:(NSString *)password
status:(NSNumber *)status
uid:(NSString *)uid;
/// 上传七牛获取token
/// @param complection 完成
+ (void)qiniuUpLoadImage:(HttpRequestHelperCompletion)complection;
/// 上传用户图像到服务器
/// @param complection 完成

View File

@@ -133,12 +133,7 @@
[self makeRequest:fang method:HttpRequestHelperMethodPOST completion:completion, __FUNCTION__, password,status,uid, nil];
}
/// token
/// @param completion
+ (void)qiniuUpLoadImage:(HttpRequestHelperCompletion)completion {
NSString * fang = [NSString stringFromBase64String:@"cWluaXUvdXBsb2FkL2dldFVwbG9hZFRva2Vu"];///qiniu/upload/getUploadToken
[self makeRequest:fang method:HttpRequestHelperMethodGET completion:completion, __FUNCTION__, nil];
}
///
+ (void)getQCloudInfo:(HttpRequestHelperCompletion)completion{
[self makeRequest:@"tencent/cos/getToken" method:HttpRequestHelperMethodGET completion:completion, __FUNCTION__, nil];

View File

@@ -10,7 +10,7 @@
#import "Api+Mine.h"
///Tool
#import "AccountInfoStorage.h"
#import "UploadImage.h"
#import "UploadFile.h"
///Model
#import "XPMineUserInfoEditModel.h"
#import "UserInfoModel.h"
@@ -122,16 +122,14 @@
///
/// @param avatar
- (void)uploadAvatar:(UIImage *)avatar {
[Api qiniuUpLoadImage:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSString *key = data.data[@"key"];
NSString *token = data.data[@"token"];
[UploadImage uploadImage:avatar named:key token:token success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
NSString *url = resp[@"path"];
[[self getView] uploadImageSuccess:url];
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
[[self getView] showErrorToast:YMLocalizedString(@"XPMineUserInfoEditPresenter0")];
}];
}]];
NSData *data = UIImageJPEGRepresentation(avatar, 0.5);
NSString *format = [UIImage getImageTypeWithImageData:data];
NSString *name = [NSString stringWithFormat:@"image/%@.%@",[NSString createUUID],format];
[[UploadFile share]QCloudUploadImage:data named:name success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
[[self getView] uploadImageSuccess:key];
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
}];
}
///

View File

@@ -69,18 +69,12 @@
///
/// @param filePath
- (void)uploadVoice:(NSString *)filePath {
[Api qiniuUpLoadImage:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSString *key = data.data[@"key"];
NSString *token = data.data[@"token"];
[UploadFile uploadFile:filePath named:key token:token success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
NSString *url = resp[@"path"];
[[self getView] uploadVoiceFileToThirdSuccess:url];
NSString *name = [NSString stringWithFormat:@"file/%@",[NSString createUUID]];
[[UploadFile share]QCloudUploadFile:filePath named:name success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
[[self getView] uploadVoiceFileToThirdSuccess:key];
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
[[self getView] uploadVoiceFileFail:message];
}];
} fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] uploadVoiceFileFail:msg];
}showLoading:NO]];
}
-(void)saveSoundWithUrl:(NSString *)audioUrl second:(NSString *)second{
[Api saveSoundCardInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {

View File

@@ -12,7 +12,7 @@
#import "UserInfoModel.h"
///Tool
#import "AccountInfoStorage.h"
#import "UploadImage.h"
#import "UploadFile.h"
///P
#import "XPMineUserInfoAlbumProtocol.h"
@@ -40,16 +40,15 @@
///
/// @param albumImage image
- (void)uploadAlbumImage:(UIImage *)albumImage {
[Api qiniuUpLoadImage:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSString *key = data.data[@"key"];
NSString *token = data.data[@"token"];
[UploadImage uploadImage:albumImage named:key token:token success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
NSString *url = resp[@"path"];
[[self getView] uploadAlbumImageToThirdSuccess:url];
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
[[self getView] showErrorToast:YMLocalizedString(@"XPMineUserInfolbumPresenter0")];
}];
} showLoading:YES]];
NSData *data = UIImageJPEGRepresentation(albumImage, 0.5);
NSString *format = [UIImage getImageTypeWithImageData:data];
NSString *name = [NSString stringWithFormat:@"image/%@.%@",[NSString createUUID],format];
[[UploadFile share]QCloudUploadImage:data named:name success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
[[self getView] uploadAlbumImageToThirdSuccess:key];
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
}];
}

View File

@@ -27,7 +27,7 @@
#import "XPWebViewController.h"
#import "XPMineDressUpViewController.h"
#import "XPDressUpShopCardViewController.h"
#import "XPMineRechargeViewController.h"
#import "XPIAPRechargeViewController.h"
@interface XPDressUpShopViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate, SDCycleScrollViewDelegate>
@@ -233,7 +233,6 @@
}
- (void)rechargeButtonAction:(UIButton *)sender {
// XPMineRechargeViewController *vc = [[XPMineRechargeViewController alloc] init];
XPIAPRechargeViewController * rechargeVC = [[XPIAPRechargeViewController alloc] init];
rechargeVC.type = @"4";
[self.navigationController pushViewController:rechargeVC animated:YES];

View File

@@ -1,16 +0,0 @@
//
// YMMineRechargeViewController.h
// YUMI
//
// Created by YUMI on 2021/9/24.
//
#import "MvpViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface XPMineRechargeViewController : MvpViewController
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,318 +0,0 @@
//
// YMMineRechargeViewController.m
// YUMI
//
// Created by YUMI on 2021/9/24.
//
#import "XPMineRechargeViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <Base64/MF_Base64Additions.h>
///Tool
#import "DJDKMIMOMColor.h"
#import "YUMIMacroUitls.h"
#import "YUMIHtmlUrl.h"
#import "XPIAPHelper.h"
#import "RechargeStorage.h"
#import "AccountInfoStorage.h"
#import "NSObject+MJExtension.h"
#import "NSArray+Safe.h"
///Model
#import "RechargeListModel.h"
///View
#import "XPMineRechageHeadView.h"
#import "XPMineRechargeTableViewCell.h"
#import "XPMineRechargeNavView.h"
///P
#import "XPMineRechargePresenter.h"
#import "XPMineRechargeProtocol.h"
///VC
#import "XPWebViewController.h"
@interface XPMineRechargeViewController ()<XPMineRechargeProtocol, UITableViewDelegate, UITableViewDataSource, XPMineRechargeTableViewCellDelegate, XPIAPHelperDelegate, XPMineRechargeNavViewDelegate>
///
@property (nonatomic,strong) NSArray *datasource;
///
@property (nonatomic,strong) UITableView *tableView;
///
@property (nonatomic,strong) XPMineRechageHeadView *headeView;
///
@property (nonatomic,copy) NSString *orderId;
///
@property (nonatomic,strong) XPMineRechargeNavView *navView;
///
@property (nonatomic,strong) UIStackView *stackView;
///
@property (nonatomic,strong) UILabel *agreeLabel;
///
@property (nonatomic,strong) UIButton *protcoloButton;
@end
@implementation XPMineRechargeViewController
- (void)dealloc {
[XPIAPHelper shareHelper].delegate = nil;
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (XPMineRechargePresenter *)createPresenter {
return [[XPMineRechargePresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initHttpData];
[self initSubViews];
[self initSubViewConstraints];
}
#pragma mark - Response
- (void)protcoloButtonAction:(UIButton *)sender {
XPWebViewController * webVC= [[XPWebViewController alloc] init];
webVC.url = URLWithType(kRechargePrivacyURL);
[self.navigationController pushViewController:webVC animated:YES];
}
#pragma mark - Private Method
- (void)initSubViews {
[self.view addSubview:self.tableView];
[self.view addSubview:self.navView];
[self.view addSubview:self.stackView];
[self.stackView addArrangedSubview:self.agreeLabel];
[self.stackView addArrangedSubview:self.protcoloButton];
self.tableView.tableHeaderView = self.headeView;
[XPIAPHelper shareHelper].delegate = self;
self.automaticallyAdjustsScrollViewInsets = NO;
}
- (void)initSubViewConstraints {
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.view).offset(-20 - kSafeAreaBottomHeight);
}];
[self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self.view);
make.height.mas_equalTo(kNavigationHeight);
}];
}
- (void)initHttpData {
[self getRechargeList];
[self getUserWalletBalanceInfo];
[self checkTranscationIds];
}
- (void)getRechargeList {
[self.presenter requestRechargeListWithChannel:@"8"];
}
- (void)getUserWalletBalanceInfo {
[self.presenter getUserWalletInfo];
}
///
- (void)checkTranscationIds {
NSString * uid = [AccountInfoStorage instance].getUid;
NSArray * array = [RechargeStorage getAllReciptsWithUid:uid];
if (array.count > 0) {
[self.presenter checkTranscationIds:array];
}
}
///
- (void)saveRechageReciptWithTransactionIdentifier:(NSString *)transactionIdentifier {
NSData *receipt = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
NSString *encodeStr = [receipt base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
if(transactionIdentifier != nil){
[dictionary setObject:transactionIdentifier forKey:@"transcationId"];
}
if(encodeStr != nil){
[dictionary setObject:encodeStr forKey:@"recipt"];
}
if(self.orderId != nil){
[dictionary setObject:self.orderId forKey:@"orderId"];
}
if(dictionary.allKeys.count == 0)return;
NSString *reciptJson = [dictionary toJSONString];
NSString * uid = [AccountInfoStorage instance].getUid;
BOOL saveSuccess = [RechargeStorage saveTranscationId:transactionIdentifier recipt:reciptJson uid:uid];
if (!saveSuccess) {
#warning to do
}
}
///
- (void)deleteRechageReciptWithTransactionIdentifier:(NSString *)transactionIdentifier {
NSString * uid = [AccountInfoStorage instance].getUid;
BOOL deleteSuccess = [RechargeStorage delegateTranscationId:transactionIdentifier uid:uid];
if (deleteSuccess) {
#warning to do
}
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.datasource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
XPMineRechargeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineRechargeTableViewCell class]) forIndexPath:indexPath];
cell.listModel = [self.datasource safeObjectAtIndex1:indexPath.row];
cell.delegate = self;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 65;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:true];
}
#pragma mark - XPMineRechargeTableViewCellDelegate
- (void)xPMineRechargeTableViewCell:(XPMineRechargeTableViewCell *)cell didSelectItem:(RechargeListModel *)listModel {
if (listModel.chargeProdId) {
[self showLoading];
[self.presenter requestIAPRechargeOrderWithChargeProdId:listModel.chargeProdId];
}
}
#pragma mark - XPMineRechargeNavViewDelegate
- (void)xPMineRechargeNavView:(XPMineRechargeNavView *)view didClickBackButton:(UIButton *)sender {
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - XPIAPHelperDelegate
///
- (void)rechargeProcessStatus:(PaymentStatus)status {
[self hideHUD];
if (status == PaymentStatus_Purchased) {
[self showLoading];
} else if (status == PaymentStatus_Purchasing) {
[self showLoading];
} else if (status == PaymentStatus_Failed) {
[self showErrorToast:YMLocalizedString(@"XPMineRechargeViewController0")];
} else if (status == PaymentStatus_Deferred) {
[self showErrorToast:YMLocalizedString(@"XPMineRechargeViewController1")];
}
}
///id
- (void)rechargeSuccess:(NSString *)transactionIdentifier {
///
[self saveRechageReciptWithTransactionIdentifier:transactionIdentifier];
NSData *receiptData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
NSString * receipt = [MF_Base64Codec base64StringFromData:receiptData];
///
// [self.presenter checkReceiptWithData:receipt orderId:self.orderId transcationId:transactionIdentifier];
}
#pragma mark - XPMineRechargeProtocol
- (void)requestRechargeListSucccess:(NSArray *)list {
self.datasource = list;
[self.tableView reloadData];
}
- (void)requestIAPRechargeOrderSuccess:(NSString *)orderId chargeProdId:(NSString *)chargeProdId {
if (orderId.length > 0) {
self.orderId = orderId;
[[XPIAPHelper shareHelper] buyAppProductWithAppProductId:chargeProdId];
}
}
- (void)requestIAPRechargeOrderFail {
///
}
///
- (void)checkReceiptSuccess:(NSString *)transcationId {
[self deleteRechageReciptWithTransactionIdentifier:transcationId];
///💎
[self getUserWalletBalanceInfo];
self.orderId = nil;
}
- (void)getUserWalletInfo:(WalletInfoModel *)balanceInfo {
self.headeView.walletInfo = balanceInfo;
}
- (void)checkTranscationIdsSuccess {
NSString * uid = [AccountInfoStorage instance].getUid;
[RechargeStorage delegateAllTranscationIdsWithUid:uid];
}
#pragma mark - Getters And Setters
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.tableFooterView = [UIView new];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor clearColor];
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_tableView registerClass:[XPMineRechargeTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineRechargeTableViewCell class])];
}
return _tableView;
}
- (XPMineRechageHeadView *)headeView {
if (!_headeView) {
_headeView = [[XPMineRechageHeadView alloc] init];
}
return _headeView;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentFill;
_stackView.spacing = 2;
}
return _stackView;
}
- (UIButton *)protcoloButton {
if (!_protcoloButton) {
_protcoloButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_protcoloButton setTitle:YMLocalizedString(@"XPIAPRechargeViewController3") forState:UIControlStateNormal];
[_protcoloButton setTitleColor:[DJDKMIMOMColor appMainColor] forState:UIControlStateNormal];
_protcoloButton.titleLabel.font = [UIFont systemFontOfSize:12];
[_protcoloButton addTarget:self action:@selector(protcoloButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _protcoloButton;
}
- (UILabel *)agreeLabel {
if (!_agreeLabel) {
_agreeLabel = [[UILabel alloc] init];
_agreeLabel.text = YMLocalizedString(@"XPMineRechargeViewController3");
_agreeLabel.font = [UIFont systemFontOfSize:12];
_agreeLabel.textColor = [DJDKMIMOMColor textThirdColor];
}
return _agreeLabel;
}
- (XPMineRechargeNavView *)navView {
if (!_navView) {
_navView = [[XPMineRechargeNavView alloc] init];
_navView.delegate = self;
}
return _navView;
}
@end

View File

@@ -40,7 +40,7 @@
///VC
#import "XPMineSettingViewController.h"
#import "XPMineUserInfoViewController.h"
#import "XPMineRechargeViewController.h"
#import "XPWebViewController.h"
#import "XPRoomViewController.h"
#import "XPMineDressUpViewController.h"
@@ -224,7 +224,6 @@ UIKIT_EXTERN NSString *kRequestRicket;
case XPMineItemType_Account:
{
// XPMineRechargeViewController * rechargeVC
[self pushThirdPartyPayVC];
}
break;

View File

@@ -43,7 +43,7 @@
#import "XPMineSettingViewController.h"
#import "XPMineUserInfoViewController.h"
#import "XPMineSimpleUserInfoViewController.h"
#import "XPMineRechargeViewController.h"
#import "XPIAPRechargeViewController.h"
#import "XPWebViewController.h"
#import "XPRoomViewController.h"
@@ -137,7 +137,6 @@
break;
case XPMineItemType_Account:
{
// XPMineRechargeViewController * rechargeVC = [[XPMineRechargeViewController alloc] init];
XPIAPRechargeViewController *rechargeVC = [[XPIAPRechargeViewController alloc] init];
rechargeVC.type = @"4";
[self.navigationController pushViewController:rechargeVC animated:YES];

View File

@@ -15,7 +15,7 @@
#import "DJDKMIMOMColor.h"
#import "UIImage+Utils.h"
#import "Api+Mine.h"
#import "UploadImage.h"
#import "UploadFile.h"
#import "TTPopup.h"
#import "NSArray+Safe.h"
#import "ClientConfig.h"
@@ -173,55 +173,49 @@
}
- (void)uploadAlbumPicList:(NSArray *)array finish:(void(^)(NSArray *list))finish {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
NSMutableArray * dataArray = [NSMutableArray array];
dispatch_async(queue, ^{
for (UIImage * image in array) {
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
[Api qiniuUpLoadImage:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
NSString *key = data.data[@"key"];
NSString *token = data.data[@"token"];
[UploadImage uploadImage:image named:key token:token success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
dispatch_semaphore_signal(semaphore);
self.imageCount ++;
NSMutableDictionary * dict= [NSMutableDictionary dictionary];
MonentsPicResInfo * infor = [MonentsPicResInfo modelWithDictionary:resp];
if (infor.path) {
[dict safeSetObject:infor.path forKey:@"resUrl"];
}
if (infor.format) {
[dict safeSetObject:infor.format forKey:@"format"];
}
if (infor.w) {
[dict safeSetObject:@(infor.w) forKey:@"width"];
}
if (infor.h) {
[dict safeSetObject:@(infor.h) forKey:@"height"];
}
[dataArray addObject:dict];
if (self.imageCount == array.count) {
dispatch_async(dispatch_get_main_queue(), ^{
finish(dataArray);
});
}
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
self.imageCount ++;
dispatch_semaphore_signal(semaphore);
}];
} else {
self.imageCount ++;
dispatch_semaphore_signal(semaphore);
}
}];
NSData *data = UIImageJPEGRepresentation(image, 0.5);
NSString *format = [UIImage getImageTypeWithImageData:data];
NSString *name = [NSString stringWithFormat:@"image/%@.%@",[NSString createUUID],format];
[[UploadFile share]QCloudUploadImage:data named:name success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
dispatch_semaphore_signal(semaphore);
self.imageCount ++;
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if (image.size.width > 0){
[dict safeSetObject:@(image.size.width) forKey:@"width"];
}
if (image.size.height){
[dict safeSetObject:@(image.size.height) forKey:@"height"];
}
if (key.length > 0) {
[dict safeSetObject:key forKey:@"resUrl"];
}
[dict safeSetObject:format forKey:@"format"];
[dataArray addObject:dict];
if (self.imageCount == array.count) {
dispatch_async(dispatch_get_main_queue(), ^{
finish(dataArray);
});
}
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
self.imageCount ++;
dispatch_semaphore_signal(semaphore);
}];
}
});
}
#pragma mark - UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView {
if (textView.text.length > 500) {

View File

@@ -30,7 +30,7 @@
#import "XPFirstRechargePresenter.h"
#import "XPFirstRechargeProtocol.h"
///VC
#import "XPMineRechargeViewController.h"
#import "XPWebViewController.h"
#import "XPFirstRechargeView.h"

View File

@@ -10,7 +10,7 @@
#import "PIRoomPhotoAlbumChoosePhotoView.h"
#import "XPGuildEmptyCollectionViewCell.h"
#import "TZImagePickerController.h"
#import "UploadImage.h"
#import "UploadFile.h"
#import "Api+Mine.h"
#import "MonentsPicResInfo.h"
#import "PIRoomPhotoAlbumOperateView.h"
@@ -279,36 +279,41 @@
}
///
- (void)uploadAlbumPicList:(NSArray *)array finish:(void(^)(NSArray *list))finish {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
NSMutableArray * dataArray = [NSMutableArray array];
dispatch_async(queue, ^{
for (UIImage * image in array) {
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
[Api qiniuUpLoadImage:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
NSString *key = data.data[@"key"];
NSString *token = data.data[@"token"];
[UploadImage uploadImage:image named:key token:token success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
dispatch_semaphore_signal(semaphore);
self.imageCount ++;
if(resp[@"path"] != nil){
[dataArray addObject:resp[@"path"]];
}
if (self.imageCount == array.count) {
dispatch_async(dispatch_get_main_queue(), ^{
finish(dataArray);
});
}
NSData *data = UIImageJPEGRepresentation(image, 0.5);
NSString *format = [UIImage getImageTypeWithImageData:data];
NSString *name = [NSString stringWithFormat:@"image/%@.%@",[NSString createUUID],format];
[[UploadFile share]QCloudUploadImage:data named:name success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
dispatch_semaphore_signal(semaphore);
self.imageCount ++;
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if (image.size.width > 0){
[dict safeSetObject:@(image.size.width) forKey:@"width"];
}
if (image.size.height){
[dict safeSetObject:@(image.size.height) forKey:@"height"];
}
if (key.length > 0) {
[dict safeSetObject:key forKey:@"resUrl"];
}
[dict safeSetObject:format forKey:@"format"];
[dataArray addObject:dict];
if (self.imageCount == array.count) {
dispatch_async(dispatch_get_main_queue(), ^{
finish(dataArray);
});
}
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
self.imageCount ++;
dispatch_semaphore_signal(semaphore);
}];
} else {
self.imageCount ++;
dispatch_semaphore_signal(semaphore);
}
}];
}
});
}

View File

@@ -43,7 +43,7 @@
///P
#import "XPGiftProtocol.h"
///VC
#import "XPMineRechargeViewController.h"
#import "XPIAPRechargeViewController.h"
#import "XPWebViewController.h"
#import "PIGiftSuperGiftBroadcastView.h"
@@ -453,7 +453,6 @@ UIKIT_EXTERN NSString * kShowFirstRechargeView;
///
- (void)xPGiftBarViewDidClickRecharge:(XPGiftBarView *)view {
[self dismissViewControllerAnimated:NO completion:^{
// XPMineRechargeViewController * rechargeVC = [[XPMineRechargeViewController alloc] init];
XPIAPRechargeViewController * rechargeVC = [[XPIAPRechargeViewController alloc] init];
rechargeVC.type = @"4";
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:rechargeVC animated:YES];

View File

@@ -20,7 +20,7 @@
#import "XPRoomRedPacketPwdView.h"
#import "XPMinePayPwdViewController.h"
#import "BaseNavigationController.h"
#import "XPMineRechargeViewController.h"
#import "XPIAPRechargeViewController.h"
#import "XPRoomHalfWebView.h"
///P
@@ -403,7 +403,6 @@
}
- (void)onRechargeButtonClick:(UIButton *)sender {
// XPMineRechargeViewController *rechargeVC = [[XPMineRechargeViewController alloc] init];
XPIAPRechargeViewController * rechargeVC = [[XPIAPRechargeViewController alloc] init];
rechargeVC.type = @"4";
[self.navigationController pushViewController:rechargeVC animated:YES];

View File

@@ -83,7 +83,7 @@
#import "PIFullScreenBannerAnimation.h"
#import <SVGA.h>
#import "Api+Gift.h"
#import "UploadFile.h"
@@ -214,6 +214,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
- (void)autoLoginSuccess {
[self.presenter loginNIM];
[self.presenter getUserInfo];
[[UploadFile share]initQCloud];
///
[self.presenter checkTranscation];
///

View File

@@ -17,7 +17,7 @@
#import <MJExtension/MJExtension.h>
#import "XCCurrentVCStackManager.h"
#import "XPMineUserInfoViewController.h"
#import "XPMineRechargeViewController.h"
///vc
#import "XPMineDressUpViewController.h"
#import "XPDressUpShopViewController.h"

View File

@@ -11,18 +11,30 @@ NS_ASSUME_NONNULL_BEGIN
@interface UploadFile : NSObject
+ (instancetype)share;
-(void)initQCloud;
+ (void)downloadAudioWithFileName:(NSString *)fileName musicUrl:(NSString *)musicUrl mainFileName:(NSString *)mainFileName completion:(void (^) (BOOL isSuccess, NSString *editAudioPath))completion;
/// 上传一个文件
/// @param filePath 文件地址
/// @param fileName 文件的名字
/// @param token token
/// @param success 成功
/// @param failure 失败
+ (void)uploadFile:(NSString *)filePath
- (void)QCloudUploadFile:(NSString *)filePath
named:(NSString *)fileName
token:(NSString *)token
success:(void (^)(NSString *key, NSDictionary *resp))success
failure:(void (^)(NSNumber *resCode, NSString *message))failure;
+ (void)downloadAudioWithFileName:(NSString *)fileName musicUrl:(NSString *)musicUrl mainFileName:(NSString *)mainFileName completion:(void (^) (BOOL isSuccess, NSString *editAudioPath))completion;
failure:(void (^)(NSNumber *resCode, NSString *message))failure;
/// 上传一个Image
/// @param image 图片
/// @param imageName 图片的名字
/// @param success 成功
/// @param failure 失败
- (void)QCloudUploadImage:(NSData *)data
named:(NSString *)name
success:(void (^)(NSString *key, NSDictionary *resp))success
failure:(void (^)(NSNumber *resCode, NSString *message))failure;
@end
NS_ASSUME_NONNULL_END

View File

@@ -6,13 +6,14 @@
//
#import <QCloudCOSXML/QCloudCOSXML.h>
#import "UploadFile.h"
#import <Qiniu/QiniuSDK.h>
#import <AFNetworking.h>
#import "Api+Mine.h"
#import "UploadFileModel.h"
static UploadFile* manager;
@interface UploadFile()<QCloudSignatureProvider>
@interface UploadFile()<QCloudSignatureProvider,QCloudCredentailFenceQueueDelegate>
//
@property (nonatomic) QCloudCredentailFenceQueue* credentialFenceQueue;
@property(nonatomic,strong) UploadFileModel *fileModel;
@end
@@ -32,13 +33,11 @@ static UploadFile* manager;
UploadFileModel *fileModel = [UploadFileModel modelWithDictionary:data.data];
self.fileModel = fileModel;
QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];
configuration.appID = fileModel.appId;
QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] init];
endpoint.regionName = fileModel.region;
// 使 HTTPS
endpoint.useHTTPS = true;
endpoint.useHTTPS = YES;
configuration.endpoint = endpoint;
//
configuration.signatureProvider = self;
@@ -46,6 +45,9 @@ static UploadFile* manager;
[QCloudCOSXMLService registerDefaultCOSXMLWithConfiguration:configuration];
[QCloudCOSTransferMangerService registerDefaultCOSTransferMangerWithConfiguration:
configuration];
self.credentialFenceQueue = [QCloudCredentailFenceQueue new];
self.credentialFenceQueue.delegate = self;
}
}];
@@ -57,60 +59,164 @@ static UploadFile* manager;
compelete:(QCloudHTTPAuthentationContinueBlock)continueBlock
{
[Api getQCloudInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200){
UploadFileModel *fileModel = [UploadFileModel modelWithDictionary:data.data];
QCloudCredential* credential = [QCloudCredential new];
// SecretId
// sercret_id SecretId访https://console.cloud.tencent.com/cam/capi
credential.secretID = self.fileModel.secretId;
credential.secretID = fileModel.secretId;
// SecretKey
// sercret_key SecretKey访https://console.cloud.tencent.com/cam/capi
credential.secretKey = self.fileModel.secretKey;
credential.secretKey = fileModel.secretKey;
// Token
// 使token使使https://cloud.tencent.com/document/product/436/14048
credential.token = self.fileModel.sessionToken;
credential.token = fileModel.sessionToken;
/** , (startTimeexpiredTime)
*/
credential.startDate = [NSDate dateWithTimeIntervalSince1970:self.fileModel.startTime]; //
credential.expirationDate = [NSDate dateWithTimeIntervalSince1970:self.fileModel.startTime];//
*/
credential.startDate = [NSDate dateWithTimeIntervalSince1970:fileModel.startTime]; //
credential.expirationDate = [NSDate dateWithTimeIntervalSince1970:fileModel.expireTime];//
QCloudAuthentationV5Creator* creator = [[QCloudAuthentationV5Creator alloc]
initWithCredential:credential];
initWithCredential:credential];
// urlRequst copymutableCopy
QCloudSignature *signature = [creator signatureForData:urlRequst];
continueBlock(signature, nil);
}
}
];
}
#pragma mark - QCloudCredentailFenceQueueDelegate
- (void) fenceQueue:(QCloudCredentailFenceQueue * )queue requestCreatorWithContinue:(QCloudCredentailFenceQueueContinue)continueBlock
{
//
//...
//zoneAs0
[Api getQCloudInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200){
UploadFileModel *fileModel = [UploadFileModel modelWithDictionary:data.data];
QCloudCredential* credential = [QCloudCredential new];
// SecretId
credential.secretID = fileModel.secretId;
// SecretKey
credential.secretKey = fileModel.secretKey;
// Token
credential.token = fileModel.sessionToken;
/** , (startTimeexpiredTime)
*/
credential.startDate = [NSDate dateWithTimeIntervalSince1970:fileModel.startTime]; //
credential.expirationDate = [NSDate dateWithTimeIntervalSince1970:fileModel.expireTime];//
QCloudAuthentationV5Creator* creator = [[QCloudAuthentationV5Creator alloc]
initWithCredential:credential];
continueBlock(creator, nil);
}
}];
}
///
/// @param filePath
/// @param fileName
/// @param token token
/// @param success
/// @param failure
+ (void)uploadFile:(NSString *)filePath
- (void)QCloudUploadFile:(NSString *)filePath
named:(NSString *)fileName
token:(NSString *)token
success:(void (^)(NSString *key, NSDictionary *resp))success
failure:(void (^)(NSNumber *resCode, NSString *message))failure {
QNConfiguration *config = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
builder.zone = [QNFixedZone zoneAs0];
failure:(void (^)(NSNumber *resCode, NSString *message))failure {
QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];
//
NSURL* url = [NSURL fileURLWithPath:filePath];
// BucketName-Appid COS https://console.cloud.tencent.com/cos5/bucket
put.bucket = self.fileModel.bucket;
// COS "video/xxx/movie.mp4"
put.object = fileName;
//NSData*NSURL*
put.body = url;
//
[put setSendProcessBlock:^(int64_t bytesSent,
int64_t totalBytesSent,
int64_t totalBytesExpectedToSend) {
// bytesSent
// totalBytesSent
// totalBytesExpectedToSend
}];
QNUploadManager *upManager = [[QNUploadManager alloc] initWithConfiguration:config];
[upManager putFile:filePath key:fileName token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
if (resp) {
success(key,resp);
}else{
failure(@(info.statusCode),info.error.localizedDescription);
//
[put setFinishBlock:^(id outputObject, NSError *error) {
// outputObject response etag
if (error) {
failure(@(error.code),error.localizedDescription);
return;
}
} option:nil];
QCloudUploadObjectResult * result = (QCloudUploadObjectResult *)outputObject;
NSArray *urlList = [result.location componentsSeparatedByString:@".com/"];
if (urlList.count == 2){
NSString *url = [NSString stringWithFormat:@"%@/%@",self.fileModel.customDomain,urlList[1]];
success(url,nil);
return;
}
success(result.location,nil);
}];
[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];
}
/// Image
/// @param image
/// @param imageName
/// @param success
/// @param failure
- (void)QCloudUploadImage:(NSData *)data
named:(NSString *)name
success:(void (^)(NSString *key, NSDictionary *resp))success
failure:(void (^)(NSNumber *resCode, NSString *message))failure{
QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];
put.bucket = self.fileModel.bucket;
// COS "video/xxx/movie.mp4"
put.object = name;
//NSData*NSURL*
put.body = data;
//
[put setSendProcessBlock:^(int64_t bytesSent,
int64_t totalBytesSent,
int64_t totalBytesExpectedToSend) {
// bytesSent
// totalBytesSent
// totalBytesExpectedToSend
}];
//
[put setFinishBlock:^(id outputObject, NSError *error) {
if (error) {
failure(@(error.code),error.localizedDescription);
return;
}
QCloudUploadObjectResult * result = (QCloudUploadObjectResult *)outputObject;
NSArray *urlList = [result.location componentsSeparatedByString:@".com/"];
if (urlList.count == 2){
NSString *url = [NSString stringWithFormat:@"%@/%@",self.fileModel.customDomain,urlList[1]];
success(url,nil);
return;
}
success(result.location,nil);
}];
[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];
}
+(void)downloadAudioWithFileName:(NSString *)fileName musicUrl:(NSString *)musicUrl mainFileName:(NSString *)mainFileName completion:(void (^) (BOOL isSuccess, NSString *editAudioPath))completion {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:musicUrl]];

View File

@@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic,copy) NSString *customDomain;
@property(nonatomic,assign) long startTime;
@property(nonatomic,assign) long expireTime;
@property(nonatomic,copy) NSString *appId;
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,36 +0,0 @@
//
// YMIAPHelper.h
// YUMI
//
// Created by YUMI on 2021/9/26.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger ,PaymentStatus) {
PaymentStatus_Purchasing = 1,//付款中
PaymentStatus_Purchased, //付款操作已经完成
PaymentStatus_Failed, //付款操作失败
PaymentStatus_Deferred, //未知状态
};
@protocol XPIAPHelperDelegate <NSObject>
///当前充值的状态
- (void)rechargeProcessStatus:(PaymentStatus)status;
///充值成功回调id
- (void)rechargeSuccess:(NSString *)transactionIdentifier;
@end
@interface XPIAPHelper : NSObject
+ (instancetype)shareHelper;
///代理
@property (nonatomic,weak) id<XPIAPHelperDelegate> delegate;
///购买商品
- (void)buyAppProductWithAppProductId:(NSString *)appProductId;
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,97 +0,0 @@
//
// YMIAPHelper.m
// YUMI
//
// Created by YUMI on 2021/9/26.
//
#import "XPIAPHelper.h"
#import <IAPHelper/IAPHelper.h>
#import <IAPShare.h>
@implementation XPIAPHelper
+ (instancetype)shareHelper {
static dispatch_once_t onceToken;
static XPIAPHelper * helper;
dispatch_once(&onceToken, ^{
helper = [[XPIAPHelper alloc] init];
});
return helper;
}
- (void)buyAppProductWithAppProductId:(NSString *)appProductId {
NSSet* dataSet = [[NSSet alloc] initWithObjects:appProductId, nil];
[IAPShare sharedHelper].iap = [[IAPHelper alloc] initWithProductIdentifiers:dataSet];
[[IAPShare sharedHelper].iap requestProductsWithCompletion:^(SKProductsRequest *request, SKProductsResponse *response) {
if (response != nil && response.products.count) {
///
} else if (!response.products.count) {
///
#warning to do
if (self.delegate && [self.delegate respondsToSelector:@selector(rechargeProcessStatus:)]) {
[self.delegate rechargeProcessStatus:PaymentStatus_Failed];
}
return;
} else if (!response) {
#warning to do
///
if (self.delegate && [self.delegate respondsToSelector:@selector(rechargeProcessStatus:)]) {
[self.delegate rechargeProcessStatus:PaymentStatus_Failed];
}
return;
} else {
#warning to do
///
if (self.delegate && [self.delegate respondsToSelector:@selector(rechargeProcessStatus:)]) {
[self.delegate rechargeProcessStatus:PaymentStatus_Failed];
}
return;
}
if (response.products.firstObject) {
[[IAPShare sharedHelper].iap buyProduct:response.products.firstObject onCompletion:^(SKPaymentTransaction *transcation) {
NSLog(@"%@",transcation.error.description);
switch(transcation.transactionState) {
case SKPaymentTransactionStatePurchased: {
NSLog(@"付款完成状态, 要做出相关的处理");
[[SKPaymentQueue defaultQueue] finishTransaction:transcation];
if (self.delegate && [self.delegate respondsToSelector:@selector(rechargeProcessStatus:)]) {
[self.delegate rechargeProcessStatus:PaymentStatus_Purchased];
}
if (self.delegate && [self.delegate respondsToSelector:@selector(rechargeSuccess:)]) {
[self.delegate rechargeSuccess:transcation.transactionIdentifier];
}
//
}
break;
case SKPaymentTransactionStateFailed: {
[[SKPaymentQueue defaultQueue] finishTransaction:transcation];
if (self.delegate && [self.delegate respondsToSelector:@selector(rechargeProcessStatus:)]) {
[self.delegate rechargeProcessStatus:PaymentStatus_Failed];
}
}
break;
case SKPaymentTransactionStatePurchasing: {
NSLog(@"正在购买中");
if (self.delegate && [self.delegate respondsToSelector:@selector(rechargeProcessStatus:)]) {
[self.delegate rechargeProcessStatus:PaymentStatus_Purchasing];
}
}
break;
default: {
[[SKPaymentQueue defaultQueue] finishTransaction:transcation];
if (self.delegate && [self.delegate respondsToSelector:@selector(rechargeProcessStatus:)]) {
[self.delegate rechargeProcessStatus:PaymentStatus_Deferred];
}
NSLog(@"其它");
}
}
}];
}
}];
}
@end

View File

@@ -37,7 +37,8 @@ NS_ASSUME_NONNULL_BEGIN
+(NSString *)getAgeWithBirth:(long)birth;
///得到区号
+(NSString *)getCountryCode;
///产生唯一的key用于图片或文件上传
+ (NSString *)createUUID;
@end

View File

@@ -255,4 +255,15 @@
if(countryCode.length == 0)return @"+886";
return [NSString stringWithFormat:@"+%@",countryCode];
}
+(NSString *)createUUID{
CFUUIDRef uuid;
CFStringRef uuidText;
uuid = CFUUIDCreate(NULL);
uuidText = CFUUIDCreateString(NULL, uuid);
NSString *time = [NSDate getNowTimeTimestamp];
NSString *result = [NSString stringWithFormat:@"%@%@",uuidText,time];
return [result MD5String];
}
@end