crh-jssdk 0.0.3 → 0.0.5

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.
@@ -1,23 +1,60 @@
1
-
2
1
  //调用sdk通用方法
3
2
  const common = (promise: any, name: string) => {
4
3
  if (!promise) {
5
- return () => Promise.resolve([{ code: '-1', data: null, msg: `jssdk暂不支持${name}方法, 请与管理员联系` }])
4
+ return () =>
5
+ Promise.resolve([
6
+ {
7
+ code: "-1",
8
+ data: null,
9
+ msg: `jssdk暂不支持${name}方法, 请与管理员联系`,
10
+ },
11
+ ]);
6
12
  }
7
13
  return async (...params: any[]) => {
8
- console.log(`方法:${name};请求参数如下:${JSON.stringify(params)}`)
14
+ console.log(`方法:${name};请求参数如下:${JSON.stringify(params)}`);
9
15
  const res = await promise(...params);
10
- return res
16
+ return res;
17
+ };
18
+ };
19
+
20
+ const empty = (name: string) =>
21
+ Promise.resolve([
22
+ { code: "-1", data: null, msg: `jssdk暂不支持${name}方法, 请与管理员联系` },
23
+ ]);
24
+
25
+ const u: string = navigator.userAgent as string;
26
+ const ios: boolean = <boolean>!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
27
+
28
+ function checkIsHarmonyOS() {
29
+ try {
30
+ if (window.HarmonyBridge && window.HarmonyBridge.callJsHandler) {
31
+ return true;
32
+ }
33
+ } catch (e) {
34
+ console.log("获取鸿蒙标识出错");
35
+ console.log(e);
11
36
  }
37
+ return false;
12
38
  }
13
39
 
14
- const empty = (name: string) => Promise.resolve([{ code: '-1', data: null, msg: `jssdk暂不支持${name}方法, 请与管理员联系` }])
15
-
16
- var u: string = navigator.userAgent as string
17
- var ios: boolean = <boolean>!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
40
+ /**
41
+ * @desc 调用鸿蒙方法
42
+ * @param key
43
+ * @param data
44
+ */
45
+ function harmonyCallJsHandler(key: string, data: string | object) {
46
+ var params = {};
47
+ try {
48
+ if (typeof data === "string") {
49
+ params = JSON.parse(data);
50
+ } else {
51
+ params = data;
52
+ }
53
+ } catch (_) {
54
+ params = {};
55
+ }
56
+ console.log('调用 HarmonyBridge: ', key, JSON.stringify(params))
57
+ window.HarmonyBridge.callJsHandler(key, JSON.stringify(params))
58
+ }
18
59
 
