JLChen
2021-04-30 a5247b61d585627a1a7b1e1f35f34de9f0af9fba
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//
//  openApiService.m
//  appDemo
//
//  Created by chenjian on 16/7/8.
//  Copyright (c) 2016年 yao_bao. All rights reserved.
//
 
#import "OpenApiClient.h"
#import "OpenApiService.h"
 
@implementation OpenApiService
- (NSInteger)getAccessToken:(NSString*)ip_In port:(NSInteger)port_In appId:(NSString*)appId_In appSecret:(NSString*)appSecret_In token:(NSString**)accessTok_Out errcode:(NSString**)strErrCode_Out errmsg:(NSString**)errMsg_Out
{
    OpenApiClient * client = [OpenApiClient shareMyInstance];
    [client setParams:ip_In port:port_In appId:appId_In appSecret:appSecret_In method:@"/openapi/accessToken"];
    
    NSDictionary *req = @{@"phone":@""};
    NSDictionary *resp = [client request:req];
    
    if (resp) {
        *strErrCode_Out = [resp[@"code"] copy];
        *errMsg_Out = [resp[@"msg"] copy];
        *accessTok_Out = [resp[@"data"][@"accessToken"] copy];
    }
    return [*strErrCode_Out isEqualToString:@"0"] ? 0 : -1;
}
- (NSInteger)getUserToken:(NSString*)ip_In port:(NSInteger)port_In appId:(NSString*)appId_In appSecret:(NSString*)appSecret_In phone:(NSString*)phoneNum_In token:(NSString**)accessTok_Out errcode:(NSString**)strErrCode_Out errmsg:(NSString**)errMsg_Out
{
    OpenApiClient * client = [OpenApiClient shareMyInstance];
    [client setParams:ip_In port:port_In appId:appId_In appSecret:appSecret_In method:@"/openapi/userTokenByAccount"];
    NSDictionary *req = @{@"phone":phoneNum_In};
    NSDictionary *resp = [client request:req];
    
    if (resp) {
        *strErrCode_Out = [resp[@"code"] copy];
        *errMsg_Out = [resp[@"msg"] copy];
        *accessTok_Out = [resp[@"data"][@"userTokenByAccount"] copy];
    }
    return [*strErrCode_Out isEqualToString:@"0"] ? 0 : -1;
}
 
- (NSInteger)userBindSms:(NSString*)ip_In port:(NSInteger)port_In appId:(NSString*)appId_In appSecret:(NSString*)appSecret_In phone:(NSString*)phoneNum_In errcode:(NSString**)strErrCode_Out errmsg:(NSString**)errMsg_Out
{
    OpenApiClient * client = [OpenApiClient shareMyInstance];
    [client setParams:ip_In port:port_In appId:appId_In appSecret:appSecret_In method:@"/openapi/userBindSms"];
    
    NSDictionary *req = @{@"phone":phoneNum_In};
    NSDictionary *resp = [client request:req];
    
    if (resp) {
        *strErrCode_Out = [resp[@"code"] copy];
        *errMsg_Out = [resp[@"msg"] copy];
    }
    return [*strErrCode_Out isEqualToString:@"0"] ? 0 : -1;
}
 
- (NSInteger)userBind:(NSString*)ip_In port:(NSInteger)port_In appId:(NSString*)appId_In appSecret:(NSString*)appSecret_In phone:(NSString*)phoneNum_In smscode:(NSString*)smsCode errmsg:(NSString**)errMsgOut
{
    OpenApiClient * client = [OpenApiClient shareMyInstance];
    [client setParams:ip_In port:port_In appId:appId_In appSecret:appSecret_In method:@"/openapi/userBindNoVerify"];
    
    NSDictionary *req = @{@"phone":phoneNum_In, @"smsCode":smsCode};
    NSDictionary *resp = [client request:req];
    
    if (resp) {
        *errMsgOut = [resp[@"msg"] copy];
    }
    return [resp[@"code"] isEqualToString:@"0"] ? 0 : -1;
}
 
