cdts/xdts-ios 3/TreeHole/CYHResetCode/NetworkInterfaceService(网络请求接口)/THNetworkInterfaceService.m

262 lines
8.4 KiB
Mathematica
Raw Permalink Normal View History

2023-07-27 09:20:00 +08:00
// 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