-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGHViewController.m
More file actions
130 lines (109 loc) · 4.2 KB
/
Copy pathGHViewController.m
File metadata and controls
130 lines (109 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// GHViewController.m
// GHNetworkModule
//
// Created by Qincc on 12/12/2020.
// Copyright (c) 2020 Qincc. All rights reserved.
//
#import "GHViewController.h"
#import <GHNetworkModule/GHNetwork.h>
@interface GHViewController ()
@end
@implementation GHViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// MARK: ⚙ 网络请求组件基础配置
#ifdef DEBUG
GHNetworkConfigure.share.generalServer = @"https://test-openiot.gosund.com";
#else
GHNetworkConfigure.share.generalServer = @"https://openiot.gosund.com";
#endif
GHNetworkConfigure.share.enableDebug = YES;
GHNetworkConfigure.share.useCache = NO; //不实用缓存
GHNetworkConfigure.share.respondeSuccessKeys = @[@"err_code"]; /** 与后端约定的请求结果状态字段, 默认 code, status */
GHNetworkConfigure.share.respondeHttpCodeKeys = @[@"http_code"];
GHNetworkConfigure.share.respondeMsgKeys = @[@"msg"]; /** 与后端约定的请求结果消息字段集合, 默认 message, msg */
GHNetworkConfigure.share.respondeDataKeys = @[@"data"]; /** 与后端约定的请求结果数据字段集合, 默认 data */
GHNetworkConfigure.share.respondeSuccessCode = @"0"; /** 与后端约定的请求成功code,默认为 200 */
GHNetworkConfigure.share.respondeHttpCode = @"200";
GHNetworkConfigure.share.startReachability = NO;
GHNetworkConfigure.share.generalHeaders = @{
@"platform":@"iphone",
@"lang":[NSBundle.mainBundle objectForInfoDictionaryKey:@"GHLanguage"],
@"appVersion":[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
@"os":@"iOS",
@"osSystem":[[UIDevice currentDevice] systemVersion],
@"requestType":@"app"
};
// 全局动态请求头参数设置,token,sign等
GHNetworkConfigure.share.generalDynamicHeaders = ^NSDictionary<NSString *,NSString *> * _Nonnull(NSDictionary * _Nonnull parameters, BOOL requireToken) {
NSMutableDictionary *temp = [NSMutableDictionary dictionaryWithCapacity:1];
[temp setValue:@"xxxxxxxxxx" forKey:@"Authorization"];
return temp;
};
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
// TODO: 发送请求
- (IBAction)sendRequest:(id)sender {
[self sendBasic1Request];
}
/**
基础请求 1
*/
- (void)sendBasic1Request {
GHNetworkRequest *request = [[GHNetworkRequest alloc] init];
request.baseURL = nil; //
request.methodPath = @"/v1.1/device/list";
request.requestMethod = GHNetworkRequestMethodGET; //根据文档设置
request.contenType = GHNetworkContenTypeJSON; //根据文档设置
request.serializerType = GHNetworkSerializerTypeJSON; //根据文档设置
request.normalParams = @{
@"username":@"",
@"password":@"",
@"region_code":@"",
@"phone_code":@"",
};
[GHNetworkModule.share sendRequest:request cacheComplete:nil networkComplete:^(GHNetworkResponse *response) {
if (response.status == GHNetworkResponseStatusSuccess) {
// 成功处理
} else {
// 失败处理
NSLog(response.error.domain);
}
[GHNetworkModule.share cancelRequestWithRequestID:response.requestId];
}];
}
- (void)sendBasic2Request {
GHLoginRequest *request = GHLoginRequest.alloc.init;
request.username = @"";
request.password = @"";
request.region_code = @"";
request.phone_code = @(1);
[GHNetworkModule.share sendRequest:request cacheComplete:nil networkComplete:^(GHNetworkResponse *response) {
if (response.status == GHNetworkResponseStatusSuccess) {
// 成功处理
} else {
// 失败处理
NSLog(response.error.domain);
}
[GHNetworkModule.share cancelRequestWithRequestID:response.requestId];
}];
}
@end
@implementation GHLoginRequest
- (instancetype)init
{
self = [super init];
if (self) {
self.methodPath = @"/v1.1/obtain_jwt_auth/";
self.requestMethod = GHNetworkRequestMethodPOST;
}
return self;
}
@end