@conecli/cone-render 0.10.1-beta.5 → 0.10.1-beta.6

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 (57) hide show
  1. package/dist/api/index.ts +1 -1
  2. package/dist/common/const.ts +1 -1
  3. package/dist/common/environmentType.ts +1 -1
  4. package/dist/common/index.h5.ts +1 -1
  5. package/dist/common/index.jd.ts +1 -1
  6. package/dist/common/index.ts +1 -1
  7. package/dist/common/index.weapp.ts +1 -1
  8. package/dist/common/pageType.ts +1 -1
  9. package/dist/common/sgmCustomCode.ts +1 -1
  10. package/dist/components/base/CountDown/index.module.scss +49 -44
  11. package/dist/components/base/CountDown/index.tsx +1 -1
  12. package/dist/components/base/CustomVideo/common.ts +1 -0
  13. package/dist/components/base/CustomVideo/index.tsx +1 -1
  14. package/dist/components/base/LazyLoadImage/index.h5.module.scss +11 -6
  15. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  16. package/dist/components/base/Price/Base/index.tsx +1 -1
  17. package/dist/components/base/Price/Double/index.module.scss +8 -0
  18. package/dist/components/base/Price/Double/index.tsx +1 -1
  19. package/dist/components/floorItem.tsx +1 -1
  20. package/dist/components/isv/Floor/index.tsx +1 -1
  21. package/dist/interface/component.ts +1 -1
  22. package/dist/interface/jumpEventReport.ts +1 -1
  23. package/dist/interface/service.ts +1 -1
  24. package/dist/jumpEventReport/base.ts +1 -1
  25. package/dist/jumpEventReport/index.jd.ts +1 -1
  26. package/dist/jumpEventReport/index.weapp.ts +1 -1
  27. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  28. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  29. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  30. package/dist/jumpEventReport/web.base.ts +1 -1
  31. package/dist/jumpEventReport/web.jd.ts +1 -1
  32. package/dist/jumpEventReport/web.jdb.ts +1 -1
  33. package/dist/jumpEventReport/web.jdjch.ts +1 -1
  34. package/dist/jumpEventReport/web.jxwxapp.ts +1 -1
  35. package/dist/jumpEventReport/web.pc.ts +1 -1
  36. package/dist/jumpEventReport/web.tjapp.ts +1 -1
  37. package/dist/jumpEventReport/web.tjm.ts +1 -1
  38. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  39. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  40. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  41. package/dist/open/api/util.ts +1 -1
  42. package/dist/sass/base.scss +142 -141
  43. package/dist/service/fetchGateway.ts +1 -1
  44. package/dist/service/http/colorSign.ts +1 -1
  45. package/dist/service/http/h5Http.ts +1 -0
  46. package/dist/service/http/index.h5.ts +1 -0
  47. package/dist/service/requestServer.h5.ts +1 -0
  48. package/dist/service/requestServer.ts +1 -1
  49. package/dist/utils/connectNativeJsBridge.ts +1 -1
  50. package/dist/utils/connectNativeJsBridge.weapp.ts +1 -1
  51. package/dist/utils/h5Utils.ts +1 -1
  52. package/dist/utils/index.h5.ts +1 -1
  53. package/dist/utils/index.ts +1 -1
  54. package/dist/utils/index.weapp.ts +1 -1
  55. package/dist/utils/utils.ts +1 -1
  56. package/package.json +35 -29
  57. package/dist/utils/memberFormatUtils.js +0 -1
@@ -1 +1 @@
1
- import { ServiceInterFace } from '../../interface'
2
1
  AppVerifyColorList,
3
2
  SHOP_VERIFY_CODE,
4
3
  PAGES_VERIFY_CODE,
5
4
  B2B_VERITY_CODE,
6
5
  PAGES_DOMAIN,
7
6
  B2BColorFunctionIdList,
8
7
  public fmInfo: {
9
8
  eid?: string
10
9
  fp?: string
11
10
  jsToken?: string
12
11
  sdkToken?: string
13
12
  }
14
13
  public api: ServiceInterFace.HttpApi
15
14
  public paramsSignInstance: any
16
15
  public paramsSignPagesInstance: any
17
16
  public paramsSignBmallInstance: any
18
17
  public isPageDomain: boolean
