developer
2023-05-20 e12c7b4c22df631ebdcd16b2f98fbef8f738f92f
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
//
//  TBSDKConfiguration.h
//  mtopext
//
//  mtop setting 统一入口
//
//  Created by wuchen.xj on 02/15/2019.
//  Copyright (c) 2019年 Taobao. All rights reserved..
//
 
#import <Foundation/Foundation.h>
#import <MtopSDK/TBSDKThreadSafeMutableDictionary.h>
#import <MtopSDK/TBSDKMTOPEnvConfig.h>
#import <mtopext/TBSDKAccountInfo.h>
 
#pragma mark - 环境定义
 
/**
 * 环境类型。
 */
typedef NS_ENUM(NSUInteger,TBSDKEnvironment) {
    
    /**
     * 正式环境
     */
    TBSDKEnvironmentRelease = 0,
    
    /**
     * 预发环境
     */
    TBSDKEnvironmentDebug,
    
    /**
     * 日常环境
     */
    TBSDKEnvironmentDaily,
    
    /**
     * 日常二套环境(废弃)
     */
    TBSDKEnvironmentDailyTwo DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除")
    
};
 
 
#pragma mark - 配置接口定义
/**
 * 实体类存储着TBSDK的配置信息。
 */
@interface TBSDKConfiguration : NSObject
 
 
/**
 * 是否使用安全保镖, 二三方版本强制为YES
 */
@property (nonatomic, assign) BOOL  safeSecret;
 
 
/**
 * 在使用安全保镖的情况下,如果存在多张安全图片的场景,指定当前实例使用哪张图片。
 * 例如安全图片文件名为:yw_1222.jpg 或 yw_1222_mwua.jpg , 其中前者的auth code 为 “”,
 * 后者的auth code 为 “mwua”,所有安全图片均以 yw_1222 为前缀。
 */
@property (nonatomic, strong) NSString  *authCode;
 
 
/**
 * App Key.
 * 若 useSecurityGuard=NO,该值需要上层自己来设置;否则SDK根据环境和authCode自动通过
 * 无线保镖SDK读取出存储在安全图片中的appkey.
 */
@property (nonatomic, copy) NSString    *appKey;
 
 
 
/**
 * App Secret.
 * 若 useSecurityGuard=NO,该值需要上层自己来设置;否则SDK根据环境和appKey自动通过
 * 无线保镖SDK读取出存储在安全图片中的appSecret.
 */
@property (nonatomic, strong) NSString  *appSecret;
 
 
/**
 * 自定义从安全图片中指定位置读取appkey.
 * 正常情况下,一张安全图片中同时存在三个环境的appkey, 线上、预发、日常,分别存储在安全图片的
 * 内部 index 为 0、1、2 的位置,SDK 会自动根据当前环境取对应位置上的appkey。但若业务需要
 * 自定义在指定索引位置读取,则可以通过该参数来设置。
 *
 * 因涉及无线保镖,故该参数只在 useSecurityGuard=YES 的情况下有效.
 */
@property (nonatomic, assign) NSUInteger    appkeyIndex;
 
 
/**
 * 网关给设备分配的ID, SDK启动时自动异步获取,在获取成功前,取上一次的缓存值。
 */
@property (nonatomic, copy) NSString    *deviceID;
 
 
 
/**
 * App版本号。
 * 用户可自定义,如未自定义,自动读取主bundle版本号。
 */
@property (nonatomic, copy) NSString  *appVersion;
 
 
 
/**
 * 无线埋点的 ttid (渠道号)。
 */
@property (nonatomic, copy) NSString    *wapTTID;
 
 
/**
 * 当前MTOP网关,默认情况下,其值为:
 * 线上:acs.m.taobao.com
 * 预发:acs.wapa.taobao.com
 * 日常:acs.waptest.taobao.com
 *
 * 若业务需要自定义域名,可直接覆写该变量。注意,若业务自己覆写,则需要自行处理线上、预发、日常三个不同环境。
 */
@property (nonatomic, strong)   NSString    *gatewayDomain;
 
 
 
/**
 * 本地时间与服务器的时间差(秒),TBSDK负责联网获取
 * 注意,只有 kMtopInner 类型网关才有此能力。
 */
@property (nonatomic, assign) NSTimeInterval  timestampOffset;
 
 
/**
 * MTOP 多套测试环境配置.
 * 若该参数>0, 报文中会增加 tb_eagleeyex_scm_project 头。
 */
@property (nonatomic, copy) NSString    *tproject;
 
 
/**
 * MTOP 测试环境配置.
 * 若该参数有值, 报文中会增加 x-debug-id 头。
 */
@property (nonatomic, copy) NSString    *debugId;
 
 
/**
 * 协议能力flag, 报文中 x-features 头。内部生成。
 */
@property(atomic, assign, readonly)  uint64_t features;
 
 
/**
 * UTDID
 */
@property (nonatomic, copy) NSString *utdid;
 
 
/**
 * UID
 */
