猎豆优选

TBSDKConfiguration.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. //
  2. // TBSDKConfiguration.h
  3. // mtopext
  4. //
  5. // mtop setting 统一入口
  6. //
  7. // Created by wuchen.xj on 02/15/2019.
  8. // Copyright (c) 2019年 Taobao. All rights reserved..
  9. //
  10. #import <Foundation/Foundation.h>
  11. #import <MtopSDK/TBSDKThreadSafeMutableDictionary.h>
  12. #import <MtopSDK/TBSDKMTOPEnvConfig.h>
  13. #import <mtopext/TBSDKAccountInfo.h>
  14. #pragma mark - 环境定义
  15. /**
  16. * 环境类型。
  17. */
  18. typedef NS_ENUM(NSUInteger,TBSDKEnvironment) {
  19. /**
  20. * 正式环境
  21. */
  22. TBSDKEnvironmentRelease = 0,
  23. /**
  24. * 预发环境
  25. */
  26. TBSDKEnvironmentDebug,
  27. /**
  28. * 日常环境
  29. */
  30. TBSDKEnvironmentDaily,
  31. /**
  32. * 日常二套环境(废弃)
  33. */
  34. TBSDKEnvironmentDailyTwo DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除")
  35. };
  36. #pragma mark - 配置接口定义
  37. /**
  38. * 实体类存储着TBSDK的配置信息。
  39. */
  40. @interface TBSDKConfiguration : NSObject
  41. /**
  42. * 是否使用安全保镖, 二三方版本强制为YES
  43. */
  44. @property (nonatomic, assign) BOOL safeSecret;
  45. /**
  46. * 在使用安全保镖的情况下,如果存在多张安全图片的场景,指定当前实例使用哪张图片。
  47. * 例如安全图片文件名为:yw_1222.jpg 或 yw_1222_mwua.jpg , 其中前者的auth code 为 “”,
  48. * 后者的auth code 为 “mwua”,所有安全图片均以 yw_1222 为前缀。
  49. */
  50. @property (nonatomic, strong) NSString *authCode;
  51. /**
  52. * App Key.
  53. * 若 useSecurityGuard=NO,该值需要上层自己来设置;否则SDK根据环境和authCode自动通过
  54. * 无线保镖SDK读取出存储在安全图片中的appkey.
  55. */
  56. @property (nonatomic, copy) NSString *appKey;
  57. /**
  58. * App Secret.
  59. * 若 useSecurityGuard=NO,该值需要上层自己来设置;否则SDK根据环境和appKey自动通过
  60. * 无线保镖SDK读取出存储在安全图片中的appSecret.
  61. */
  62. @property (nonatomic, strong) NSString *appSecret;
  63. /**
  64. * 自定义从安全图片中指定位置读取appkey.
  65. * 正常情况下,一张安全图片中同时存在三个环境的appkey, 线上、预发、日常,分别存储在安全图片的
  66. * 内部 index 为 0、1、2 的位置,SDK 会自动根据当前环境取对应位置上的appkey。但若业务需要
  67. * 自定义在指定索引位置读取,则可以通过该参数来设置。
  68. *
  69. * 因涉及无线保镖,故该参数只在 useSecurityGuard=YES 的情况下有效.
  70. */
  71. @property (nonatomic, assign) NSUInteger appkeyIndex;
  72. /**
  73. * 网关给设备分配的ID, SDK启动时自动异步获取,在获取成功前,取上一次的缓存值。
  74. */
  75. @property (nonatomic, copy) NSString *deviceID;
  76. /**
  77. * App版本号。
  78. * 用户可自定义,如未自定义,自动读取主bundle版本号。
  79. */
  80. @property (nonatomic, copy) NSString *appVersion;
  81. /**
  82. * 无线埋点的 ttid (渠道号)。
  83. */
  84. @property (nonatomic, copy) NSString *wapTTID;
  85. /**
  86. * 当前MTOP网关,默认情况下,其值为:
  87. * 线上:acs.m.taobao.com
  88. * 预发:acs.wapa.taobao.com
  89. * 日常:acs.waptest.taobao.com
  90. *
  91. * 若业务需要自定义域名,可直接覆写该变量。注意,若业务自己覆写,则需要自行处理线上、预发、日常三个不同环境。
  92. */
  93. @property (nonatomic, strong) NSString *gatewayDomain;
  94. /**
  95. * 本地时间与服务器的时间差(秒),TBSDK负责联网获取
  96. * 注意,只有 kMtopInner 类型网关才有此能力。
  97. */
  98. @property (nonatomic, assign) NSTimeInterval timestampOffset;
  99. /**
  100. * MTOP 多套测试环境配置.
  101. * 若该参数>0, 报文中会增加 tb_eagleeyex_scm_project 头。
  102. */
  103. @property (nonatomic, copy) NSString *tproject;
  104. /**
  105. * MTOP 测试环境配置.
  106. * 若该参数有值, 报文中会增加 x-debug-id 头。
  107. */
  108. @property (nonatomic, copy) NSString *debugId;
  109. /**
  110. * 协议能力flag, 报文中 x-features 头。内部生成。
  111. */
  112. @property(atomic, assign, readonly) uint64_t features;
  113. /**
  114. * UTDID
  115. */
  116. @property (nonatomic, copy) NSString *utdid;
  117. /**
  118. * UID
  119. */
  120. @property (nonatomic, copy) NSString *uid;
  121. /**
  122. * 经纬度,报文中 x-location 头。
  123. */
  124. @property (nonatomic, assign) double longitude;
  125. /**
  126. * 经纬度,报文中 x-location 头。
  127. */
  128. @property (nonatomic, assign) double latitude;
  129. /**
  130. * 设置是否支持开放用户, 影响 x-features 头
  131. * 注: 为何变量名叫 OpenAccsOut ? 笔误?MTOP 迷案....
  132. */
  133. @property (assign, nonatomic) BOOL supportOpenAccsOut;
  134. /**
  135. * 全局错误信息,请慎用
  136. */
  137. @property (nonatomic, copy) NSString *customErrorMessage;
  138. /**
  139. * 全局扩展参数和data参数平级
  140. */
  141. @property (nonatomic, strong) TBSDKThreadSafeMutableDictionary *globalExtData;
  142. /**
  143. * 交易单元域名列表,由外部初始化时设置。
  144. * index 0 : 线上环境
  145. * index 1 : 预发环境
  146. * index 2 : 日常环境
  147. */
  148. @property (nonatomic, strong) NSArray *tradeUnitDomains;
  149. /**
  150. * 是否关闭获取deviceID能力.默认为NO.
  151. * 某些网关(例如Lazada) 没有获取deviceId的能力,设置为YES关闭该能力。
  152. */
  153. @property (nonatomic, assign) BOOL isDisableNewDeviceID;
  154. /**
  155. * 是否关闭获取deviceID能力.默认为NO.
  156. * 某些网关(例如Lazada) 没有获取deviceId的能力,设置为YES关闭该能力。
  157. */
  158. @property (nonatomic, assign) BOOL isSwitchOffGetServerTime;
  159. /**
  160. * 是否开启HTTPS, 默认YES.
  161. * YES: mtop http url 以 'https://' 开头;
  162. * NO: mtop http url 以 'http://' 开头.
  163. * 注意:若该变量为 NO,会强制全局为 http;若该变量设置为 YES, 请求维度仍可单独降级为 http.
  164. */
  165. @property (nonatomic, assign) BOOL enableHttps;
  166. /**
  167. * 自定义SDK 网络错误文案。若非国际化要求,需要特定编码文本,请不要设置该文案。
  168. */
  169. @property (nonatomic, copy) NSString *networkErrorMsg;
  170. /**
  171. * 自定义SDK 防刷限流错误文案。若非国际化要求,需要特定编码文本,请不要设置该文案。
  172. */
  173. @property (nonatomic, copy) NSString *flowLimitErrorMsg;
  174. /**
  175. * 自定义SDK 服务端错误文案。若非国际化要求,需要特定编码文本,请不要设置该文案。
  176. */
  177. @property (nonatomic, copy) NSString *serviceErrorMsg;
  178. /**
  179. * MTOP请求关联的当前VC 或 页面名称
  180. */
  181. @property(atomic, copy) NSString *pageName;
  182. /**
  183. * MTOP请求关联的当前请求的 URL
  184. */
  185. @property(atomic, copy) NSString *pageUrl;
  186. /**
  187. * 运行时存放了与登录相关账户信息,如uid、sid
  188. */
  189. @property (nonatomic, strong) TBSDKAccountInfo *accountInfo DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");;
  190. /**
  191. * ISV需要用到
  192. */
  193. @property (nonatomic, copy) NSString *securityAppKey;
  194. /**
  195. * 以下废弃参数
  196. */
  197. @property (nonatomic, assign) TBSDKEnvironment environment DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
  198. @property (nonatomic, copy) NSString *appName DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
  199. @property (nonatomic, copy) NSString *topAPIURL DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
  200. @property (nonatomic, copy) NSString *wapAPIURL DEPRECATED_MSG_ATTRIBUTE("使用 gatewayDomain 代替");
  201. @property (nonatomic, copy) NSString *mtopOriginalUrl DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
  202. @property (nonatomic, copy) NSString *topOriginalUrl DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
  203. @property (nonatomic, copy) NSString *wapAPISecurityURL DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
  204. @property (nonatomic, copy) NSString *defaultDomain DEPRECATED_MSG_ATTRIBUTE("使用 gatewayDomain 代替");
  205. /**
  206. * 获取默认配置,默认配置类型为二方类型 kTypeInner. 该方法线程安全。
  207. * 说明,为了避免业务配置到错误的类型configure,推荐使用新API: shareInstanceWithType: 来获取对象。
  208. * @return 配置实例
  209. */
  210. + (instancetype)shareInstance DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
  211. /**
  212. * 通过实例ID来获取对应实例。其中已经内置ID为 MTOP_ID_INNER 与 MTOP_ID_OPEN 实例, 如果需要新增实例,请通过
  213. * mtopsdk_configuration.plist 配置文件来新增实例,只有在 plist 中注册过的ID,才可以使用。配置文件配置规则(示例)如下:
  214. *
  215. * ROOT (dictionary)
  216. * |---ExternalInstances (dictionary)
  217. * |---- @"id1":@"0" (0 表示该实例类型为二方实例)
  218. * |-----@"id2":@"1" (1 表示该实例类型为三方实例)
  219. *
  220. * 注意:ID为 MTOP_ID_INNER 与 MTOP_ID_OPEN 实例不可在配置文件中修改类型,已经分别设置为二方、三方实力。若不是
  221. * MTOP_ID_INNER 与 MTOP_ID_OPEN,且名称未在plist中注册,返回nil.
  222. *
  223. * @param Id 索引MTOP实例的KEY值。可以为 MTOP_ID_INNER/MTOP_ID_OPEN 或者定义在 mtopsdk_configuration.plist 中
  224. * @return MTOP实例。若非内置实例且名称未注册,则返回nil.
  225. */
  226. + (instancetype) shareInstanceWithID:(NSString *)Id;
  227. /**
  228. * 获取当前实例ID。
  229. */
  230. - (NSString *)ID;
  231. /**
  232. * 获取当前实例类型。
  233. */
  234. - (MtopType)type;
  235. /**
  236. * 打开全站https(默认全站开启HTTPS)
  237. * 该功能为历史功能,目前已经全面切为全站HTTTPS, 已废弃。
  238. */
  239. - (void) enableAllSiteHttps DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
  240. /**
  241. * 关闭全站https(默认全站开启HTTPS)
  242. * 该功能为历史功能,目前已经全面切为全站HTTTPS, 已废弃。
  243. */
  244. - (void) disableAllSiteHttps DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
  245. /**
  246. * 开启白盒秘钥
  247. * 该功能为历史功能,目前已经全站开启白盒秘钥, 该配置已废弃。
  248. */
  249. - (void) enableWhiteSecurity DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
  250. /**
  251. * 关闭白盒秘钥
  252. * 该功能为历史功能,目前已经全站开启白盒秘钥, 该配置已废弃。
  253. */
  254. - (void) unableWhiteSecurity DEPRECATED_MSG_ATTRIBUTE("为保证代码兼容性,暂未删除");
  255. /**
  256. * 设置一个应用级别的请求头, 注意 设置的值不会被持久化,只是在应用生命周期内有效
  257. * @param key 参数名称
  258. * @param value 参数值
  259. *
  260. */
  261. - (void) setApplicationRequestHeader: (NSString*) value forKey: (NSString*) key;
  262. /**
  263. * 获取一个应用级别的请求头的值
  264. * @param name 参数名称
  265. * @return setApplicationRequestHeader设置的值
  266. */
  267. - (NSString*) getApplicationRequestHeader: (NSString*) name;
  268. /**
  269. * 获取当前的应用级别的请求头
  270. * @return 全部KV
  271. */
  272. - (NSDictionary*) getCurrentApplicationRequestHeader;
  273. /**
  274. * 移除一个应用级别的请求头
  275. * @param name
  276. *
  277. */
  278. - (void) removeApplicationRequestHeader: (NSString*) name;
  279. /**
  280. * 移除所以应用级别的请求头
  281. * @param name
  282. *
  283. */
  284. - (void) removeAllApplicationRequestHeader;
  285. /**
  286. * 设置一个应用级别的请求但不需要URL-Encoding的头, 注意 设置的值不会被持久化,只是在应用生命周期内有效
  287. * @param key 参数名称
  288. * @param value 参数值
  289. *
  290. */
  291. - (void) setApplicationRequestHeaderWithoutEncoding: (NSString*) value forKey: (NSString*) key;
  292. /**
  293. * 获取当前的应用级别的请求头
  294. * @return 全部KV
  295. */
  296. - (NSDictionary*) getCurrentApplicationRequestHeaderWithoutEncoding;
  297. /**
  298. * 从磁盘加载配置参数
  299. */
  300. - (void) loadAVCV;
  301. /**
  302. * 获取当前发送MTOP请求所在VC
  303. */
  304. - (NSString*)currentPageName;
  305. /**
  306. * 获取当前发送MTOP请求所在容器访问的URL
  307. */
  308. - (NSString*)currentPageUrl;
  309. /**
  310. * 设置环境. 该参数只有类型为二方(kTypeInner)时起作用,其有两层作用:
  311. *
  312. * 1)指定网关: 在二方环境中,阿里的默认的做法都是分为线上、预发、日常三套环境,不同环境指向不同的网关域名,
  313. * 若为二方环境,这些域名都已经内置,APP只要设置环境即可;
  314. * 2)指定Appkey/Appsecrect: 在二方环境中, 为保证安全,其Appkey/Appsecrect一般都是保存在无线保镖的
  315. * 的安全文件中,SDK 通过该参数,可以直接通过无线保镖SDK读取所需要的Appkey,以及加签等动作。
  316. *
  317. * 若为三方(kTypeOpen)类型,则该参数忽略。
  318. */
  319. + (void)setEnvironment:(TBSDKEnvironment)env;
  320. /**
  321. * 当前环境
  322. */
  323. + (TBSDKEnvironment)currentEnvironment;
  324. /**
  325. * 全局默认实例ID。
  326. * 该值从 MTOP SDK 配置文件 mtopsdk_configuration.plist 中的 DefaultID 字段读取,若没有该配置文件,
  327. * 默认返回 MTOP_ID_INNER。该参数在 mtopsdk_configuration.plist 文件中配置:
  328. *
  329. * Root (Dictionary)
  330. * |
  331. * |---DefaultID : @"INNER" (@"INNER" 内置二方实例; @“OPEN” 内置三方实例;或其他自定义实例 )
  332. */
  333. + (NSString *)defaultID;
  334. //! 请将api字符串转换为小写
  335. + (void)addEcodeSignAPI:(NSArray *)API;
  336. + (NSDate *)timeStampFixedWithServer;
  337. @end