19
18
  constructor() {
20
19
  this.api = api
21
20
  this.isPageDomain = location?.hostname === PAGES_DOMAIN
22
21
  this.paramsSignInstance = undefined
23
22
  this.paramsSignPagesInstance = undefined
24
23
  this.paramsSignBmallInstance = undefined
25
24
  this.fmInfo = {}
26
25
  this._initSign()
27
26
  }
28
27
 
29
28
  _getMobileJsToken(): Promise<{
30
29
  ok: boolean
31
30
  data?: any
32
31
  error?: any
33
32
  }> {
34
33
  return new Promise((resolve, reject) => {
35
34
  try {
36
35
  if (window?.getJsToken) {
37
36
  window.getJsToken(function (res) {
38
37
  console.log('JS token 获取结果:', res)
39
38
  resolve({
40
39
  ok: true,
41
40
  data: res,
42
41
  })
43
42
  }, 600)
44
43
  } else {
45
44
  reject({
46
45
  ok: false,
47
46
  error: '没有识别到getJsToken全局方法',
48
47
  })
49
48
  }
50
49
  } catch (e) {
51
50
  console.log('获取指纹JS token 异常', e)
52
51
  reject({
53
52
  ok: false,
54
53
  error: e,
55
54
  })
56
55
  }
57
56
  })
58
57
  }
59
58
 
60
59
  async getFmInfo() {
61
60
  try {
62
61
  const { ok, data } = await this._getMobileJsToken()
63
62
  this.fmInfo = ok && data ? data : this.fmInfo
64
63
  return this.fmInfo
65
64
  } catch (e) {
66
65
  console.log('获取指纹信息异常', e)
67
66
  return this.fmInfo
68
67
  }
69
68
  }
70
69
 
71
70
  _initSign() {
72
71
  this.paramsSignInstance = window.PSign
73
72
  ? window.PSign
74
73
  : window.ParamsSign
75
74
  ? this._initParamsSignInstance(SHOP_VERIFY_CODE)
76
75
  : null
77
76
  this.paramsSignPagesInstance = window.ParamsSign
78
77
  ? this._initParamsSignInstance(PAGES_VERIFY_CODE)
79
78
  : null
80
79
  this.paramsSignBmallInstance = window.ParamsSign
81
80
  ? this._initParamsSignInstance(B2B_VERITY_CODE)
82
81
  : null
83
82
  }
84
83
 
85
84
  _initParamsSignInstance(appId) {
86
85
  return new window.ParamsSign({
87
86
  appId: appId,
88
87
  debug: false,
89
88
  preRequest: false,
90
89
  onSign: ({ code }) => {
91
90
  console.log('签名可用率监控', code)
92
91
  },
93
92
  onRequestTokenRemotely: ({ code, message }) => {
94
93
  console.log('算法接口可用率监控', code, message)
95
94
  },
96
95
  onRequestToken: ({ code, message }) => {
97
96
  console.log('token的可用率监控', code, message)
98
97
  },
99
98
  })
100
99
  }
101
100
 
102
101
  paramsSign(data) {
103
102
  try {
104
103
  console.log('获取加签参数', data, this.paramsSignInstance)
105
104
  if (!data || typeof data !== 'object' || !this.paramsSignInstance) {
106
105
  return Promise.resolve(data)
107
106
  } else {
108
107
  const param: any = {
109
108
  appid: data.appid,
110
109
  client: data.client,
111
110
  clientVersion: data.clientVersion,
112
111
  functionId: data.functionId,
113
112
  t: data.t,
114
113
  sign: data?.sign,
115
114
  jsonp: data?.jsonp,
116
115
  }
117
116
  data && data.body && (param.body = sha256(data.body).toString())
118
117
  console.log(
119
118
  '获取加签前的参数处理',
120
119
  param,
121
120
  '获取下发data',
122
121
  data,
123
122
  '获取加签实例',
124
123
  this.paramsSignInstance,
125
124
  this.paramsSignPagesInstance,
126
125
  )
127
126
  return this.isPageDomain &&
128
127
  this.paramsSignPagesInstance &&
129
128
  AppVerifyColorList.includes(param.functionId)
130
129
  ? this.paramsSignPagesInstance.sign(param)
131
130
  : this.paramsSignBmallInstance &&
132
131
  B2BColorFunctionIdList.includes(param.functionId)
133
132
  ? this.paramsSignBmallInstance.sign(param)
134
133
  : this.paramsSignInstance.sign(param)
135
134
  }
136
135
  } catch (e) {
137
136
  console.log('获取加签参数结果异常', e)
138
137
  return Promise.resolve(data)
139
138
  }
140
139
  }