19
- export {
20
- common,
21
- empty,
22
- ios
23
- }
60
+ export { common, empty, ios, checkIsHarmonyOS, harmonyCallJsHandler };
@@ -0,0 +1,587 @@
1
+ import { ios } from "../common/utils";
2
+
3
+ //解析opStation
4
+ const parsOpStation = (json: string) => {
5
+ // 匹配任何键名为字符串并且对应值为字符串的情况
6
+ const regex = /"([^"]+)":"({[^}]+})"/g;
7
+ let result = json;
8
+
9
+ // 循环匹配所有键值对
10
+ let match;
11
+ while ((match = regex.exec(json)) !== null) {
12
+ const key = match[1];
13
+ const valueStr = match[2];
14
+ try {
15
+ const valueObj = JSON.parse(valueStr);
16
+ // 将解析后的对象替换原始字符串中的对应键值对
17
+ result = result.replace(
18
+ `"${key}":"${valueStr}"`,
19
+ `"${key}":${JSON.stringify(valueObj)}`
20
+ );
21
+ } catch (e) {
22
+ console.error(`转为json格式有误,key为=> "${key}":`, e);
23
+ }
24
+ }
25
+
26
+ return result;
27
+ };
28
+
29
+ /**
30
+ * @name 版本号比较
31
+ * @param {string} version1 版本号1
32
+ * @param {string} version2 版本号2
33
+ * @returns 1: 版本1大于版本2 | -1: 版本1小于版本2 | 0: 版本相等
34
+ */
35
+ const compareVersion = (version1: any, version2: any) => {
36
+ version1 = version1.split('.');
37
+ version2 = version2.split('.');
38
+ const n = Math.max(version1.length, version2.length);
39
+ for (let i = 0; i < n; i++) {
40
+ const code1 = version1[i] === undefined ? 0 : parseInt(version1[i], 10);
41
+ const code2 = version2[i] === undefined ? 0 : parseInt(version2[i], 10);
42
+ if (code1 > code2) {
43
+ return 1;
44
+ }
45
+ if (code1 < code2) {
46
+ return -1;
47
+ }
48
+ }
49
+ return 0;
50
+ };
51
+
52
+ const APPID = 'b5bae4daa01aa0c2';
53
+
54
+ // webview类型
55
+ const webviewType = (() => {
56
+ const ua = navigator.userAgent;
57
+ const isWTSDK = ua.includes('cxzqwtsdk');
58
+ return {
59
+ isWTSDK,
60
+ // 新乐赚
61
+ isNewLeZhuan: !isWTSDK && ua.toLowerCase().includes('lezhuan'),
62
+ // 新聚财
63
+ isNewJuCai:
64
+ !isWTSDK &&
65
+ !ua.includes('crhsdk') &&
66
+ (ua.includes('Android_CFZQ_JUCAI') || ua.includes('iOS_CFZQ_JUCAI')),
67
+ // 老聚财
68
+ isOldJuCai: ua.includes('crhsdk') && !ua.includes('cfzqsdk'),
69
+ isLeZhuan: (!isWTSDK && ua.toLowerCase().includes('lezhuan')) || ua.includes('cfzqsdk'),
70
+ isCRH: ua.includes('crhsdk') || ua.includes('crhapp')
71
+ };
72
+ })();
73
+
74
+ const actionMap = {
75
+ // 财信处理action地址方法
76
+ onJsOverrideUrlLoading(str: string) {
77
+ if (ios && window.webkit?.messageHandlers?.lzforward) {
78
+ window.webkit.messageHandlers.lzforward?.postMessage(str);
79
+ } else if (window.MyWebView && window.MyWebView.onJsOverrideUrlLoading) {
80
+ window.MyWebView.onJsOverrideUrlLoading(str);
81
+ } else {
82
+ window.location.href = str;
83
+ }
84
+ },
85
+ // 财信调用action路径
86
+ callAction(actionId: string | number, param?: any, cbFunName?: any) {
87
+ let url = `http://action:${actionId}/?target=2`;
88
+ if (param) {
89
+ const paramStr = JSON.stringify(param);
90
+ url += `&param=${encodeURIComponent(paramStr)}`;
91
+ }
92
+ if (cbFunName) {
93
+ url += `&callback=${cbFunName}`;
94
+ }
95
+ console.log('callAction:', url);
96
+ this.onJsOverrideUrlLoading(url);
97
+ },
98
+ // 财信聚财通过js bridge调用app接口
99
+ setupWebViewJavascriptBridge(callback: any) {
100
+ if (window.WebViewJavascriptBridge) {
101
+ callback(window.WebViewJavascriptBridge);
102
+ } else {
103
+ document.addEventListener(
104
+ 'WebViewJavascriptBridgeReady',
105
+ () => {
106
+ callback(window.WebViewJavascriptBridge);
107
+ },
108
+ false
109
+ );
110
+ if (!/android/gi.test(navigator.userAgent)) {
111
+ if (window.WebViewJavascriptBridge) {
112
+ callback(window.WebViewJavascriptBridge);
113
+ return;
114
+ }
115
+ if (window.WVJBCallbacks) {
116
+ window.WVJBCallbacks.push(callback);
117
+ return;
118
+ }
119
+ window.WVJBCallbacks = [callback];
120
+ const WVJBIframe = document.createElement('iframe');
121
+ WVJBIframe.style.display = 'none';
122
+ WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
123
+ document.documentElement.appendChild(WVJBIframe);
124
+ setTimeout(() => {
125
+ document.documentElement.removeChild(WVJBIframe);
126
+ }, 0);
127
+ }
128
+ }
129
+ },
130
+ // 聚财Android调用app接口
131
+ callAndroidActionOfJvCai(param: any) {
132
+ const paramStr = JSON.stringify(param);
133
+ if (window.mobile) {
134
+ window.mobile.onActionEvent(paramStr);
135
+ }
136
+ },
137
+ // 财信调用聚财方法
138
+ callJuCaiAction(funName: any, data?: any, callback?: any) {
139
+ console.log('callJuCaiAction:', funName, data, callback);
140
+ if (ios) {
141
+ this.setupWebViewJavascriptBridge((bridge: any) => {
142
+ bridge.callHandler(funName, data, window[callback]);
143
+ });
144
+ } else {
145
+ const param: any = {
146
+ funName,
147
+ callbackFunName: callback
148
+ };
149
+ if (data) {
150
+ param.data = data;
151
+ }
152
+ this.callAndroidActionOfJvCai(param);
153
+ }
154
+ },
155
+ /**
156
+ * iOS客户端方法加载函数(老乐赚老聚财)
157
+ * @param {string} url
158
+ */
159
+ loadIOSNative(url: string) {
160
+ let iFrame: any = '';
161
+ iFrame = document.createElement('iframe');
162
+ iFrame.setAttribute('src', url);
163
+ iFrame.setAttribute('style', 'display:none;');
164
+ iFrame.setAttribute('height', '0px');
165
+ iFrame.setAttribute('width', '0px');
166
+ iFrame.setAttribute('frameborder', '0');
167
+ document.body.appendChild(iFrame);
168
+ iFrame.parentNode.removeChild(iFrame);
169
+ iFrame = null;
170
+ }
171
+ }
172
+
173
+
174
+
175
+ try {
176
+ if (!ios && webviewType.isNewJuCai) {
177
+ actionMap.setupWebViewJavascriptBridge((bridge: any) => {
178
+ bridge.init();
179
+ });
180
+ }
181
+ } catch (e) {
182
+ console.log('初始化失败');
183
+ }
184
+
185
+ export default {
186
+ //是否在app内
187
+ isApp() {
188
+ const ua = navigator.userAgent;
189
+ const isAppFlags = [
190
+ 'crhsdk',
191
+ 'crhapp',
192
+ 'cfzqsdk',
193
+ 'LeZhuan',
194
+ 'LEZHUAN',
195
+ 'Android_CFZQ_JUCAI',
196
+ 'iOS_CFZQ_JUCAI'
197
+ ];
198
+ return isAppFlags.some(flag => ua.includes(flag));
199
+ },
200
+ // 拦截Android物理返回键事件,并回调给前端 --- 仅安卓
201
+ interceptBack(callback: Function) {
202
+ window.jtoJHandle.interceptBack('interceptBackCallBack')
203
+ window.interceptBackCallBack = function (e: any) {
204
+ callback && callback(e)
205
+ }
206
+ },
207
+
208
+ // 关闭页面 closeSJKH
209
+ closeSJKH() {
210
+ if (webviewType.isNewLeZhuan) {
211
+ actionMap.callAction(3);
212
+ } else if (webviewType.isNewJuCai) { // iphone
213
+ actionMap.callJuCaiAction('closePage', {});
214
+ } else if (ios) { // iphone
215
+ window.location.href = 'objc://callIOSQuit/';
216
+ } else {
217
+ window.jtoJHandle.closeSJKH();
218
+ }
219
+ },
220
+ /**
221
+ * 通过打开新的webview打开外部链接
222
+ */
223
+ goWebview(pageId: string | number, url: string, callback: Function) {
224
+ const jsonObj = {
225
+ indexUrl: url,
226
+ uploadPicUrl: '',
227
+ cookieDomain: '',
228
+ closeBusiness: 'closeCallBack',
229
+ module: '',
230
+ identifier: 'zt'
231
+ };
232
+ const jsonStr = JSON.stringify(jsonObj);
233
+ if (webviewType.isNewLeZhuan) {
234
+ actionMap.callAction(207, { pageId: pageId || '1', needLogin: '0' });
235
+ } else if (webviewType.isNewJuCai) {
236
+ actionMap.callJuCaiAction('gotoClientPage', { pageId: ios ? String(pageId) : pageId, needLogin: '0' });
237
+ } else if (ios) { // iphone
238
+ actionMap.loadIOSNative(`objc://openNewBusiness/$?${jsonStr}`);
239
+ } else {
240
+ window.jtoJHandle.openNewBusiness(jsonStr);
241
+ }
242
+ },
243
+ /**
244
+ * 获取用户信息
245
+ */
246
+ getUser() {
247
+ return new Promise(async resolve => {
248
+ window.getUserInfoCB = (actionId: any, response: any = {}) => {
249
+ let isLogin = false;
250
+ let isPhoneLogin = false;
251
+ const statusInfo = response;
252
+ console.log('getUserInfoCB:', actionId, response);
253
+ if (+response.ret !== 0 && !response.login_status) {
254
+ console.warn('调用失败!', 'getUserInfoCB');
255
+ } else {
256
+ if (response.isTradeLogin === 1) {
257
+ console.log('交易已登录');
258
+ isLogin = true;
259
+ }
260
+ if (response.isSnsLogin === 1) {
261
+ console.log('手机号已登录');
262
+ isPhoneLogin = true;
263
+ }
264
+ }
265
+ resolve({
266
+ ...response
267
+ });
268
+ };
269
+ if (webviewType.isNewLeZhuan) {
270
+ actionMap.callAction(909, {}, 'getUserInfoCB');
271
+ } else if (webviewType.isNewJuCai) {
272
+ const data: any = await this.getDeviceInfo();
273
+ // window.getUserInfoCB(null, data);
274
+ resolve({
275
+ ...data
276
+ });
277
+ } else if (webviewType.isOldJuCai) {
278
+ // 老聚财
279
+ const res:any = await this.jcLogin();
280
+ resolve({
281
+ ...res
282
+ });
283
+ } else {
284
+ this.businessAlertView('http://action:909/?target=2&callback=getUserInfoCB');
285
+ }
286
+ });
287
+ },
288
+ // 获取客户端用户和设备信息
289
+ getDeviceInfo(type = 'fetch') {
290
+ console.log('getDeviceInfo----');
291
+ return new Promise(async resolve => {
292
+ window.getDeviceInfoCB = (actionId: any, info = {}) => {
293
+ console.log('getDeviceInfo回调:', actionId, info);
294
+ /**
295
+ * info = "{"appName":"lezhuan","channel":"38106","clientId":"200030002048","deviceId":"dd2375d70947a02a","isp":"CU","mac":"1CB796216DC3","mobileType":"Android","model":"SEA-AL10","netType":"wifi","osVer":"10","phoneNo":"18888888888","resolution":"1080*2259","ret":0,"version":"5.7.0","appConfig":{"canShowMonitor":1,"dailybill":1,"globalQuotation":0,"imSwitch":1,"isShowStockNewsTag":1,"magicNineTurn":1,"onekeyLogin":1,"profitLossFlag":1,"searchMethod":2,"stockDetailNews":1},"grayRelease":{"WEALTH_TAB":0,"quotationNews":1,"CONDITION_SHEET":1}}"
296
+ */
297
+ if (typeof info === 'string') {
298
+ info = JSON.parse(info);
299
+ }
300
+ resolve({
301
+ ...info,
302
+ });
303
+ delete window.getDeviceInfoCB;
304
+ };
305
+ if (webviewType.isNewLeZhuan) {
306
+ actionMap.callAction(903, {}, 'getDeviceInfoCB');
307
+ } else if (webviewType.isNewJuCai) {
308
+ const data: any = await this.jcLogin('fetch');
309
+ console.log(data, 'data');
310
+ resolve({ ...data })
311
+ } else {
312
+ if (ios) {
313
+ actionMap.loadIOSNative('objc://getDeviceInfo/?getDeviceInfoCB');
314
+ } else {
315
+ window.jtoJHandle?.getDeviceInfo('getDeviceInfoCB');
316
+ }
317
+ }
318
+ });
319
+ },
320
+ // 聚财获取登录信息或者未登录调起登录,调登录type传callback_after_login
321
+ jcLogin(type = 'fetch') {
322
+ return new Promise(resolve => {
323
+ if (webviewType.isNewJuCai) {
324
+ const data = { info_type: 'wt', call_type: type, key_type: '' };
325
+ actionMap.setupWebViewJavascriptBridge((bridge: any) => {
326
+ bridge.callHandler('getUserInfoByRsa', data, (info: any) => {
327
+ console.log('getNewJcDeviceInfoCB:', info);
328
+ const deviceInfo:any = {};
329
+ const mobileInfo = info.mobile_hardware
330
+ ? info.mobile_hardware.replace('HDInfo=', '').split(',')
331
+ : [];
332
+ mobileInfo.forEach((item: any) => {
333
+ const index = item.indexOf(':');
334
+ deviceInfo[item.substring(0, index)] = item.substring(index + 1);
335
+ });
336
+ console.log('deviceInfo:', deviceInfo);
337
+ resolve({
338
+ ...info,
339
+ deviceInfo,
340
+ isLogin: info.login_status === '1',
341
+ token: info.param,
342
+ fundAccount: '',
343
+ mobile: deviceInfo.RMRN || ''
344
+ });
345
+ });
346
+ });
347
+ } else if (webviewType.isOldJuCai) {
348
+ window.oldJuCaiLoginCB = (token: any) => {
349
+ console.log('oldJuCaiLoginCB:', token);
350
+ resolve({
351
+ isLogin: !!token,
352
+ token: JSON.parse(JSON.stringify(token)),
353
+ fundAccount: '',
354
+ mobile: ''
355
+ });
356
+ };
357
+ if (ios) {
358
+ window.location.href = 'objc://getUser/?oldJuCaiLoginCB';
359
+ } else if (window.jtoJHandle) {
360
+ window.jtoJHandle.getUser('oldJuCaiLoginCB');
361
+ }
362
+ }
363
+ });
364
+ },
365
+ // app各种方法:交易密码登录框、银证转账充值等。
366
+ // 参数格式:http://action:actionID/?target=tType&callback=funName&param=requestJSON
367
+ businessAlertView(url: string, callback?: any) {
368
+ console.log('businessAlertView:', url, callback);
369
+ if (ios) {
370
+ if (callback) {
371
+ url = `${url}$?${callback}`;
372
+ }
373
+ actionMap.loadIOSNative(`objc://businessAlertView/$?${url}`);
374
+ } else if (window.jtoJHandle) {
375
+ if (callback) {
376
+ window.jtoJHandle.businessAlertView(url, callback);
377
+ } else {
378
+ window.jtoJHandle.businessAlertView(url);
379
+ }
380
+ } else {
381
+ }
382
+ },
383
+ // 获取交易登录的token(弹出登录框)
384
+ getTradeLoginToken(appid?: string) {
385
+ const tradeParam = { appId: appid || APPID };
386
+ console.log('tradeParam:', tradeParam);
387
+ return new Promise(async resolve => {
388
+ // 乐赚交易登录回调获取token准备传入u001
389
+ window.getTradeLoginTokenCB = (actionId: any, response:any) => {
390
+ console.log('getTradeLoginTokenCB:', actionId, response);
391
+ if (response.ret === 0) {
392
+ resolve(response.token);
393
+ } else {
394
+ resolve('');
395
+ }
396
+ delete window.getTradeLoginTokenCB;
397
+ };
398
+ if (webviewType.isNewLeZhuan) {
399
+ actionMap.callAction(209, tradeParam, 'getTradeLoginTokenCB');
400
+ } else if (webviewType.isNewJuCai) {
401
+ const res: any = await this.getDeviceInfo();
402
+ console.log(res, 'res')
403
+ if (!res.isLogin) {
404
+ const jcLoginRes: any = await this.jcLogin('callback_after_login');
405
+ resolve(jcLoginRes.token);
406
+ } else {
407
+ resolve(res.token);
408
+ }
409
+ } else if (webviewType.isOldJuCai) {
410
+ const jcLoginRes: any = await this.jcLogin('callback_after_login');
411
+ resolve(jcLoginRes.token);
412
+ } else {
413
+ this.businessAlertView(
414
+ `http://action:209/?target=2&callback=getTradeLoginTokenCB&param=${encodeURIComponent(
415
+ JSON.stringify(tradeParam)
416
+ )}`
417
+ );
418
+ }
419
+ });
420
+ },
421
+ /**
422
+ * 获取手机号token
423
+ * @returns {string} token
424
+ */
425
+ getPhoneToken() {
426
+ return new Promise(async resolve => {
427
+ window.communityLoginCB = (actionId: any, response: any) => {
428
+ console.log(`社区token的值:`, actionId, response.token);
429
+ if (response.ret === 0) {
430
+ resolve(`${response.token},${APPID}`);
431
+ } else {
432
+ resolve('');
433
+ }
434
+ };
435
+ const communityParam = { appId: APPID, tokenRetry: true };
436
+ if (webviewType.isNewLeZhuan) {
437
+ actionMap.callAction(229, communityParam, 'communityLoginCB');
438
+ } else if (webviewType.isNewJuCai) {
439
+ const res: any = await this.getDeviceInfo();
440
+ resolve(res.token);
441
+ } else {
442
+ this.businessAlertView(
443
+ `http://action:229/?target=2&callback=communityLoginCB&param=${encodeURIComponent(
444
+ JSON.stringify(communityParam)
445
+ )}`
446
+ );
447
+ }
448
+ });
449
+ },
450
+ /**
451
+ * 获取客户端版本号
452
+ */
453
+ getVersion() {
454
+ const ua = navigator.userAgent.toLowerCase();
455
+ let regex: any = '';
456
+ if (webviewType.isNewLeZhuan) {
457
+ regex = ios ? /cfzq_lezhuan_([\d.]+)/ : /cfzq_lezhuan([\d.]+)/;
458
+ } else if (webviewType.isNewJuCai) {
459
+ regex = /cfzq_jucai_([\d.]+)/;
460
+ }
461
+ const match = ua.match(regex);
462
+
463
+ if (match) {
464
+ const version = match[1];
465
+ return version;
466
+ } else {
467
+ console.warn('version没有找到匹配项');
468
+ return '0.0.0';
469
+ }
470
+ },
471
+ /**
472
+ * 设置原生状态栏颜色(乐赚客户端)
473
+ * @param {object} params
474
+ * @param {string} params.color 状态栏背景颜色,如#ff0000
475
+ * @param {string} params.wordColorStyle 状态栏文字颜色,0 白色,1 黑色
476
+ */
477
+ async setStatusBar(params: any) {
478
+ if (webviewType.isNewLeZhuan) {
479
+ if (compareVersion('6.1.0', this.getVersion()) === 1) {
480
+ console.log('---版本号低,无法设置状态栏颜色---');
481
+ return;
482
+ }
483
+ let data = {
484
+ statusColor: params.color,
485
+ isDark: params.wordColorStyle === '1'
486
+ };
487
+ actionMap.callAction(933, data);
488
+ } else if (webviewType.isCRH) {
489
+ if (ios) {
490
+ actionMap.loadIOSNative(`objc://setAppBackgroundColor/$?${params.color}`);
491
+ } else if (window.jtoJHandle) {
492
+ window.jtoJHandle.setAppBackgroundColor(params.color);
493
+ }
494
+ }
495
+ },
496
+
497
+ /**
498
+ * 产品收藏
499
+ * @param {object} params
500
+ * @param {string} params.versionList 支持自选的版本号
501
+ * @param {string} params.productNo 产品编号
502
+ * @param {string} params.productCode 产品代码
503
+ * @param {string} params.categoryId 产品类型
504
+ * @param {string} params.actionType 操作类型 1:收藏2:取消收藏3:查询是否收藏
505
+ * @param {string} params.callbackName 回调函数
506
+ */
507
+ setCollect(params: { versionList: string [], productNo: string | number, productCode: string | number, categoryId: string | number, actionType: string | number, callbackName: string }) {
508
+ const sdkParams = { productNo: params.productNo, productCode: params.productCode, categoryId: params.categoryId, actionType: params.actionType};
509
+ return new Promise(async resolve => {
510
+ if (params.versionList.indexOf(this.getVersion()) > -1 && webviewType.isNewLeZhuan) {
511
+ window.callAfterFavor = (actionId: any, data: any) => {
512
+ console.log(data, 'ret');
513
+ resolve({
514
+ error_no: '0',
515
+ error_info: '',
516
+ ...data
517
+ })
518
+ };
519
+ actionMap.callAction(909, {}, 'getUserInfo');
520
+ const userInfo: any = await this.getUser();
521
+ if (userInfo.ret !== 0 && !userInfo.login_status) {
522
+ resolve({
523
+ error_no: '-1',
524
+ error_info: '调用失败'
525
+ })
526
+ } else {
527
+ if (userInfo.isSnsLogin === 0) {
528
+ resolve({
529
+ error_no: '-2',
530
+ error_info: '社区未登录'
531
+ })
532
+ } else {
533
+ actionMap.callAction(107, sdkParams, 'callAfterFavor');
534
+ }
535
+ }
536
+ } else {
537
+ resolve({
538
+ error_no: '-3',
539
+ error_info: '请在最新版财信证券APP中添加理财自选'
540
+ })
541
+ }
542
+ })
543
+ },
544
+
545
+ /**
546
+ * 银证转账
547
+ * @param {string} version 支持半屏转账的版本号
548
+ * @param {string} callbackName 回调函数
549
+ */
550
+ async goBankTransfer(version: string | number = '7.2.0', callbackName?: string) {
551
+ if (webviewType.isNewLeZhuan) {
552
+ if (compareVersion(version, this.getVersion()) === 1) {
553
+ actionMap.callAction(218, { transType: '1' }, callbackName);
554
+ } else {
555
+ actionMap.callAction(939, { transType: '1' }, callbackName);
556
+ }
557
+ } else if (webviewType.isNewJuCai) {
558
+ actionMap.callJuCaiAction('gotoClientPage', { pageId: '2621', needLogin: '0' });
559
+ } else {
560
+ this.businessAlertView('http://action:218/?target=2', '');
561
+ }
562
+ },
563
+
564
+ /**
565
+ * 分享
566
+ * @param {object} params
567
+ * @param {string} params.img_url 分享展示的图片
568
+ * @param {string} params.url 分享链接
569
+ * @param {string} params.title 标题
570
+ * @param {string} params.message 内容
571
+ */
572
+ async share(params: { img_url?: any, url?: any, title?: any, message?: any }) {
573
+ if (webviewType.isLeZhuan) {
574
+ const shareParam = {
575
+ img_url: params.img_url,
576
+ url: params.url,
577
+ title: params.title,
578
+ message: params.message
579
+ };
580
+ if (webviewType.isNewJuCai) {
581
+ actionMap.callAction(900, shareParam, '');
582
+ } else {
583
+ this.businessAlertView(`http://action:900/?target=2&param=${encodeURIComponent(JSON.stringify(shareParam))}`);
584
+ }
585
+ }
586
+ }
587
+ };
@@ -1,4 +1,4 @@
1
- import { ios } from '../common/utils'
1
+ import { ios, checkIsHarmonyOS, harmonyCallJsHandler } from "../common/utils";
2
2
 