@property (nonatomic, copy) NSString *uid;
 
 
/**
 * 经纬度,报文中 x-location 头。
 */
@property (nonatomic, assign) double longitude;
 
 
/**
 * 经纬度,报文中 x-location 头。
 */
@property (nonatomic, assign) double latitude;
 
 
/**
 * 设置是否支持开放用户, 影响 x-features 头
 * 注: 为何变量名叫 OpenAccsOut ? 笔误?MTOP 迷案....
 */
@property (assign, nonatomic) BOOL supportOpenAccsOut;
 
 
/**
 * 全局错误信息,请慎用
 */
@property (nonatomic, copy) NSString *customErrorMessage;
 
 
/**
 * 全局扩展参数和data参数平级
 */
@property (nonatomic, strong) TBSDKThreadSafeMutableDictionary  *globalExtData;
 
 
/**
 * 交易单元域名列表,由外部初始化时设置。
 * index 0 : 线上环境
 * index 1 : 预发环境
 * index 2 : 日常环境
 */
@property (nonatomic, strong) NSArray   *tradeUnitDomains;
 
 
 
/**
 * 是否关闭获取deviceID能力.默认为NO.
 * 某些网关(例如Lazada) 没有获取deviceId的能力,设置为YES关闭该能力。
 */
@property (nonatomic, assign) BOOL  isDisableNewDeviceID;
 
 
 
/**
 * 是否关闭获取deviceID能力.默认为NO.
 * 某些网关(例如Lazada) 没有获取deviceId的能力,设置为YES关闭该能力。
 */
@property (nonatomic, assign) BOOL  isSwitchOffGetServerTime;
 
 
 
/**
 * 是否开启HTTPS, 默认YES.
 * YES: mtop http url 以 'https://' 开头;
 * NO: mtop http url 以 'http://' 开头.
 * 注意:若该变量为 NO,会强制全局为 http;若该变量设置为 YES, 请求维度仍可单独降级为 http.
 */
@property (nonatomic, assign) BOOL  enableHttps;
 
 
 
/**
 * 自定义SDK 网络错误文案。若非国际化要求,需要特定编码文本,请不要设置该文案。
 */
@property (nonatomic, copy)  NSString   *networkErrorMsg;
 
 
 
/**
 * 自定义SDK 防刷限流错误文案。若非国际化要求,需要特定编码文本,请不要设置该文案。
 */
@property (nonatomic, copy)  NSString   *flowLimitErrorMsg;
 
 
 
/**
 * 自定义SDK 服务端错误文案。若非国际化要求,需要特定编码文本,请不要设置该文案。
 */
@property (nonatomic, copy)  NSString   *serviceErrorMsg;
 
 
 
/**
 *  MTOP请求关联的当前VC 或 页面名称
 */
@property(atomic, copy) NSString    *pageName;
 
 
 
/**
 * MTOP请求关联的当前请求的 URL
 */
@property(atomic, copy) NSString    *pageUrl;
 
 
 
/**
 * 运行时存放了与登录相关账户信息,如uid、sid
 */
@property (nonatomic, strong) TBSDKAccountInfo  *accountInfo DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");;
 
/**
 *  ISV需要用到
 */
@property (nonatomic, copy) NSString    *securityAppKey;
 
 
 
/**
 * 以下废弃参数
 */
@property (nonatomic, assign) TBSDKEnvironment environment DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
@property (nonatomic, copy) NSString    *appName DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
@property (nonatomic, copy) NSString    *topAPIURL DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
@property (nonatomic, copy) NSString    *wapAPIURL DEPRECATED_MSG_ATTRIBUTE("使用 gatewayDomain 代替");
@property (nonatomic, copy) NSString    *mtopOriginalUrl DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
@property (nonatomic, copy) NSString    *topOriginalUrl DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
@property (nonatomic, copy) NSString    *wapAPISecurityURL DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
@property (nonatomic, copy) NSString    *defaultDomain DEPRECATED_MSG_ATTRIBUTE("使用 gatewayDomain 代替");
 
 
/**
 * 获取默认配置,默认配置类型为二方类型 kTypeInner. 该方法线程安全。
 * 说明,为了避免业务配置到错误的类型configure,推荐使用新API: shareInstanceWithType: 来获取对象。
 * @return 配置实例
 */
+ (instancetype)shareInstance DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
 
 
/**
 * 通过实例ID来获取对应实例。其中已经内置ID为 MTOP_ID_INNER 与 MTOP_ID_OPEN 实例, 如果需要新增实例,请通过
 * mtopsdk_configuration.plist 配置文件来新增实例,只有在 plist 中注册过的ID,才可以使用。配置文件配置规则(示例)如下:
 *
 * ROOT (dictionary)
 *  |---ExternalInstances (dictionary)
 *            |---- @"id1":@"0" (0 表示该实例类型为二方实例)
 *            |-----@"id2":@"1" (1 表示该实例类型为三方实例)
 *
 * 注意:ID为 MTOP_ID_INNER 与 MTOP_ID_OPEN 实例不可在配置文件中修改类型,已经分别设置为二方、三方实力。若不是
 *      MTOP_ID_INNER 与 MTOP_ID_OPEN,且名称未在plist中注册,返回nil.
 *
 * @param Id 索引MTOP实例的KEY值。可以为 MTOP_ID_INNER/MTOP_ID_OPEN 或者定义在 mtopsdk_configuration.plist 中
 * @return MTOP实例。若非内置实例且名称未注册,则返回nil.
 */