140
+ import { ServiceInterFace } from '../../interface'
141
141
  AppVerifyColorList,
142
142
  SHOP_VERIFY_CODE,
143
143
  PAGES_VERIFY_CODE,
144
144
  B2B_VERITY_CODE,
145
145
  PAGES_DOMAIN,
146
146
  B2BColorFunctionIdList,
147
147
  public fmInfo: {
148
148
  eid?: string
149
149
  fp?: string
150
150
  jsToken?: string
151
151
  sdkToken?: string
152
152
  }
153
153
  public api: ServiceInterFace.HttpApi
154
154
  public paramsSignInstance: any
155
155
  public paramsSignPagesInstance: any
156
156
  public paramsSignBmallInstance: any
157
157
  public isPageDomain: boolean
158
158
  public initParamsSignInstance: any
159
159
  public initJsTokenInstance: any
160
160
  constructor() {
161
161
  this.api = api
162
162
  this.isPageDomain = location?.hostname === PAGES_DOMAIN
163
163
  this.paramsSignInstance = undefined
164
164
  this.paramsSignPagesInstance = undefined
165
165
  this.paramsSignBmallInstance = undefined
166
166
  this.initParamsSignInstance = undefined
167
167
  this.initJsTokenInstance = undefined
168
168
  this.fmInfo = {}
169
169
  }
170
170
 
171
171
  _loadSingleJs(jsFileName, successCallback?, failCallback?) {
172
172
  const jsInfo = global.loadJsSdkList.find(
173
173
  (item) => item?.fileName === jsFileName,
174
174
  )
175
175
  if (jsInfo) {
176
176
  global
177
177
  .loadItemSdkPromise(jsInfo)
178
178
  .then(() => {
179
179
  typeof successCallback === 'function' && successCallback()
180
180
  })
181
181
  .catch(() => {
182
182
  console.info('业务发起接口请求前置加载js异常' + jsInfo?.src)
183
183
  typeof failCallback === 'function' && failCallback()
184
184
  })
185
185
  } else {
186
186
  typeof failCallback === 'function' && failCallback()
187
187
  }
188
188
  }
189
189
 
190
190
  _getMobileJsToken(): Promise<{
191
191
  ok: boolean
192
192
  data?: any
193
193
  error?: any
194
194
  }> {
195
195
  return this._handleInitJsToken().then(() => {
196
196
  try {
197
197
  if (window?.getJsToken) {
198
198
  return new Promise((resolve) => {
199
199
  window.getJsToken(function (res) {
200
200
  console.log('JS token 获取结果', res)
201
201
  resolve({
202
202
  ok: true,
203
203
  data: res,
204
204
  })
205
205
  }, 600)
206
206
  })
207
207
  } else {
208
208
  console.log('没有识别到getJsToken全局方法')
209
209
  return Promise.resolve({
210
210
  ok: false,
211
211
  error: '没有识别到getJsToken全局方法',
212
212
  })
213
213
  }
214
214
  } catch (e) {
215
215
  console.log('获取指纹JS token 异常', e)
216
216
  return Promise.resolve({
217
217
  ok: false,
218
218
  error: e,
219
219
  })
220
220
  }
221
221
  })
222
222
  }
223
223
 
224
224
  async getFmInfo() {
225
225
  try {
226
226
  const { ok, data } = await this._getMobileJsToken()
227
227
  this.fmInfo = ok && data ? data : this.fmInfo
228
228
  return this.fmInfo
229
229
  } catch (e) {
230
230
  console.log('获取指纹信息异常', e)
231
231
  return this.fmInfo
232
232
  }
233
233
  }
234
234
 
235
235
  _initSign() {
236
236
  this.paramsSignInstance = window.PSign
237
237
  ? window.PSign
238
238
  : window.ParamsSign
239
239
  ? this._initParamsSignInstance(SHOP_VERIFY_CODE)
240
240
  : null
241
241
  this.paramsSignPagesInstance = window.ParamsSign
242
242
  ? this._initParamsSignInstance(PAGES_VERIFY_CODE)
243
243
  : null
244
244
  this.paramsSignBmallInstance = window.ParamsSign
245
245
  ? this._initParamsSignInstance(B2B_VERITY_CODE)
246
246
  : null
247
247
  }
248
248
 