- (NSInteger)userBindNoVerify:(NSString*)ip_In port:(NSInteger)port_In appId:(NSString*)appId_In appSecret:(NSString*)appSecret_In phone:(NSString*)phoneNum_In errmsg:(NSString**)errMsgOut
{
    OpenApiClient * client = [OpenApiClient shareMyInstance];
    [client setParams:ip_In port:port_In appId:appId_In appSecret:appSecret_In method:@"/openapi/userBindNoVerify"];
    
    NSDictionary *req = @{@"account":phoneNum_In};
    NSDictionary *resp = [client request:req];
    
    if (resp) {
        *errMsgOut = [resp[@"msg"] copy];
    }
    return [resp[@"code"] isEqualToString:@"0"] ? 0 : -1;
}
 
- (NSInteger)userTokenByAccount:(NSString*)ip_In port:(NSInteger)port_In appId:(NSString*)appId_In appSecret:(NSString*)appSecret_In phone:(NSString*)phoneNum_In token:(NSString**)accessTok_Out errcode:(NSString**)strErrCode_Out errmsg:(NSString**)errMsg_Out
{
    OpenApiClient * client = [OpenApiClient shareMyInstance];
    [client setParams:ip_In port:port_In appId:appId_In appSecret:appSecret_In method:@"/openapi/userTokenByAccount"];
    NSDictionary *req = @{@"account":phoneNum_In};
    NSDictionary *resp = [client request:req];
    
    if (resp) {
        *strErrCode_Out = [resp[@"code"] copy];
        *errMsg_Out = [resp[@"msg"] copy];
        *accessTok_Out = [resp[@"data"][@"userToken"] copy];
    }
    return [*strErrCode_Out isEqualToString:@"0"] ? 0 : -1;
}
 
 
- (NSInteger)deviceOpenList:(NSString *)token_In bindId:(long)bindId_In limit:(NSUInteger)limit_In type:(NSString *)type_In needApInfo:(NSString *)needApInfo_In  result:(NSDictionary **)result_Out errcode:(NSString**)strErrCode_Out errmsg:(NSString**)errMsg_Out {
    OpenApiClient * client = [OpenApiClient shareMyInstance];
    client.method = @"/openapi/deviceOpenList";
    NSDictionary *req = @{ @"token": token_In, @"bindId": [NSNumber numberWithLong:bindId_In], @"limit":[NSNumber numberWithInt:(int)limit_In],@"type" : type_In, @"needApInfo" :  needApInfo_In};
   NSDictionary *resp = [client request:req];
   if (resp) {
       *strErrCode_Out = [resp[@"code"] copy];
       *errMsg_Out = [resp[@"msg"] copy];
       *result_Out = resp[@"data"];
   }
   return [*strErrCode_Out isEqualToString:@"0"] ? 0 : -1;
}
 
- (NSInteger)deviceBaseList:(NSString *)token_In bindId:(long)bindId_In limit:(NSUInteger)limit_In type:(NSString *)type_In needApInfo:(NSString *)needApInfo_In  result:(NSDictionary **)result_Out errcode:(NSString**)strErrCode_Out errmsg:(NSString**)errMsg_Out {
     OpenApiClient * client = [OpenApiClient shareMyInstance];
     client.method = @"/openapi/deviceBaseList";
    NSDictionary *req = @{ @"token": token_In, @"bindId": [NSNumber numberWithLong:bindId_In], @"limit":[NSNumber numberWithInt:(int)limit_In],@"type" : type_In, @"needApInfo" :  needApInfo_In};
     NSDictionary *resp = [client request:req];
     if (resp) {
         *strErrCode_Out = [resp[@"code"] copy];
         *errMsg_Out = [resp[@"msg"] copy];
         *result_Out = resp[@"data"];
     }
     return [*strErrCode_Out isEqualToString:@"0"] ? 0 : -1;
    
}
 
