Files
yinmeng-ios-store/yinmeng-ios/yinmeng-ios/Base/MVP/Api/Api.m
2023-12-05 18:58:44 +08:00

91 lines
3.7 KiB
Objective-C

//
// Api.m
// mew-ios
//
// Created by 触海 on 2023/11/6.
//
#import "Api.h"
#import "NewEncryptTool.h"
@implementation Api
+ (void)makeRequest:(NSString *)route method:(MewHttpRequestHelperMethod)method completion:(MewHttpRequestHelperCompletion)completion, ... {
va_list arg_lists;
va_start(arg_lists, completion);
// 获取第一个参数 __FUNCTION__ ,然后解析出来 key 。
const char *functionName = va_arg(arg_lists, const char *);
NSString *fn = [[NSString alloc] initWithUTF8String:functionName];
// NSLog 一下 __FUNCTION__ 就知道为什么这么截取了。
NSRange blankRange = [fn rangeOfString:@":"];
NSUInteger start = blankRange.location + 1;
NSUInteger length;
if ((start + 2) < fn.length) {
length = fn.length - start - 2;
} else if ((start + 1) < fn.length) {
length = fn.length -start - 1;
} else {
length = fn.length -start;
}
NSString *fromatParamKeys = [fn substringWithRange:NSMakeRange(start, length)];
// 构造请求的 NSMutableDictionary *params 。
NSMutableDictionary *params = [NSMutableDictionary dictionary];
NSArray *paramKeys = [fromatParamKeys componentsSeparatedByString:@":"];
NSEnumerator *enumerator = [paramKeys objectEnumerator];
NSString *value = nil;
while((value = va_arg(arg_lists, NSString*))){
[params setValue:value forKey:enumerator.nextObject];
};
va_end(arg_lists);
[MewHttpRequestHelper request:route method:method params:params completion:completion];
}
/// 获取用户信息
+ (void)getUserInfo:(MewHttpRequestHelperCompletion)completion uid:(NSString *)uid {
NSString *getUrl = [NewEncryptTool MEW_aesDecrypt:@"KEMxFkjgYfZuaj0tYsUeqQ=="];///user/get
[self makeRequest:getUrl method:MewHttpRequestHelperMethodGET completion:completion, __FUNCTION__, uid, nil];
}
/// 批量验证
/// @param complection 完成
/// @param transcationIdStr 需要验证的数据
+ (void)requestCheckTranscationIds:(MewHttpRequestHelperCompletion)complection
transcationIdStr:(NSString *)transcationIdStr {
NSString *getUrl = [NewEncryptTool MEW_aesDecrypt:@"AC1UrTdJJWq1b8dtUCnP4zFOik6EzK85rr1GEjLv2Kk="];///verify/checkIOSChargeRecord
[self makeRequest:getUrl method:MewHttpRequestHelperMethodPOST completion:complection, __FUNCTION__,transcationIdStr, nil];
}
/// 获取手机号的验证码
/// @param completion 请求完成
/// @param mobile 手机号
/// @param type 类型 请看XPEunm中的枚举
+ (void)mew_phoneSmsCode:(MewHttpRequestHelperCompletion)completion mobile:(NSString *)mobile type:(NSString *)type {
NSString *getUrl = [NewEncryptTool MEW_aesDecrypt:@"2Hx71goXCYG6r1fVVkSHsA=="];///sms/getCode
[self makeRequest:getUrl method:MewHttpRequestHelperMethodPOST completion:completion, __FUNCTION__, mobile, type, nil];
}
/// 补全用户资料
/// @param complection 完成
/// @param userInfo 需要更新的用户信息
+ (void)mew_completeUserInfo:(MewHttpRequestHelperCompletion)complection
userInfo:(NSDictionary *)userInfo {
NSString *getUrl = [NewEncryptTool MEW_aesDecrypt:@"6A7+MXSz6a7RbsOb9Ls+mA=="];///user/v2/update
[MewHttpRequestHelper request:getUrl method:MewHttpRequestHelperMethodPOST params:userInfo completion:complection];
}
/// 获取用户钱包余额信息
/// @param complection 完成
/// @param uid 用户uid
/// @param ticket ticketg
+ (void)mew_getUserWalletInfo:(MewHttpRequestHelperCompletion)complection
uid:(NSString *)uid
ticket:(NSString *)ticket {
NSString *getUrl = [NewEncryptTool MEW_aesDecrypt:@"7xFYk5dOEOCLb2Sfp0mwZw=="];//purse/query
[self makeRequest:getUrl method:MewHttpRequestHelperMethodGET completion:complection, __FUNCTION__, uid, ticket,nil];
}
@end