249
249
  _initParamsSignInstance(appId) {
250
250
  return new window.ParamsSign({
251
251
  appId: appId,
252
252
  debug: false,
253
253
  preRequest: false,
254
254
  onSign: ({ code }) => {
255
255
  console.log('签名可用率监控', code)
256
256
  },
257
257
  onRequestTokenRemotely: ({ code, message }) => {
258
258
  console.log('算法接口可用率监控', code, message)
259
259
  },
260
260
  onRequestToken: ({ code, message }) => {
261
261
  console.log('token的可用率监控', code, message)
262
262
  },
263
263
  })
264
264
  }
265
265
 
266
266
  paramsSign(data) {
267
267
  try {
268
268
  return this._handleInitSign().then(() => {
269
269
  console.log('获取加签参数', data, this.paramsSignInstance)
270
270
  if (!data || typeof data !== 'object' || !this.paramsSignInstance) {
271
271
  return Promise.resolve(data)
272
272
  } else {
273
273
  const param: any = {
274
274
  appid: data.appid,
275
275
  client: data.client,
276
276
  clientVersion: data.clientVersion,
277
277
  functionId: data.functionId,
278
278
  t: data.t,
279
279
  sign: data?.sign,
280
280
  jsonp: data?.jsonp,
281
281
  }
282
282
  data && data.body && (param.body = sha256(data.body).toString())
283
283
  console.log(
284
284
  '获取加签前的参数处理',
285
285
  param,
286
286
  '获取下发data',
287
287
  data,
288
288
  '获取加签实例',
289
289
  this.paramsSignInstance,
290
290
  this.paramsSignPagesInstance,
291
291
  )
292
292
  return this.isPageDomain &&
293
293
  this.paramsSignPagesInstance &&
294
294
  AppVerifyColorList.includes(param.functionId)
295
295
  ? this.paramsSignPagesInstance.sign(param)
296
296
  : this.paramsSignBmallInstance &&
297
297
  B2BColorFunctionIdList.includes(param.functionId)
298
298
  ? this.paramsSignBmallInstance.sign(param)
299
299
  : this.paramsSignInstance.sign(param)
300
300
  }
301
301
  })
302
302
  } catch (e) {
303
303
  console.log('获取加签参数结果异常', e)
304
304
  return Promise.resolve(data)
305
305
  }
306
306
  }
307
307
 
308
308
  _handleInitSign() {
309
309
  if (!this.initParamsSignInstance) {
310
310
  this.initParamsSignInstance = new Promise((resolve) => {
311
311
  if (window?.ParamsSign) {
312
312
  this._initSign()
313
313
  resolve({
314
314
  ok: true,
315
315
  msg: '加固js已加载',
316
316
  })
317
317
  } else if (window?.PAGE_DATA?.asyncLoadSecurityJs) {
318
318
  this._loadSingleJs(
319
319
  'securityJs',
320
320
  () => {
321
321
  this._initSign()
322
322
  resolve({
323
323
  ok: true,
324
324
  msg: '异步请求加固js成功加载',
325
325
  })
326
326
  },
327
327
  () => {
328
328
  resolve({
329
329
  ok: true,
330
330
  msg: '加固js加载异常',
331
331
  })
332
332
  },
333
333
  )
334
334
  } else {
335
335
  resolve({
336
336
  ok: true,
337
337
  msg: '加固js开关配置为false不加载',
338
338
  })
339
339
  }
340
340
  })
341
341
  }
342
342
  return this.initParamsSignInstance
343
343
  }
344
344
 
345
345
  _handleInitJsToken() {
346
346
  if (!this.initJsTokenInstance) {
347
347
  this.initJsTokenInstance = new Promise((resolve) => {
348
348
  if (window?.getJsToken) {
349
349
  resolve({
350
350
  ok: true,
351
351
  msg: '指纹js已加载',
352
352
  })
353
353
  } else if (window?.PAGE_DATA?.asyncLoadMtkJs) {
354
354
  this._loadSingleJs(
355
355
  'mtkJs',
356
356
  () => {
357
357
  resolve({
358
358
  ok: true,
359
359
  msg: '异步请求指纹js成功加载',
360
360
  })
361
361
  },
362
362
  () => {
363
363
  resolve({
364
364
  ok: true,
365
365
  msg: '指纹js加载异常',
366
366
  })
367
367
  },
368
368
  )
369
369
  } else {
370
370
  resolve({
371
371
  ok: true,
372
372
  msg: '指纹js开关配置为false不加载',
373
373
  })
374
374
  }
375
375
  })
376
376
  }
377
377
  return this.initJsTokenInstance
378
378
  }