- (NSInteger)deviceOpenDetailList:(NSString *)token_In deviceList:(NSArray *)deviceList_In result:(NSDictionary **)result_Out errcode:(NSString**)strErrCode_Out errmsg:(NSString**)errMsg_Out {
    OpenApiClient * client = [OpenApiClient shareMyInstance];
    client.method = @"/openapi/deviceOpenDetailList";
    
    
    NSMutableDictionary *req = [NSMutableDictionary dictionaryWithDictionary: @{ @"token": token_In}];
    [req setObject:deviceList_In forKey:@"deviceList"];
        NSDictionary *resp = [client request:req];
        if (resp) {
            *strErrCode_Out = [resp[@"code"] copy];
            *errMsg_Out = [resp[@"msg"] copy];
            *result_Out = resp[@"data"];
        }
        return [*strErrCode_Out isEqualToString:@"0"] ? 0 : -1;
}
 
- (NSInteger)deviceBaseDetailList:(NSString *)token_In deviceList:(NSArray *)deviceList_In result:(NSDictionary **)result_Out errcode:(NSString**)strErrCode_Out errmsg:(NSString**)errMsg_Out {
    OpenApiClient * client = [OpenApiClient shareMyInstance];
    client.method = @"/openapi/deviceBaseDetailList";
    NSDictionary *req = @{ @"token": token_In, @"deviceList" : deviceList_In};
    NSDictionary *resp = [client request:req];
    if (resp) {
       *strErrCode_Out = [resp[@"code"] copy];
       *errMsg_Out = [resp[@"msg"] copy];
       *result_Out = resp[@"data"];
    }
    return [*strErrCode_Out isEqualToString:@"0"] ? 0 : -1;
}
 
- (NSInteger)alarmStatus:(NSString *)token_In deviceId:(NSString *)deviceId channelId:(NSString *)channelId status:(int *)status errcode:(NSString**)strErrCode_Out errmsg:(NSString**)errMsg_Out {
    OpenApiClient * client = [OpenApiClient shareMyInstance];
      client.method = @"/openapi/bindDeviceChannelInfo";
      NSDictionary *req = @{ @"token": token_In, @"deviceId" : deviceId, @"channelId" : channelId};
      NSDictionary *resp = [client request:req];
      if (resp) {
          *strErrCode_Out = [resp[@"code"] copy];
          *errMsg_Out = [resp[@"msg"] copy];
          *status = [resp[@"data"][@"alarmStatus"] intValue];
      }
      return [*strErrCode_Out isEqualToString:@"0"] ? 0 : -1;
}
 
- (NSInteger)updateStatus:(NSString *)token_In deviceId:(NSString *)deviceId status:(int *)status errcode:(NSString**)strErrCode_Out errmsg:(NSString**)errMsg_Out {
    OpenApiClient * client = [OpenApiClient shareMyInstance];
         client.method = @"/openapi/deviceVersionList";
    NSDictionary *req = @{ @"token": token_In, @"deviceIds" : deviceId };
         NSDictionary *resp = [client request:req];
         if (resp) {
             *strErrCode_Out = [resp[@"code"] copy];
             *errMsg_Out = [resp[@"msg"] copy];
             NSArray *deviceVersionList = resp[@"data"][@"deviceVersionList"];
             NSDictionary *dic = deviceVersionList.firstObject;
             if (![dic[@"canBeUpgrade"] boolValue]) {
                 *status = 0;
             }
             else {
                 *status = 1;
             }
         }
         return [*strErrCode_Out isEqualToString:@"0"] ? 0 : -1;
}
 
- (NSInteger)cloudStatus:(NSString *)token_In deviceId:(NSString *)deviceId channelId:(NSString *)channelId status:(int *)status errcode:(NSString**)strErrCode_Out errmsg:(NSString**)errMsg_Out {
    OpenApiClient * client = [OpenApiClient shareMyInstance];
         client.method = @"/openapi/getStorageStrategy";
       NSDictionary *req = @{ @"token": token_In, @"deviceId" : deviceId, @"channelId" : channelId};
         NSDictionary *resp = [client request:req];
         if (resp) {
             *strErrCode_Out = [resp[@"code"] copy];
             *errMsg_Out = [resp[@"msg"] copy];
             *status = [resp[@"data"][@"strategyStatus"] intValue];
         }
         return [*strErrCode_Out isEqualToString:@"0"] ? 0 : -1;
}
 
- (void)cancelRequest {
    OpenApiClient * client = [OpenApiClient shareMyInstance];
    [client cancelRequest];
    
}
 
@end