igsdk 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +423 -0
  2. package/package.json +3 -4
  3. package/README-CN.html +0 -696
package/README.md ADDED
@@ -0,0 +1,423 @@
1
+ # iGlees SDK文档
2
+
3
+
4
+
5
+ ## SDK简介
6
+
7
+ iGlees SDK为Cocos开发者提供了广告、网络请求、加解密、缓存数据等功能。
8
+
9
+
10
+
11
+ ## SDK集成
12
+
13
+ #### 说明
14
+
15
+ iGlees SDK的所有功能均放在IG命名空间,然后根据具体的功能模块进行调用。比如IG.IGSdk,IG.HttpWrapper等。
16
+
17
+
18
+
19
+ #### 初始化SDK
20
+
21
+ 在使用iGlees SDK前,请务必先调用初始化方法完成SDK的初始,具体如下:
22
+
23
+ ```typescript
24
+ /**
25
+ * 初始化(注:使用SDK功能前调用,只需要调用一次,建议进入首个场景就调用)
26
+ * @param sys 当前系统对象 (CocosCreator<3.0时传cc.sys,CocosCreator>=3.0时传sys)
27
+ * @param reflection 反射对象(打包原生平台时需要设置,CocosCreator<=3.5时传jsb.reflection, CocosCreator>=3.6时传native.reflection)
28
+ * @param logLevel 日志等级(线上环境设置为LOG_ERROR或OFF)
29
+ * @param 是否初始化成功
30
+ */
31
+ static init(sys: any, reflection?: any, logLevel?: LOG_LEVEL): boolean;
32
+
33
+ //初始化SDK
34
+ IG.IGSdk.init(sys, sys.isNative ? jsb.reflection : null, IG.LOG_LEVEL.DEBUG);
35
+ ```
36
+
37
+
38
+
39
+ #### 广告模块
40
+
41
+ ###### 初始化广告SDK
42
+
43
+ 在使用广告模块时,需先初始化广告SDK,具体如下:
44
+
45
+ ```typescript
46
+ /**
47
+ * 初始化广告SDK
48
+ * @param initOpt 初始化可配置参数
49
+ * @param callback 初始化回调
50
+ */
51
+ static init(initOpt: ASWInitOpt, callback?: ASWInitCallback): void;
52
+
53
+ //初始化广告SDK
54
+ let initOpt = new IG.ASWInitOpt();
55
+ initOpt.mediaIdWeb = '11';
56
+ initOpt.mediaIdAndroid = '9';
57
+ initOpt.mediaIdIOS = '10';
58
+ initOpt.mediaId = '11';
59
+ initOpt.channel = "";
60
+ initOpt.customData = "";
61
+ initOpt.showLog = true;
62
+ initOpt.test = true;
63
+ IG.AdSdkWrapper.init(initOpt, (code, msg) => {
64
+ console.log(`Init sdk : code=${code} , msg=${msg}`);
65
+ });
66
+ ```
67
+
68
+ 其中,初始化可配参数ASWInitOpt定义如下:
69
+
70
+ ```typescript
71
+ /**
72
+ * 初始化参数
73
+ */
74
+ export class ASWInitOpt extends InitOpt {
75
+ //Web端媒体id
76
+ public mediaIdWeb: string;
77
+ //Android端媒体id
78
+ public mediaIdAndroid: string;
79
+ //iOS端媒体id
80
+ public mediaIdIOS: string;
81
+ //鸿蒙端媒体id
82
+ public mediaIdOpenHarmony: string;
83
+ }
84
+
85
+ /**
86
+ * 初始化可配置参数
87
+ */
88
+ export class InitOpt {
89
+ //媒体标识(必传)
90
+ public mediaId: string = "";
91
+ //自定义渠道标识。广告数据可以根据自定义渠道进行拆分
92
+ public channel: string = "";
93
+ //自定义数据,最长255字符。激励视频服务端验证时,该数据会回调给服务器
94
+ public customData: string = ""
95
+ // 是否显示日志,默认不显示。线上环境应设置成false
96
+ public showLog: boolean = false;
97
+ //是否打开测试模式。正式上线前请设置为false,否则将不产生收益
98
+ public test: boolean = false;
99
+ }
100
+ ```
101
+
102
+
103
+
104
+ ###### 请求广告
105
+
106
+ ```typescript
107
+ /**
108
+ * 请求广告
109
+ * @param adOpt 请求广告可配置参数
110
+ * @param callback 请求广告回调
111
+ */
112
+ static requestAd(adOpt: ASWAdOpt, callback?: ASWAdCallback): void;
113
+
114
+ //请求广告
115
+ let adOpt = new IG.ASWAdOpt();
116
+ adOpt.adIdWeb = '3';
117
+ adOpt.adIdWechatGame = 'adunit-6c232b47c4cc6f9b';
118
+ adOpt.adIdAndroid = '37';
119
+ adOpt.adType = IG.AD_TYPE.REWARD_VIDEO;
120
+ IG.AdSdkWrapper.requestAd(adOpt, {
121
+ onAdReward(adId) {
122
+ console.log(`ad[${adId}] reward.`);
123
+ },
124
+ });
125
+ ```
126
+
127
+ 其中,请求广告可配置参数ASWAdOpt定义如下:
128
+
129
+ ```typescript
130
+ /**
131
+ * 请求广告参数
132
+ */
133
+ export class ASWAdOpt {
134
+ //广告类型(小游戏使用)
135
+ public adType: AD_TYPE;
136
+ //Web端广告位id
137
+ public adIdWeb: string;
138
+ //Android端广告位id
139
+ public adIdAndroid: string;
140
+ //iOS端广告位id
141
+ public adIdIOS: string;
142
+ //鸿蒙端广告位id
143
+ public adIdOpenHarmony: string;
144
+ //微信小游戏端广告位id
145
+ public adIdWechatGame: string;
146
+ //抖音小游戏端广告位id
147
+ public adIdDouYinGame: string;
148
+ }
149
+ ```
150
+
151
+ 其中,请求广告回调ASWAdCallback定义如下:
152
+
153
+ ```typescript
154
+ /**
155
+ * 请求广告回调接口
156
+ */
157
+ export interface ASWAdCallback {
158
+ /**
159
+ * 加载广告成功回调
160
+ * @param adId 广告位id
161
+ */
162
+ onAdLoad?(adId: string): void;
163
+
164
+ /**
165
+ * 广告曝光回调
166
+ * @param adId 广告位id
167
+ */
168
+ onAdShow?(adId: string): void;
169
+
170
+ /**
171
+ * 广告点击回调(Web平台不一定回调)
172
+ * @param adId 广告位id
173
+ */
174
+ onAdClick?(adId: string): void;
175
+
176
+ /**
177
+ * 激励视频可以奖励回调
178
+ * @param adId 广告位id
179
+ */
180
+ onAdReward?(adId: string): void;
181
+
182
+ /**
183
+ * 激励视频观看完成回调
184
+ * @param adId 广告位id
185
+ */
186
+ onAdComplete?(adId: string): void;
187
+
188
+ /**
189
+ * 广告关闭回调(Web平台不一定回调)
190
+ * @param adId 广告位id
191
+ */
192
+ onAdDismiss?(adId: string): void;
193
+
194
+ /**
195
+ * 广告加载失败回调
196
+ * @param adId 广告位id
197
+ * @param code 错误码
198
+ * @param msg 错误消息
199
+ */
200
+ onAdError?(adId: string, code: number, msg: string): void;
201
+ }
202
+ ```
203
+
204
+
205
+
206
+ #### 网络请求模块
207
+
208
+ ###### 设置HTTP请求配置
209
+
210
+ ```typescript
211
+ /**
212
+ * 设置Http请求配置(请求之前设置)
213
+ * @param httpConfig Http请求配置
214
+ */
215
+ static setConfig(httpConfig: HttpWrapperConfig): void;
216
+
217
+ //构建HTTP请求配置
218
+ let httpConfig = new IG.HttpWrapperConfig();
219
+ httpConfig.baseUrl = 'https://rx.dijikj.com/flkapi/';
220
+ httpConfig.version = '1.1.1';
221
+ httpConfig.channel = 'officail';
222
+ //设置HTTP请求配置
223
+ IG.HttpWrapper.setConfig(httpConfig);
224
+ ```
225
+
226
+ 其中,HTTP配置HttpWrapperConfig定义如下:
227
+
228
+ ```typescript
229
+ /**
230
+ * Http请求配置
231
+ */
232
+ export class HttpWrapperConfig extends HttpConfig {
233
+ //请求基地址
234
+ public baseUrl?: string;
235
+ //客户端版本号
236
+ public version?: string;
237
+ //渠道标识
238
+ public channel?: string;
239
+ //签名前缀
240
+ public signPrefix?: string;
241
+ //AES加密秘钥
242
+ public key?: string;
243
+ //AES加密向量
244
+ public iv?: string;
245
+ }
246
+
247
+ /**
248
+ * Http请求配置
249
+ */
250
+ export class HttpConfig {
251
+ //请求超时时间(ms)
252
+ public timeout: number = 5000;
253
+ }
254
+ ```
255
+
256
+
257
+
258
+ ###### 发起请求
259
+
260
+ ```typescript
261
+ /**
262
+ * GET请求
263
+ * @param path 请求路径
264
+ * @param callback 请求回调
265
+ */
266
+ get<T extends HttpResData>(path: string, callback?: HttpCallbackBean<T>): void;
267
+
268
+ /**
269
+ * POST请求
270
+ * @param path 请求路径
271
+ * @param params 请求参数
272
+ * @param callback 请求回调
273
+ */
274
+ post<T extends HttpResData>(path: string, params?: object, callback?: HttpCallbackBean<T>): void;
275
+
276
+
277
+ //构建回调
278
+ let callback = new IG.HttpCallbackBean<LoginResData>();
279
+ callback.onFail = (code: number, msg: string) => {
280
+ console.error(`Http request fail: code=${code} , msg=${msg}`);
281
+ };
282
+ callback.onRes = (data: LoginResData) => {
283
+ //缓存token
284
+ IG.HttpWrapper.setToken(data.data.token);
285
+ }
286
+ //构建请求参数
287
+ let param = new LoginParam();
288
+ param.type = 1;
289
+ param.mobile = '13617678127';
290
+ param.code = '123454321';
291
+ //发起请求
292
+ new IG.HttpWrapper().post<LoginResData>('user/login', param, callback);
293
+ ```
294
+
295
+
296
+
297
+ #### 加解密模块
298
+
299
+ ```typescript
300
+ /**
301
+ * 加解密工具类
302
+ */
303
+ export class CryptoUtil {
304
+ /**
305
+ * 设置配置(未设置时使用默认秘钥、向量)
306
+ * @param key 秘钥
307
+ * @param iv 向量
308
+ */
309
+ static setKey(key: string, iv?: string): void;
310
+
311
+ /**
312
+ * 获取秘钥
313
+ * @param key 当前设置的秘钥
314
+ * @returns 秘钥
315
+ */
316
+ private static getKey;
317
+
318
+
319
+ /**
320
+ * 获取向量
321
+ * @param iv 当前设置的向量
322
+ * @returns 向量
323
+ */
324
+ private static getIv;
325
+
326
+ /**
327
+ * MD5(32位小写)
328
+ * @param data 需要MD5的数据
329
+ * @returns MD5后的数据
330
+ */
331
+ static md5(data: string): any;
332
+
333
+ /**
334
+ * AES加密
335
+ * @param data 需要AES加密的数据
336
+ * @param key 秘钥(未设置时,使用默认秘钥)
337
+ * @param iv 向量(未设置时,使用默认向量)
338
+ * @returns AES加密后的数据
339
+ */
340
+ static aesEncrypty(data: string, key?: string, iv?: string): any;
341
+
342
+ /**
343
+ * AES解密
344
+ * @param data 需要AES解密的数据
345
+ * @param key 秘钥(未设置时,使用默认秘钥)
346
+ * @param iv 向量(未设置时,使用默认向量)
347
+ * @returns AES解密后的数据
348
+ */
349
+ static aesDecrypt(data: string, key?: string, iv?: string): any;
350
+
351
+ /**
352
+ * Base64加密
353
+ * @param data 需要Base64加密的数据
354
+ * @returns Base64加密后的数据
355
+ */
356
+ static base64Encrpty(data: string): any;
357
+
358
+ /**
359
+ * BASE64 解密
360
+ * @param data 需要Base64解密的数据
361
+ * @returns Base64解密后的数据
362
+ */
363
+ static base64Decrypt(data: string): any;
364
+
365
+ /**
366
+ * 生成符合UUID v4标准的唯一标识(优化版)
367
+ */
368
+ static uuid(): string;
369
+
370
+ }
371
+ ```
372
+
373
+
374
+
375
+ #### 缓存模块
376
+
377
+ ```typescript
378
+ /**
379
+ * 本地存储工具类
380
+ */
381
+ export class StorageUtil {
382
+
383
+ /**
384
+ * 检查是否可以缓存
385
+ * @param key 数据key
386
+ */
387
+ private static checkAvailable;
388
+
389
+ /**
390
+ * 缓存数据
391
+ * @param key 数据key
392
+ * @param data 数据
393
+ */
394
+ static setData(key: string, data: any): void;
395
+
396
+ /**
397
+ * 获取缓存数据
398
+ * @param key 数据key
399
+ * @returns 数据
400
+ */
401
+ static getData(key: string): string | null;
402
+
403
+ /**
404
+ * 安全缓存数据(数据会加密)
405
+ * @param key 数据key
406
+ * @param data 数据
407
+ * @param encryptKey 加密秘钥(未设置时,使用默认秘钥)
408
+ * @param encryptIv 加密向量(未设置时,使用默认向量)
409
+ */
410
+ static setDataSafely(key: string, data: any, encryptKey?: string, encryptIv?: string): void;
411
+
412
+ /**
413
+ * 获取缓存数据(数据会解密)
414
+ * @param key 数据key
415
+ * @param encryptKey 加密秘钥(未设置时,使用默认秘钥)
416
+ * @param encryptIv 加密向量(未设置时,使用默认向量)
417
+ * @returns 数据
418
+ */
419
+ static getDataSafely(key: string, encryptKey?: string, encryptIv?: string): string | null;
420
+
421
+ }
422
+ ```
423
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "igsdk",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "iGlees sdk for CocosCreator.include ads,http request,utils etc.",
5
5
  "main": "igsdk.js",
6
6
  "types": "igsdk.d.ts",
@@ -16,7 +16,6 @@
16
16
  "license": "MIT",
17
17
  "files": [
18
18
  "igsdk.js",
19
- "igsdk.d.ts",
20
- "README-CN.html"
19
+ "igsdk.d.ts"
21
20
  ]
22
- }
21
+ }