+ (instancetype) shareInstanceWithID:(NSString *)Id;
 
 
/**
 * 获取当前实例ID。
 */
- (NSString *)ID;
 
 
/**
 * 获取当前实例类型。
 */
- (MtopType)type;
 
 
/**
 * 打开全站https(默认全站开启HTTPS)
 * 该功能为历史功能,目前已经全面切为全站HTTTPS, 已废弃。
 */
- (void) enableAllSiteHttps DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
 
 
 
/**
 * 关闭全站https(默认全站开启HTTPS)
 * 该功能为历史功能,目前已经全面切为全站HTTTPS, 已废弃。
 */
- (void) disableAllSiteHttps DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
 
 
 
/**
 * 开启白盒秘钥
 * 该功能为历史功能,目前已经全站开启白盒秘钥, 该配置已废弃。
 */
- (void) enableWhiteSecurity DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
 
 
 
/**
 * 关闭白盒秘钥
 * 该功能为历史功能,目前已经全站开启白盒秘钥, 该配置已废弃。
 */
- (void) unableWhiteSecurity DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
 
 
 
/**
 * 设置一个应用级别的请求头, 注意 设置的值不会被持久化,只是在应用生命周期内有效
 * @param key 参数名称
 * @param value 参数值
 *
 */
- (void) setApplicationRequestHeader: (NSString*) value forKey: (NSString*) key;
 
 
 
/**
 * 获取一个应用级别的请求头的值
 * @param name 参数名称
 * @return setApplicationRequestHeader设置的值
 */
- (NSString*) getApplicationRequestHeader: (NSString*) name;
 
 
 
/**
 * 获取当前的应用级别的请求头
 * @return 全部KV
 */
- (NSDictionary*) getCurrentApplicationRequestHeader;
 
 
 
/**
 * 移除一个应用级别的请求头
 * @param name
 *
 */
- (void) removeApplicationRequestHeader: (NSString*) name;
 
 
 
/**
 * 移除所以应用级别的请求头
 * @param name
 *
 */
- (void) removeAllApplicationRequestHeader;
 
 
 
/**
 * 设置一个应用级别的请求但不需要URL-Encoding的头, 注意 设置的值不会被持久化,只是在应用生命周期内有效
 * @param key 参数名称
 * @param value 参数值
 *
 */
- (void) setApplicationRequestHeaderWithoutEncoding: (NSString*) value forKey: (NSString*) key;
 
 
 
 
/**
 * 获取当前的应用级别的请求头
 * @return 全部KV
 */
- (NSDictionary*) getCurrentApplicationRequestHeaderWithoutEncoding;
 
 
 
/**
 * 从磁盘加载配置参数
 */
- (void) loadAVCV;
 
 
 
/**
 *  获取当前发送MTOP请求所在VC
 */
- (NSString*)currentPageName;
 
 
 
/**
 *  获取当前发送MTOP请求所在容器访问的URL
 */
- (NSString*)currentPageUrl;
 
 
 
/**
 * 设置环境. 该参数只有类型为二方(kTypeInner)时起作用,其有两层作用:
 *
 * 1)指定网关: 在二方环境中,阿里的默认的做法都是分为线上、预发、日常三套环境,不同环境指向不同的网关域名,
 *   若为二方环境,这些域名都已经内置,APP只要设置环境即可;
 * 2)指定Appkey/Appsecrect: 在二方环境中, 为保证安全,其Appkey/Appsecrect一般都是保存在无线保镖的
 *   的安全文件中,SDK 通过该参数,可以直接通过无线保镖SDK读取所需要的Appkey,以及加签等动作。
 *
 * 若为三方(kTypeOpen)类型,则该参数忽略。
 */
+ (void)setEnvironment:(TBSDKEnvironment)env;
 
 
 
/**
 * 当前环境
 */
+ (TBSDKEnvironment)currentEnvironment;
 
 
/**
 * 全局默认实例ID。
 * 该值从 MTOP SDK 配置文件 mtopsdk_configuration.plist 中的 DefaultID 字段读取,若没有该配置文件,
 * 默认返回 MTOP_ID_INNER。该参数在 mtopsdk_configuration.plist 文件中配置:
 *
 * Root (Dictionary)
 *  |
 *  |---DefaultID : @"INNER" (@"INNER" 内置二方实例; @“OPEN” 内置三方实例;或其他自定义实例 )
 */
+ (NSString *)defaultID;
 
 
//! 请将api字符串转换为小写
+ (void)addEcodeSignAPI:(NSArray *)API;
 
+ (NSDate *)timeStampFixedWithServer;
 
 
@end