3
3
  //解析opStation
4
4
  const parsOpStation = (json: string) => {
@@ -31,11 +31,15 @@ export default {
31
31
  getDeviceInfo(fn?: <T>(v: T) => {}) {
32
32
  if (ios) {
33
33
  window.location.href = "objc://getDeviceInfo/?getDeviceInfoCallBack";
34
+ } else if (checkIsHarmonyOS()) {
35
+ harmonyCallJsHandler("getDeviceInfo", {
36
+ callback: "getDeviceInfoCallBack",
37
+ });
34
38
  } else {
35
39
  window.jtoJHandle.getDeviceInfo("getDeviceInfoCallBack");
36
40
  }
37
41
 
38
- window.getDeviceInfoCallBack = function(res: any) {
42
+ window.getDeviceInfoCallBack = function (res: any) {
39
43
  console.log("getDeviceInfo-sdk", res);
40
44
  let data: any = {};
41
45
  try {
@@ -67,4 +71,89 @@ export default {
67
71
  fn && fn(real_res);
68
72
  };
69
73
  },
74
+
75
+ // 拦截Android物理返回键事件,并回调给前端 --- 仅安卓 鸿蒙
76
+ interceptBack(callback: Function) {
77
+ if (checkIsHarmonyOS()) {
78
+ harmonyCallJsHandler("interceptBack", {
79
+ callback: "interceptBackCallBack",
80
+ });
81
+ } else {
82
+ window.jtoJHandle.interceptBack('interceptBackCallBack')
83
+ }
84
+
85
+ window.interceptBackCallBack = function (e: any) {
86
+ callback && callback(e)
87
+ }
88
+ },
89
+
90
+ // 关闭页面 closeSJKH
91
+ callQuit() {
92
+ if (ios) {
93
+ window.location.href = "objc://callIOSQuit";
94
+ } else if (checkIsHarmonyOS()) {
95
+ harmonyCallJsHandler("closeSJKH", '');
96
+ } else {
97
+ window.jtoJHandle.interceptBack('closeSJKH')
98
+ }
99
+ },
100
+
101
+ goWebview(title: string, url: string, callback: Function) {
102
+ const params = {
103
+ title: title,
104
+ url: url,
105
+ callback: 'openOwnPageCallBack'
106
+ }
107
+ if (ios) {
108
+ window.location.href = `objc://openOwnPage/$?${JSON.stringify(params)}"`;
109
+ } else if (checkIsHarmonyOS()) {
110
+ harmonyCallJsHandler("openOwnPage", params);
111
+ } else {
112
+ window.jtoJHandle.openOwnPage(JSON.stringify(params))
113
+ }
114
+ window.openOwnPageCallBack = function (e: any) {
115
+ callback && callback(e)
116
+ }
117
+ },
118
+ // 获取用户信息
119
+ getUser() {
120
+ return new Promise((resolve) => {
121
+ if (ios) {
122
+ window.location.href = "objc://getUser/?getUserCallBack";
123
+ } else if (checkIsHarmonyOS()) {
124
+ harmonyCallJsHandler("getUser", {
125
+ callback: "getUserCallBack",
126
+ });
127
+ } else if (window.jtoJHandle) {
128
+ window.jtoJHandle.getUser("getUserCallBack");
129
+ }
130
+ window.getUserInfoCallBack = function(account = "", pwd = "") {
131
+ console.log("getUser-sdk", account, pwd);
132
+ resolve({
133
+ account,
134
+ pwd,
135
+ });
136
+ };
137
+ });
138
+ },
139
+ // 爱建统一登录
140
+ callOtherLogin() {
141
+ return new Promise((resolve) => {
142
+ if (ios) {
143
+ window.location.href = "objc://callOtherLogin/?callOtherLoginCallBack";
144
+ } else if (checkIsHarmonyOS()) {
145
+ harmonyCallJsHandler("callOtherLogin", {
146
+ callback: "callOtherLoginCallBack",
147
+ });
148
+ } else if (window.jtoJHandle) {
149
+ window.jtoJHandle.callOtherLogin("callOtherLoginCallBack");
150
+ }
151
+ window.callOtherLoginCallBack = function(loginInfo: object) {
152
+ console.log("callOtherLogin-sdk", loginInfo);
153
+ resolve({
154
+ loginInfo
155
+ });
156
+ };
157
+ });
158
+ },
70
159
  };
@@ -1,27 +1,72 @@
1
1
  /**
2
2
  * @desc 商城sdk
3
- * 1 光大app sdk;2:财人汇app sdk
3
+ * 1 财人汇app sdk
4
4
  */
5
5
  import { common, empty } from "../common/utils.js";
6
- import CrhAppSdk from "./crh-app-sdk.js"; //财人汇app sdk
7
-
8
- const getDeviceInfo: any = {
9
- //获取设备信息
10
- 2: (...params: any[]) => common(CrhAppSdk.getDeviceInfo, "getDeviceInfo")(...params),
11
- };
12
6
 
13
7
  export default class MALL {
14
- public sdkType: number; // 初始化确定是哪种sdk 财人汇 光大 同花顺
8
+ public sdkType: number; // 初始化确定是哪种sdk 财人汇
9
+ public sdkObj: any; //具体的sdk对象
15
10
 
16
11
  constructor(sdkType: number) {
17
- this.sdkType = sdkType; // 1 财人汇 2 光大 3 同花顺 4 大智慧
12
+ this.sdkType = sdkType; // 1 财人汇
13
+ }
14
+
15
+ public async initSdk() {
16
+ console.log("start initSdk");
17
+ if (+this.sdkType === 1) {
18
+ this.sdkObj = (await import("./crh-app-sdk")).default;
19
+ } else if (+this.sdkType === 2) {
20
+ this.sdkObj = (await import("./crh-app-sdk-cxzq")).default;
21
+ }
22
+ console.log("sdk初始化了", this.sdkType);
18
23
  }
19
24
 
20
25
  //获取设备信息
21
26
  public getDeviceInfo(fn: <T>(v: T) => {}) {
22
- if (!getDeviceInfo[this.sdkType]) {
27
+ if (!this.sdkObj.getDeviceInfo) {
23
28
  return empty("getDeviceInfo");
24
29
  }
25
- return getDeviceInfo[this.sdkType](fn);
30
+ return this.sdkObj.getDeviceInfo(fn);
31
+ }
32
+
33
+ //拦截Android物理返回键事件,并回调给前端 --- 仅安卓 鸿蒙
34
+ public interceptBack(fn: <T>(v: T) => {}) {
35
+ if (!this.sdkObj.interceptBack) {
36
+ return empty("interceptBack");
37
+ }
38
+ return this.sdkObj.interceptBack(fn);
39
+ }
40
+
41
+ //关闭页面
42
+ public closeSJKH(fn: <T>(v: T) => {}) {
43
+ if (!this.sdkObj.closeSJKH) {
44
+ return empty("closeSJKH");
45
+ }
46
+ return this.sdkObj.closeSJKH(fn);
47
+ }
48
+
49
+ //打开新页面
50
+ public openOwnPage(fn: <T>(v: T) => {}) {
51
+ if (!this.sdkObj.openOwnPage) {
52
+ return empty("openOwnPage");
53
+ }
54
+ return this.sdkObj.openOwnPage(fn);
55
+ }
56
+
57
+ //获取用户信息
58
+ public getUserInfo(fn: <T>(v: T) => {}) {
59
+ if (!this.sdkObj.getUserInfo) {
60
+ return empty("getUserInfo");
61
+ }
62
+ return this.sdkObj.getUserInfo(fn);
63
+ }
64
+
65
+ //调起客户端登录
66
+ public callOtherLogin(fn: <T>(v: T) => {}) {
67
+ if (!this.sdkObj.callOtherLogin) {
68
+ return empty("callOtherLogin");
69
+ }
70
+ return this.sdkObj.callOtherLogin(fn);
26
71
  }
27
72
  }
package/declare.d.ts CHANGED
@@ -4,6 +4,8 @@
4
4
  declare interface Window {
5
5
  browser: any;
6
6
  getDeviceInfoCallBack: any;
7
+ getUserInfoCallBack: any;
8
+ callOtherLoginCallBack: any;
7
9
  svideoCheckCallback: any;
8
10
  faceVertifyCallBack: any;
9
11
  sensorsTrack: any;
@@ -15,6 +17,7 @@ declare interface Window {
15
17
  cbas3: any;
16
18
  meteor: any;
17
19
  jtoJHandle: any;
20
+ HarmonyBridge: any;
18
21
  hasDialogDownloadFlag: any;
19
22
  hasStartAISvideoFlag: any;
20
23
  vuelog: (...args: any[]) => void;
@@ -22,4 +25,21 @@ declare interface Window {
22
25
  MobileDetect: any;
23
26
  execNew: any;
24
27
  initJsBridge: any;
28
+ interceptBackCallBack:any;
29
+ closeSJKH:any;
30
+ jumpNewPage:any;
31
+ jumpNewPageCallBack:any;
32
+ openOwnPage:any;
33
+ openOwnPageCallBack:any;
34
+ WebViewJavascriptBridge:any;
35
+ WVJBCallbacks:any;
36
+ webkit:any;
37
+ MyWebView:any;
38
+ getUserInfoCB:any;
39
+ getDeviceInfoCB:any;
40
+ oldJuCaiLoginCB:any;
41
+ mobile:any;
42
+ getTradeLoginTokenCB: any;
43
+ communityLoginCB: any;
44
+ callAfterFavor: any;
25
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crh-jssdk",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "crh-jssdk",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tsconfig.json CHANGED
@@ -6,6 +6,7 @@
6
6
  // "incremental": true, /* Enable incremental compilation */
7
7
  "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8
8
  "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9
+ "lib": ["es2015", "dom"],
9
10
  // "lib": [], /* Specify library files to be included in the compilation. */
10
11
  // "allowJs": true, /* Allow javascript files to be compiled. */
11
12
  // "checkJs": true, /* Report errors in .js files. */
@@ -1,70 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.ios = exports.empty = exports.common = void 0;
40
- //调用sdk通用方法
41
- var common = function (promise, name) {
42
- if (!promise) {
43
- return function () { return Promise.resolve([{ code: '-1', data: null, msg: "jssdk\u6682\u4E0D\u652F\u6301".concat(name, "\u65B9\u6CD5, \u8BF7\u4E0E\u7BA1\u7406\u5458\u8054\u7CFB") }]); };
44
- }
45
- return function () {
46
- var params = [];
47
- for (var _i = 0; _i < arguments.length; _i++) {
48
- params[_i] = arguments[_i];
49
- }
50
- return __awaiter(void 0, void 0, void 0, function () {
51
- var res;
52
- return __generator(this, function (_a) {
53
- switch (_a.label) {
54
- case 0:
55
- console.log("\u65B9\u6CD5:".concat(name, ";\u8BF7\u6C42\u53C2\u6570\u5982\u4E0B:").concat(JSON.stringify(params)));
56
- return [4 /*yield*/, promise.apply(void 0, params)];
57
- case 1:
58
- res = _a.sent();
59
- return [2 /*return*/, res];
60
- }
61
- });
62
- });
63
- };
64
- };
65
- exports.common = common;
66
- var empty = function (name) { return Promise.resolve([{ code: '-1', data: null, msg: "jssdk\u6682\u4E0D\u652F\u6301".concat(name, "\u65B9\u6CD5, \u8BF7\u4E0E\u7BA1\u7406\u5458\u8054\u7CFB") }]); };
67
- exports.empty = empty;
68
- var u = navigator.userAgent;
69
- var ios = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
70
- exports.ios = ios;
package/business/index.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MALL = void 0;
7
- var mall_1 = require("./mall");
8
- Object.defineProperty(exports, "MALL", { enumerable: true, get: function () { return __importDefault(mall_1).default; } });
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var utils_1 = require("../common/utils");
4
- //解析opStation
5
- var parsOpStation = function (json) {
6
- // 匹配任何键名为字符串并且对应值为字符串的情况
7
- var regex = /"([^"]+)":"({[^}]+})"/g;
8
- var result = json;
9
- // 循环匹配所有键值对
10
- var match;
11
- while ((match = regex.exec(json)) !== null) {
12
- var key = match[1];
13
- var valueStr = match[2];
14
- try {
15
- var valueObj = JSON.parse(valueStr);
16
- // 将解析后的对象替换原始字符串中的对应键值对
17
- result = result.replace("\"".concat(key, "\":\"").concat(valueStr, "\""), "\"".concat(key, "\":").concat(JSON.stringify(valueObj)));
18
- }
19
- catch (e) {
20
- console.error("\u8F6C\u4E3Ajson\u683C\u5F0F\u6709\u8BEF\uFF0Ckey\u4E3A=> \"".concat(key, "\":"), e);
21
- }
22
- }
23
- return result;
24
- };
25
- exports.default = {
26
- // 获取设备信息
27
- getDeviceInfo: function (fn) {
28
- if (utils_1.ios) {
29
- window.location.href = "objc://getDeviceInfo/?getDeviceInfoCallBack";
30
- }
31
- else {
32
- window.jtoJHandle.getDeviceInfo("getDeviceInfoCallBack");
33
- }
34
- window.getDeviceInfoCallBack = function (res) {
35
- console.log("getDeviceInfo-sdk", res);
36
- var data = {};
37
- try {
38
- data = JSON.parse(res);
39
- }
40
- catch (error) {
41
- res = parsOpStation(res);
42
- data = JSON.parse(res);
43
- }
44
- var real_res = {
45
- device_id: data.deviceId || "",
46
- app_name: data.appName || "",
47
- net_type: data.appnettype || "",
48
- mac: data.mac || "",
49
- brand: data.brand || "",
50
- mobile_tel: data.mobileNo || "",
51
- os_version: data.osVersion || "",
52
- imsi: data.imsi || "",
53
- lanip: data.lanIP || "",
54
- app_version: data.appVersion || "",
55
- sdk_version: data.sdkVersion || "",
56
- opStation: data.opStation || "",
57
- };
58
- // if (data.appVersion && navigator.userAgent.indexOf("crhapp") > -1) {
59
- // this.the_login_register_req.device_info.app_ver = data.appVersion;
60
- // } else {
61
- // this.the_login_register_req.device_info.app_ver = data.sdkVersion;
62
- // }
63
- console.log(real_res, "real_res");
64
- fn && fn(real_res);
65
- };
66
- },
67
- };
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- /**
7
- * @desc 商城sdk
8
- * 1 光大app sdk;2:财人汇app sdk
9
- */
10
- var utils_js_1 = require("../common/utils.js");
11
- var crh_app_sdk_js_1 = __importDefault(require("./crh-app-sdk.js")); //财人汇app sdk
12
- var getDeviceInfo = {
13
- //获取设备信息
14
- 2: function () {
15
- var params = [];
16
- for (var _i = 0; _i < arguments.length; _i++) {
17
- params[_i] = arguments[_i];
18
- }
19
- return (0, utils_js_1.common)(crh_app_sdk_js_1.default.getDeviceInfo, "getDeviceInfo").apply(void 0, params);
20
- },
21
- };
22
- var MALL = /** @class */ (function () {
23
- function MALL(sdkType) {
24
- this.sdkType = sdkType; // 1 财人汇 2 光大 3 同花顺 4 大智慧
25
- }
26
- //获取设备信息
27
- MALL.prototype.getDeviceInfo = function (fn) {
28
- if (!getDeviceInfo[this.sdkType]) {
29
- return (0, utils_js_1.empty)("getDeviceInfo");
30
- }
31
- return getDeviceInfo[this.sdkType](fn);
32
- };
33
- return MALL;
34
- }());
35
- exports.default = MALL;
package/index.js DELETED
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- var index_1 = require("./business/index");
19
- function JSSDK(system, sdkType) {
20
- var System = null;
21
- if (system === 'mall') {
22
- System = index_1.MALL;
23
- }
24
- return /** @class */ (function (_super) {
25
- __extends(class_1, _super);
26
- function class_1(option) {
27
- var _this = _super.call(this, option) || this;
28
- _this.sdkType = sdkType;
29
- return _this;
30
- }
31
- return class_1;
32
- }(System));
33
- }
34
- exports.default = JSSDK;