262 lines
8.4 KiB
Objective-C
262 lines
8.4 KiB
Objective-C
// YPTools Auto Update Create Date https://github.com/HansenCCC/YPTools
|
|
// 2023-02-08 17:49:52 +0800
|
|
//
|
|
// THNetworkInterfaceService.m
|
|
// TreeHole
|
|
//
|
|
// Created by iOS on 2023/2/8.
|
|
// Copyright © 2023 CYH. All rights reserved.
|
|
//
|
|
|
|
#import "THNetworkInterfaceService.h"
|
|
#import "NetworkingManager.h"
|
|
|
|
#import "BottleDetialController.h"
|
|
|
|
@implementation THNetworkInterfaceService
|
|
|
|
//这里写公共接口
|
|
|
|
|
|
///获取随机数
|
|
+ (CGFloat)randomBetween:(float)smallerNumber And:(float)largerNumber {
|
|
//设置精确的位数
|
|
int precision = 100;
|
|
//先取得他们之间的差值
|
|
float subtraction = largerNumber - smallerNumber;
|
|
//取绝对值
|
|
subtraction = ABS(subtraction); //ABS整数绝对值
|
|
//乘以精度的位数
|
|
subtraction *= precision;
|
|
//在差值间随机
|
|
float randomNumber = arc4random() % ((int)subtraction+1);
|
|
//随机的结果除以精度的位数
|
|
randomNumber /= precision;
|
|
//将随机的值加到较小的值上
|
|
float result = MIN(smallerNumber, largerNumber) + randomNumber;
|
|
//返回结果
|
|
return result;
|
|
}
|
|
|
|
@end
|
|
|
|
//MARK: - 瓶子
|
|
@implementation THNetworkInterfaceService (Bottle)
|
|
|
|
///是否为交换类型瓶子
|
|
+ (BOOL)isExchangeBottleType:(THBottleType)bottleType {
|
|
BOOL isExchangeType = (bottleType==THBottleType_Exchange_SecretText)||(bottleType==THBottleType_Exchange_Voice)||(bottleType==THBottleType_Exchange_Picture);
|
|
return isExchangeType;
|
|
}
|
|
///查询瓶子类型, 根据后端字符串转换
|
|
+ (THBottleType)inquiryBottleType:(NSString *)typeStr {
|
|
if ([typeStr isEqualToString:@"pic_game_normal"]) {
|
|
//交换照片
|
|
return THBottleType_Exchange_Picture;
|
|
}
|
|
if ([typeStr isEqualToString:@"voice_game_normal"]) {
|
|
//交换声音
|
|
return THBottleType_Exchange_Voice;
|
|
}
|
|
if ([typeStr isEqualToString:@"text_game_secret"]) {
|
|
//交换秘密
|
|
return THBottleType_Exchange_SecretText;
|
|
}
|
|
if ([typeStr isEqualToString:@"voice_game_song"]) {
|
|
//声音瓶
|
|
return THBottleType_TextAndVoice;
|
|
}
|
|
if ([typeStr isEqualToString:@"my_photo"]) {
|
|
//写真瓶
|
|
return THBottleType_TextAndPicture;
|
|
}
|
|
//纯文字
|
|
return THBottleType_Text;
|
|
}
|
|
|
|
|
|
///无瓶子弹框提示
|
|
+ (void)showBottleEmptyAlertViewWithButtonTap:(void(^)(UIButton *sender))tapBlock {
|
|
[MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) {
|
|
config.message = @" 更多推荐瓶子正在来的路上\n酒馆派对正在火热进行中🔥\n快去参与派对查看更多的瓶子吧~";
|
|
config.otherTitle = @"查看更多瓶子";
|
|
config.otherHandler = ^(MTAlertButton *button) {
|
|
if (tapBlock) {
|
|
tapBlock(button);
|
|
}
|
|
};
|
|
}];
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
//MARK: - 首页
|
|
@implementation THNetworkInterfaceService (Home)
|
|
|
|
///获取单个推荐瓶子详情
|
|
+ (void)requestSingleRecommendBottleInfoComplete:(responseDictionaryBlock)complete {
|
|
//老接口
|
|
[PYHTTPManager postWithPath:@"recommend/bottle" params:nil callback:^(id _Nullable rsp, NSError * _Nullable error) {
|
|
if (!error) {
|
|
// NSLog(@"%@数据==%@",url, rsp);
|
|
return;
|
|
}
|
|
if ([rsp isKindOfClass:NSDictionary.class]) {
|
|
NSDictionary *dic = rsp;
|
|
complete(dic, nil);
|
|
return;
|
|
}
|
|
NSAssert(YES, @"返回数据格式不是JSON,解析出错");
|
|
}];
|
|
/*
|
|
[NetworkingManager scheduledGET:@"recommend/bottle" parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, NetResponseModel * _Nullable responseModel) {
|
|
|
|
} failure:nil];
|
|
*/
|
|
}
|
|
|
|
///获取单个瓶子详情
|
|
+ (void)requestSingleBottleInfoComplete:(responseDictionaryBlock)complete {
|
|
|
|
[SVProgressHUD showWithStatus:nil];
|
|
[self requestRecommendBottleIdsWithPageSize:1 complete:^(NSArray * _Nullable responseArrayData, NSError * _Nullable err) {
|
|
NSLog(@"首页推荐酒瓶===%@", responseArrayData);
|
|
if (!responseArrayData.count) {
|
|
//弹窗-查看更多
|
|
[SVProgressHUD dismiss];
|
|
[self showBottleEmptyAlertViewWithButtonTap:^(UIButton * _Nonnull sender) {
|
|
BottleDetialController *deDetial = [[BottleDetialController alloc]init];
|
|
[QMUIHelper.visibleViewController.navigationController.navigationController pushViewController:deDetial animated:YES];
|
|
}];
|
|
return;
|
|
}
|
|
NSString *firstId = responseArrayData.firstObject;
|
|
//根据id获取详情
|
|
[THNetworkInterfaceService requestRecommendBottleInfoWithBottleId:firstId complete:^(NSDictionary * _Nullable responseDicData, NSError * _Nullable err) {
|
|
NSLog(@"首页推荐酒瓶===%@", responseDicData);
|
|
if (!responseDicData.allKeys.count) {
|
|
[SVProgressHUD dismiss];
|
|
[THNetworkInterfaceService showBottleEmptyAlertViewWithButtonTap:^(UIButton * _Nonnull sender) {
|
|
BottleDetialController *deDetial = [[BottleDetialController alloc]init];
|
|
[QMUIHelper.visibleViewController.navigationController.navigationController pushViewController:deDetial animated:YES];
|
|
}];
|
|
return;
|
|
}
|
|
[SVProgressHUD dismiss];
|
|
if (complete) {
|
|
complete(responseDicData, err);
|
|
}
|
|
}];
|
|
}];
|
|
}
|
|
|
|
///获取推荐瓶子Id_list
|
|
+ (void)requestRecommendBottleIdsWithPageSize:(NSInteger)pageSize complete:(responseArrayBlock)complete {
|
|
NSMutableDictionary *paramM = [NSMutableDictionary dictionary];
|
|
paramM[@"num"] = @(pageSize);
|
|
NSString *path = [NSString stringWithFormat:@"v3/bottle/recommend/%@", [self userId]];
|
|
[NetworkingManager scheduledGET:path parameters:paramM success:^(NSURLSessionDataTask * _Nonnull task, NetResponseModel * _Nullable responseModel) {
|
|
// NSArray *ids = responseModel.data;
|
|
if (complete) {
|
|
complete(responseModel.data, nil);
|
|
}
|
|
} failure:nil];
|
|
}
|
|
///根据bottleId获取推荐瓶子详情
|
|
+ (void)requestRecommendBottleInfoWithBottleId:(NSString *)bId complete:(responseDictionaryBlock)complete {
|
|
NSString *path = [NSString stringWithFormat:@"v3/bottle/recommend/get/%@", bId];
|
|
[NetworkingManager scheduledGET:path parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, NetResponseModel * _Nullable responseModel) {
|
|
if (complete) {
|
|
complete(responseModel.data, nil);
|
|
}
|
|
} failure:nil];
|
|
}
|
|
|
|
|
|
@end
|
|
|
|
//MARK: - 附近
|
|
@implementation THNetworkInterfaceService (Near)
|
|
|
|
@end
|
|
|
|
//MARK: - 邀请
|
|
@implementation THNetworkInterfaceService (Invite)
|
|
|
|
@end
|
|
|
|
//MARK: - 聊天
|
|
@implementation THNetworkInterfaceService (Chat)
|
|
|
|
@end
|
|
|
|
//MARK: - 我的
|
|
@implementation THNetworkInterfaceService (Mine)
|
|
|
|
@end
|
|
|
|
|
|
//MARK: - 用户
|
|
@implementation THNetworkInterfaceService (UserInfo)
|
|
|
|
///是否为管理员账户
|
|
+ (BOOL)isManager {
|
|
return [UserService currentUser].is_manager;
|
|
}
|
|
|
|
///获取用户userId
|
|
+ (nullable NSString *)userId {
|
|
return [NSString stringWithFormat:@"%d", [UserService currentUserID]];
|
|
// NSString *im_uid = [LoginService imUserId];
|
|
// if (im_uid.length) {
|
|
// //hole_102769---->102769
|
|
// NSArray *components = [im_uid componentsSeparatedByString:@"_"];
|
|
// return components.lastObject;
|
|
// }
|
|
// return nil;
|
|
}
|
|
|
|
///刷新userToken
|
|
+ (void)refreshUserToken:(NSString *)token {
|
|
NSString *userToken = [LoginService token];
|
|
if (token.length && ![userToken isEqualToString:token]) {
|
|
userToken = token;
|
|
}
|
|
NSLog(@"CYH===%@", userToken);
|
|
[NetworkingManager.shared setScheduleRequestHeader:@{
|
|
@"Authorization" : [@"Bearer " stringByAppendingString:userToken]
|
|
}];
|
|
}
|
|
|
|
@end
|
|
|
|
//MARK: - 设备
|
|
@implementation THNetworkInterfaceService (Device)
|
|
|
|
//app发布版本
|
|
+ (NSString *)version {
|
|
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
|
|
return infoDictionary[@"CFBundleShortVersionString"];
|
|
}
|
|
|
|
// bundle 构建迭代的版本号
|
|
+ (NSString *)bundleVersion {
|
|
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
|
|
return infoDictionary[@"CFBundleVersion"];
|
|
}
|
|
|
|
+ (NSString *)deviceModel {
|
|
UIDevice *device = [UIDevice currentDevice];
|
|
return device.model;
|
|
}
|
|
+ (NSString *)deviceSystemVersion {
|
|
UIDevice *device = [UIDevice currentDevice];
|
|
return device.systemVersion;
|
|
}
|
|
|
|
@end
|
|
|
|
// 2023-02-08 17:49:52 +0800
|
|
// YPTools Auto Update Create Date https://github.com/HansenCCC/YPTools
|