@@ -0,0 +1 @@
1
+ import Taro from '@tarojs/taro'
2
  isSupportHybridHttpRequest,
1
3
  draInterfaceCustomReport,
2
4
  draBusinessCustomReport,
3
5
  jsonHeader = 'application/json;charset=utf-8',
4
6
  formDataHeader = 'application/x-www-form-urlencoded',
5
7
  HYBRID: 'httpRequest_hybrid',
6
8
  TARO: 'httpRequest_taro',
7
9
  #requestTimeStamp: number
8
10
  #responseTimeStamp: number
9
11
  #getResTimeStamp: number
10
12
  #reportType: string
11
13
  #callbackFunction: string
12
14
 
13
15
  async request({
14
16
  url,
15
17
  method = 'POST',
16
18
  timeout = 7000,
17
19
  isColorVerify = false,
18
20
  ...otherOptions
19
21
  }): Promise<Taro.request.SuccessCallbackResult<any>> {
20
22
  const { header: otherHeader, ...otherOpts } = otherOptions
21
23
  const header = {
22
24
  'content-type':
23
25
  method === 'POST'
24
26
  ? RequestHeaderContentType.formDataHeader
25
27
  : RequestHeaderContentType.jsonHeader,
26
28
  ...otherHeader,
27
29
  }
28
30
  let getRequestUrl = url
29
31
  let requestTask
30
32
  const data = otherOpts?.data
31
33
  const isGatewayRequest =
32
34
  url === this.api.apiFunc && typeof data === 'object'
33
35
  if (isGatewayRequest) {
34
36
  getRequestUrl = this._handleSpecialGatewayUrl(url)
35
37
  const shouldUseHybridRequest = this._shouldUseHybridRequest(data)
36
38
  if (shouldUseHybridRequest) {
37
39
  requestTask = this._hybridRequest(getRequestUrl, data)
38
40
  } else {
39
41
  otherOpts.data = await this._prepareGatewayReqData(data, isColorVerify)
40
42
  requestTask = this._taroRequest(
41
43
  getRequestUrl,
42
44
  otherOpts,
43
45
  method,
44
46
  timeout,
45
47
  header,
46
48
  )
47
49
  }
48
50
  } else {
49
51
  requestTask = this._taroRequest(
50
52
  getRequestUrl,
51
53
  otherOpts,
52
54
  method,
53
55
  timeout,
54
56
  header,
55
57
  )
56
58
  }
57
59
  const requestTimeoutPromise =
58
60
  new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
59
61
  setTimeout(() => {
60
62
  resolve({
61
63
  statusCode: 500,
62
64
  resTimeoutState: true,
63
65
  errMsg: 'request timeout',
64
66
  })
65
67
  }, timeout)
66
68
  })
67
69
  return Promise.race([requestTask, requestTimeoutPromise]).then(
68
70
  (res: any) => {
69
71
  if (res && res.statusCode === 500 && res.resTimeoutState) {
70
72
  if (this.#reportType === HTTP_REQUEST_TYPE.HYBRID) {
71
73
  this._clearFunction(this.#callbackFunction)
72
74
  } else {
73
75
  requestTask.abort && requestTask.abort()
74
76
  }
75
77
  }
76
78
  this._handleReportInterfaceError(url, data, timeout, res)
77
79
  return res
78
80
  },
79
81
  )
80
82
  }
81
83
 
82
84
  _handleSpecialGatewayUrl(url: string): string {
83
85
  if (isPc && window.location.hostname.includes('.jd.hk')) {
84
86
  return this.api.hkApiFunc
85
87
  }
86
88
  if (
87
89
  isJdApp &&
88
90
  window?.shopGlobalSwitch?.dualProtocol &&
89
91
  !window.location.href.includes('jshopx_vconsole')
90
92
  ) {
91
93
  return window?.shopGlobalSwitch?.dualProtocol?.apiTestApp || url
92
94
  }
93
95
  return url
94
96
  }
95
97
 
96
98
  _shouldUseHybridRequest(data: any): boolean {
97
99
  try {
98
100
  const isWhxFunctionId = /^whx\_/.test(data?.functionId)
99
101
  const isGlobalOpenHybirdHttpRequest =
100
102
  window?.shopGlobalSwitch?.openHybirdHttpRequest === 'true'
101
103
  if (
102
104
  !isJdApp ||
103
105
  !isSupportHybridHttpRequest ||
104
106
  !isGlobalOpenHybirdHttpRequest ||
105
107
  isWhxFunctionId ||
106
108
  isJdAndHarmonyDevice
107
109
  ) {
108
110
  return false
109
111
  }
110
112
  const configData = global.getDynamicConfig('hybridHttpSwitch')
111
113
  const { globalOn = false, grayscale = {} } = configData || {}
112
114
  const buildType = process.env.BUILD_TYPE || ''
113
115
  const isInvokeGray = globalOn || grayscale[buildType]
114
116
  console.log(
115
117
  '使用hybrid请求是否命中灰度,isInvokeGray:',
116
118
  isInvokeGray,
117
119
  '获取mpaas配置hybridHttpSwitch原始数据configData',
118
120
  configData,
119
121
  )
120
122
  const hasWindowXWebView = !!window.XWebView
121
123
  return isInvokeGray && hasWindowXWebView
122
124
  } catch (e) {
123
125
  console.log('获取是否使用Hybrid请求出错,e:', e)
124
126
  return false
125
127
  }
126
128
  }
127
129
 
128
130
  _hybridRequest(url: string, data: any): Promise<any> {
129
131
  return new Promise((resolve, reject) => {
130
132
  try {
131
133
  const changeCurrentUrl = url.startsWith('//') ? `https:${url}` : url
132
134
  const { functionId, body, ...otherH5Param } = data
133
135
  const reqParams = {
134
136
  url: isIosDevice ? `${changeCurrentUrl}/` : changeCurrentUrl,
135
137
  functionId: functionId,
136
138
  body: body,
137
139
  headerType: '0',
138
140
  param: {
139
141
  ...otherH5Param,
140
142
  },
141
143
  header: {
142
144
  Referer: window.location.origin,
143
145
  },
144
146
  }
145
147
  const callbackFunction = this._generateCallbackFunction()
146
148
  this.#callbackFunction = callbackFunction
147
149
  this.#requestTimeStamp = Date.now()
148
150
  this.#reportType = HTTP_REQUEST_TYPE.HYBRID
149
151
  window.XWebView.callNative(
150
152
  'ColorQueryPlugin',
151
153
  'colorRequest',
152
154
  JSON.stringify(reqParams),
153
155
  callbackFunction,
154
156
  '1',
155
157
  )
156
158
  window[callbackFunction] = (result) => {
157
159
  this.#responseTimeStamp = Date.now()
158
160
  try {
159
161
  const resultObj =
160
162
  typeof result === 'string' ? JSON.parse(result) : result
161
163
  resolve(resultObj)
162
164
  } catch (error) {
163
165
  const errMsg = 'hybrid网络请求JSON解析失败, error: ' + error
164
166
  draBusinessCustomReport({
165
167
  type: `${HTTP_REQUEST_TYPE.HYBRID}_jsonParseError`,
166
168
  errMsg,
167
169
  result,
168
170
  })
169
171
  reject({ errMsg })
170
172
  }
171
173
  this._clearFunction(callbackFunction)
172
174
  }
173
175
  } catch (error) {
174
176
  reject({
175
177
  errMsg:
176
178
  'hybrid网络请求,App下调用window.XWebView.callNative出错, error: ' +
177
179
  error,
178
180
  })
179
181
  }
180
182
  })
181
183
  }
182
184
 
183
185
  _generateCallbackFunction() {
184
186
  return `hybridHttpRequestCallback_${Date.now()}_${Math.ceil(
185
187
  Math.random() * 100000,
186
188
  )}`
187
189
  }
188
190
 
189
191
  _clearFunction(functionName: string) {
190
192
  try {
191
193
  delete window[functionName]
192
194
  } catch (e) {
193
195
  window[functionName] = undefined
194
196
  }
195
197
  }
196
198
 
197
199
  async _prepareGatewayReqData(
198
200
  data: any,
199
201
  isColorVerify: boolean,
200
202
  ): Promise<any> {
201
203
  const { functionId } = data
202
204
  console.log('获取当前是否需要color加固', isColorVerify, functionId)
203
205
  if (isColorVerify) {
204
206
  const { h5st } = await colorSign.paramsSign(data)
205
207
  h5st && (data.h5st = encodeURI(h5st))
206
208
  console.log(`${functionId}的apiReq_h5st===>:${h5st}`)
207
209
  }
208
210
  const { jsToken } = await colorSign.getFmInfo()
209
211
  console.log(`${functionId}的api jsToken指纹===>:${jsToken}`)
210
212
  jsToken && (data['x-api-eid-token'] = jsToken)
211
213
  return data
212
214
  }
213
215
 
214
216
  _taroRequest(
215
217
  url: string,
216
218
  otherOpts: any,
217
219
  method: string,
218
220
  timeout: number,
219
221
  header: string,
220
222
  ): Promise<any> {
221
223
  const reqParam = {
222
224
  url,
223
225
  method,
224
226
  timeout,
225
227
  header,
226
228
  credentials: 'include',
227
229
  ...otherOpts,
228
230
  }
229
231
  this.#requestTimeStamp = Date.now()
230
232
  this.#reportType = HTTP_REQUEST_TYPE.TARO
231
233
  return Taro.request(reqParam)
232
234
  }
233
235
 
234
236
  _reportRequestTime(url: string, data: any): void {
235
237
  this.#getResTimeStamp = Date.now()
236
238
  if (this.#reportType === HTTP_REQUEST_TYPE.TARO) {
237
239
  this.#responseTimeStamp = this.#getResTimeStamp
238
240
  }
239
241
  draInterfaceCustomReport(
240
242
  {
241
243
  type: `${this.#reportType}_consumeTime`,
242
244
  url,
243
245
  functionId: data?.functionId,
244
246
  requestTimeStamp: this.#requestTimeStamp,
245
247
  responseTimeStamp: this.#responseTimeStamp,
246
248
  errMsg: `使用${this.#reportType}调用接口请求响应耗时`,
247
249
  source: 'remote',
248
250
  },
249
251
  {
250
252
  consumeTime: `${this.#responseTimeStamp - this.#requestTimeStamp}ms`,
251
253
  getResTime: `${this.#getResTimeStamp - this.#requestTimeStamp}ms`,
252
254
  },
253
255
  )
254
256
  }
255
257
 
256
258
  _handleReportInterfaceError(
257
259
  url: string,
258
260
  reqData: any,
259
261
  timeOut: any,
260
262
  res: any,
261
263
  ): void {
262
264
  const source = 'remote'
263
265
  const requestType = this.#reportType
264
266
  let errorType = ''
265
267
  let subMsg = ''
266
268
  let reportFlag = false
267
269
  if (res) {
268
270
  const { statusCode, data, status, resTimeoutState } = res
269
271
  if (statusCode === 500 && resTimeoutState) {
270
272
  reportFlag = true
271
273
  errorType = 'timeout'
272
274
  subMsg = `接口请求超时${timeOut}ms`
273
275
  } else if ((statusCode === 200 || status === '0') && data) {
274
276
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
275
277
  ? Number(data.code)
276
278
  : -1
277
279
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
278
280
  ? Number(data.subCode)
279
281
  : -1
280
282
  const isSuccess =
281
283
  data.success === true ||
282
284
  data.isSuccess ||
283
285
  resCode === 0 ||
284
286
  resCode === 200 ||
285
287
  subCode === 0
286
288
  if (!isSuccess && resCode !== 3) {
287
289
  reportFlag = true
288
290
  errorType = 'dataError'
289
291
  subMsg = '接口请求返回数据异常'
290
292
  }
291
293
  } else {
292
294
  reportFlag = true
293
295
  errorType = 'statusError'
294
296
  subMsg = '接口请求错误,h5请求statusCode非200,或hybrid请求status非0,或未返回data字段'
295
297
  }
296
298
  }
297
299
  reportFlag &&
298
300
  draInterfaceCustomReport({
299
301
  subMsg,
300
302
  url,
301
303
  source,
302
304
  requestType,
303
305
  errorType,
304
306
  functionId: reqData?.functionId,
305
307
  appid: reqData?.appId,
306
308
  client: reqData?.client,
307
309
  clientVersion: reqData?.clientVersion,
308
310
  statusCode: res?.statusCode,
309
311
  status: res?.status,
310
312
  code: res?.data?.code || res?.data?.subCode,
311
313
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
312
314
  originReqDataStr: JSON.stringify(reqData),
313
315
  originResDataStr: JSON.stringify(res),
314
316
  })
315
317
  }
@@ -0,0 +1 @@
1
+ import H5Http from "./h5Http"