@conecli/cone-render 0.10.1-shop3.8 → 0.10.1-shop3.80

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 (109) hide show
  1. package/README.md +1 -1
  2. package/dist/api/index.ts +1 -1
  3. package/dist/common/accessibility.h5.ts +1 -0
  4. package/dist/common/accessibility.ts +0 -0
  5. package/dist/common/const.ts +1 -1
  6. package/dist/common/index.h5.ts +1 -1
  7. package/dist/common/index.jd.ts +1 -1
  8. package/dist/common/index.ts +1 -1
  9. package/dist/common/index.weapp.ts +1 -1
  10. package/dist/common/jdplayerSdk.weapp.tsx +1 -0
  11. package/dist/common/jssdk.ts +1 -1
  12. package/dist/common/jssdk.weapp.ts +1 -0
  13. package/dist/common/pageType.ts +1 -1
  14. package/dist/common/token/index.h5.ts +1 -1
  15. package/dist/common/token/token.jd.ts +1 -1
  16. package/dist/common/wxappApi.ts +1 -1
  17. package/dist/components/ErrorBoundary.tsx +1 -1
  18. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  19. package/dist/components/base/CountDown/index.tsx +1 -1
  20. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  21. package/dist/components/base/CustomVideo/index.tsx +1 -1
  22. package/dist/components/base/CustomVideo/index.weapp.tsx +1 -0
  23. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  24. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  25. package/dist/components/base/InOrOutViewObserver/index.weapp.tsx +1 -0
  26. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  27. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  28. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  29. package/dist/components/base/MobileCommonHeader/index.weapp.tsx +1 -0
  30. package/dist/components/base/NetworkDataError/const.ts +1 -1
  31. package/dist/components/base/NetworkDataError/index.module.scss +118 -72
  32. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  33. package/dist/components/base/Price/Base/index.module.scss +12 -0
  34. package/dist/components/base/Price/Base/index.tsx +1 -1
  35. package/dist/components/base/Price/Double/index.module.scss +24 -0
  36. package/dist/components/base/Price/Double/index.tsx +1 -1
  37. package/dist/components/base/ShopLeGaoTag/index.h5.module.scss +35 -0
  38. package/dist/components/base/ShopLeGaoTag/index.h5.tsx +1 -0
  39. package/dist/components/base/ShopLeGaoTag/index.module.scss +33 -0
  40. package/dist/components/base/ShopLeGaoTag/index.tsx +1 -0
  41. package/dist/components/debug/DebugLayout/index.module.scss +2 -2
  42. package/dist/components/floorItem.tsx +1 -1
  43. package/dist/components/isv/Floor/index.tsx +1 -1
  44. package/dist/components/remoteFloorItem.tsx +1 -1
  45. package/dist/interface/common.ts +1 -1
  46. package/dist/interface/component.ts +1 -1
  47. package/dist/interface/jumpEventReport.ts +1 -1
  48. package/dist/interface/service.ts +1 -1
  49. package/dist/jumpEventReport/base.ts +1 -1
  50. package/dist/jumpEventReport/const.ts +1 -1
  51. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  52. package/dist/jumpEventReport/index.h5.ts +1 -1
  53. package/dist/jumpEventReport/index.jd.ts +1 -1
  54. package/dist/jumpEventReport/index.weapp.ts +1 -1
  55. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  56. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  57. package/dist/jumpEventReport/logEventConfig.h5.ts +1 -0
  58. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  59. package/dist/jumpEventReport/web/report.ts +1 -1
  60. package/dist/jumpEventReport/web.base.ts +1 -1
  61. package/dist/jumpEventReport/web.jd.ts +1 -1
  62. package/dist/jumpEventReport/web.pc.ts +1 -1
  63. package/dist/jumpEventReport/web.tjm.ts +1 -1
  64. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  65. package/dist/language/en_US.json +274 -0
  66. package/dist/language/zh_CN.json +274 -0
  67. package/dist/language/zh_HK.json +274 -0
  68. package/dist/libs/openShopBridge.js +161 -0
  69. package/dist/libs/openShopBridge.min.js +1 -0
  70. package/dist/libs/taroAppReport.js +2 -2
  71. package/dist/modules/ContainerFloorList/index.h5.module.scss +16 -2
  72. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  73. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  74. package/dist/modules/DecorateContainerFloorList/index.weapp.tsx +1 -0
  75. package/dist/open/api/environment.ts +1 -1
  76. package/dist/open/api/shopMember.ts +1 -1
  77. package/dist/open/api/shopMember.weapp.ts +1 -0
  78. package/dist/open/api/track.ts +1 -1
  79. package/dist/open/api/util.ts +1 -1
  80. package/dist/open/components/index.ts +1 -1
  81. package/dist/open/index.ts +1 -1
  82. package/dist/sass/app.h5.scss +27 -1
  83. package/dist/service/fetchGateway.ts +1 -1
  84. package/dist/service/fetchGateway.weapp.ts +1 -1
  85. package/dist/service/fetchJsonp.weapp.ts +1 -0
  86. package/dist/service/http/const.ts +1 -1
  87. package/dist/service/http/h5Http.ts +1 -1
  88. package/dist/service/http/httpInterceptors.weapp.ts +1 -0
  89. package/dist/service/requestServer.h5.ts +1 -1
  90. package/dist/service/requestServer.ts +1 -1
  91. package/dist/service/requestServer.weapp.ts +1 -1
  92. package/dist/utils/connectNativeJsBridge.ts +1 -1
  93. package/dist/utils/h5Utils.ts +1 -1
  94. package/dist/utils/harmonyCallRouter.h5.ts +1 -0
  95. package/dist/utils/harmonyCallRouter.ts +0 -0
  96. package/dist/utils/index.h5.ts +1 -1
  97. package/dist/utils/index.ts +1 -1
  98. package/dist/utils/index.weapp.ts +1 -1
  99. package/dist/utils/jumpExtMapUtil.ts +1 -0
  100. package/dist/utils/log.ts +1 -0
  101. package/dist/utils/{sColor.js → sColor.ts} +1 -1
  102. package/dist/utils/sColor.weapp.ts +1 -0
  103. package/dist/utils/utils.ts +1 -1
  104. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  105. package/dist/wxapp/common/user_info.js +1 -1
  106. package/package.json +162 -141
  107. package/dist/jumpEventReport/web/wqshop.report.ts +0 -1
  108. package/dist/utils/priceUtils.js +0 -1
  109. /package/dist/utils/{jumpExtMapUtil.js → jumpExtMapUtil.h5.ts} +0 -0
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro';
2
1
  isSupportHybridHttpRequest,
3
2
  draInterfaceCustomReport,
4
3
  draBusinessCustomReport,
5
4
  jsonHeader = 'application/json;charset=utf-8',
6
5
  formDataHeader = 'application/x-www-form-urlencoded',
7
6
  HYBRID: 'httpRequest_hybrid',
8
7
  TARO: 'httpRequest_taro',
9
8
  #requestTimeStamp: number;
10
9
  #responseTimeStamp: number;
11
10
  #getResTimeStamp: number;
12
11
  #reportType: string;
13
12
  #callbackFunction: string;
14
13
 
15
14
  async request({
16
15
  url,
17
16
  method = 'POST',
18
17
  timeout = 7000,
19
18
  isColorVerify = false,
20
19
  ...otherOptions
21
20
  }): Promise<Taro.request.SuccessCallbackResult<any>> {
22
21
  const { header: otherHeader, ...otherOpts } = otherOptions;
23
22
  const header = {
24
23
  'content-type':
25
24
  method === 'POST'
26
25
  ? RequestHeaderContentType.formDataHeader
27
26
  : RequestHeaderContentType.jsonHeader,
28
27
  ...otherHeader,
29
28
  };
30
29
  let getRequestUrl = url;
31
30
  let requestTask;
32
31
  const data = otherOpts?.data;
33
32
  const isGatewayRequest = url === this.api.apiFunc && typeof data === 'object';
34
33
  if (isGatewayRequest) {
35
34
  getRequestUrl = this._handleSpecialGatewayUrl(url);
36
35
  const shouldUseHybridRequest = this._shouldUseHybridRequest(data);
37
36
  if (shouldUseHybridRequest) {
38
37
  requestTask = this._hybridRequest(getRequestUrl, data);
39
38
  } else {
40
39
  otherOpts.data = await this._prepareGatewayReqData(data, isColorVerify);
41
40
  requestTask = this._taroRequest(getRequestUrl, otherOpts, method, timeout, header);
42
41
  }
43
42
  } else {
44
43
  requestTask = this._taroRequest(getRequestUrl, otherOpts, method, timeout, header);
45
44
  }
46
45
  const requestTimeoutPromise = new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
47
46
  setTimeout(() => {
48
47
  resolve({
49
48
  statusCode: 500,
50
49
  resTimeoutState: true,
51
50
  errMsg: 'request timeout',
52
51
  });
53
52
  }, timeout);
54
53
  });
55
54
  return Promise.race([requestTask, requestTimeoutPromise]).then((res: any) => {
56
55
  if (res && res.statusCode === 500 && res.resTimeoutState) {
57
56
  if (this.#reportType === HTTP_REQUEST_TYPE.HYBRID) {
58
57
  this._clearFunction(this.#callbackFunction);
59
58
  } else {
60
59
  requestTask.abort && requestTask.abort();
61
60
  }
62
61
  }
63
62
  this._handleReportInterfaceError(url, data, timeout, res);
64
63
  return res;
65
64
  });
66
65
  }
67
66
 
68
67
  _handleSpecialGatewayUrl(url: string): string {
69
68
  if (isPc && window.location.hostname.includes('.jd.hk')) {
70
69
  return this.api.hkApiFunc;
71
70
  }
72
71
  if (
73
72
  isJdApp &&
74
73
  window?.shopGlobalSwitch?.dualProtocol &&
75
74
  !window.location.href.includes('jshopx_vconsole')
76
75
  ) {
77
76
  return window?.shopGlobalSwitch?.dualProtocol?.apiTestApp || url;
78
77
  }
79
78
  return url;
80
79
  }
81
80
 
82
81
  _shouldUseHybridRequest(data: any): boolean {
83
82
  try {
84
83
  const isWhxFunctionId = /^whx\_/.test(data?.functionId);
85
84
  const isGlobalOpenHybirdHttpRequest =
86
85
  window?.shopGlobalSwitch?.openHybirdHttpRequest === 'true';
87
86
  if (
88
87
  !isJdApp ||
89
88
  !isSupportHybridHttpRequest ||
90
89
  !isGlobalOpenHybirdHttpRequest ||
91
90
  isWhxFunctionId ||
92
91
  isJdAndHarmonyDevice
93
92
  ) {
94
93
  return false;
95
94
  }
96
95
  const configData = global.getDynamicConfig('hybridHttpSwitch');
97
96
  const { globalOn = false, grayscale = {} } = configData || {};
98
97
  const buildType = process.env.BUILD_TYPE || '';
99
98
  const isInvokeGray = globalOn || grayscale[buildType];
100
99
  console.log(
101
100
  '使用hybrid请求是否命中灰度,isInvokeGray:',
102
101
  isInvokeGray,
103
102
  '获取mpaas配置hybridHttpSwitch原始数据configData',
104
103
  configData,
105
104
  );
106
105
  const hasWindowXWebView = !!window.XWebView;
107
106
  return isInvokeGray && hasWindowXWebView;
108
107
  } catch (e) {
109
108
  console.log('获取是否使用Hybrid请求出错,e:', e);
110
109
  return false;
111
110
  }
112
111
  }
113
112
 
114
113
  _hybridRequest(url: string, data: any): Promise<any> {
115
114
  return new Promise((resolve, reject) => {
116
115
  try {
117
116
  const changeCurrentUrl = url.startsWith('//') ? `https:${url}` : url;
118
117
  const { functionId, body, ...otherH5Param } = data;
119
118
  const reqParams = {
120
119
  url: isIosDevice ? `${changeCurrentUrl}/` : changeCurrentUrl,
121
120
  functionId: functionId,
122
121
  body: body,
123
122
  headerType: '0',
124
123
  param: {
125
124
  ...otherH5Param,
126
125
  },
127
126
  header: {
128
127
  Referer: window.location.origin,
129
128
  },
130
129
  };
131
130
  const callbackFunction = this._generateCallbackFunction();
132
131
  this.#callbackFunction = callbackFunction;
133
132
  this.#requestTimeStamp = Date.now();
134
133
  this.#reportType = HTTP_REQUEST_TYPE.HYBRID;
135
134
  window.XWebView.callNative(
136
135
  'ColorQueryPlugin',
137
136
  'colorRequest',
138
137
  JSON.stringify(reqParams),
139
138
  callbackFunction,
140
139
  '1',
141
140
  );
142
141
  window[callbackFunction] = (result) => {
143
142
  this.#responseTimeStamp = Date.now();
144
143
  try {
145
144
  const resultObj = typeof result === 'string' ? JSON.parse(result) : result;
146
145
  resolve(resultObj);
147
146
  } catch (error) {
148
147
  const errMsg = 'hybrid网络请求JSON解析失败, error: ' + error;
149
148
  draBusinessCustomReport({
150
149
  type: `${HTTP_REQUEST_TYPE.HYBRID}_jsonParseError`,
151
150
  errMsg,
152
151
  result,
153
152
  });
154
153
  reject({ errMsg });
155
154
  }
156
155
  this._clearFunction(callbackFunction);
157
156
  };
158
157
  } catch (error) {
159
158
  reject({
160
159
  errMsg: 'hybrid网络请求,App下调用window.XWebView.callNative出错, error: ' + error,
161
160
  });
162
161
  }
163
162
  });
164
163
  }
165
164
 
166
165
  _generateCallbackFunction() {
167
166
  return `hybridHttpRequestCallback_${Date.now()}_${Math.ceil(Math.random() * 100000)}`;
168
167
  }
169
168
 
170
169
  _clearFunction(functionName: string) {
171
170
  try {
172
171
  delete window[functionName];
173
172
  } catch (e) {
174
173
  window[functionName] = undefined;
175
174
  }
176
175
  }
177
176
 
178
177
  async _prepareGatewayReqData(data: any, isColorVerify: boolean): Promise<any> {
179
178
  const { functionId } = data;
180
179
  console.log('获取当前是否需要color加固', isColorVerify, functionId);
181
180
  if (isColorVerify) {
182
181
  const { h5st } = await colorSign.paramsSign(data);
183
182
  h5st && (data.h5st = encodeURI(h5st));
184
183
  console.log(`${functionId}的apiReq_h5st===>:${h5st}`);
185
184
  }
186
185
  const { jsToken } = await colorSign.getFmInfo();
187
186
  console.log(`${functionId}的api jsToken指纹===>:${jsToken}`);
188
187
  jsToken && (data['x-api-eid-token'] = jsToken);
189
188
  return data;
190
189
  }
191
190
 
192
191
  _taroRequest(
193
192
  url: string,
194
193
  otherOpts: any,
195
194
  method: string,
196
195
  timeout: number,
197
196
  header: string,
198
197
  ): Promise<any> {
199
198
  const reqParam = {
200
199
  url,
201
200
  method,
202
201
  timeout,
203
202
  header,
204
203
  credentials: 'include',
205
204
  ...otherOpts,
206
205
  };
207
206
  this.#requestTimeStamp = Date.now();
208
207
  this.#reportType = HTTP_REQUEST_TYPE.TARO;
209
208
  return Taro.request(reqParam);
210
209
  }
211
210
 
212
211
  _reportRequestTime(url: string, data: any): void {
213
212
  this.#getResTimeStamp = Date.now();
214
213
  if (this.#reportType === HTTP_REQUEST_TYPE.TARO) {
215
214
  this.#responseTimeStamp = this.#getResTimeStamp;
216
215
  }
217
216
  draInterfaceCustomReport(
218
217
  {
219
218
  type: `${this.#reportType}_consumeTime`,
220
219
  url,
221
220
  functionId: data?.functionId,
222
221
  requestTimeStamp: this.#requestTimeStamp,
223
222
  responseTimeStamp: this.#responseTimeStamp,
224
223
  errMsg: `使用${this.#reportType}调用接口请求响应耗时`,
225
224
  source: 'remote',
226
225
  },
227
226
  {
228
227
  consumeTime: `${this.#responseTimeStamp - this.#requestTimeStamp}ms`,
229
228
  getResTime: `${this.#getResTimeStamp - this.#requestTimeStamp}ms`,
230
229
  },
231
230
  );
232
231
  }
233
232
 
234
233
  _handleReportInterfaceError(url: string, reqData: any, timeOut: any, res: any): void {
235
234
  const source = 'remote';
236
235
  const requestType = this.#reportType;
237
236
  let errorType = '';
238
237
  let subMsg = '';
239
238
  let reportFlag = false;
240
239
  if (res) {
241
240
  const { statusCode, data, status, resTimeoutState } = res;
242
241
  if (statusCode === 500 && resTimeoutState) {
243
242
  reportFlag = true;
244
243
  errorType = 'timeout';
245
244
  subMsg = `接口请求超时${timeOut}ms`;
246
245
  } else if ((statusCode === 200 || status === '0') && data) {
247
246
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
248
247
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
249
248
  ? Number(data.subCode)
250
249
  : -1;
251
250
  const isSuccess =
252
251
  data.success === true ||
253
252
  data.isSuccess ||
254
253
  resCode === 0 ||
255
254
  resCode === 200 ||
256
255
  subCode === 0;
257
256
  if (!isSuccess && resCode !== 3) {
258
257
  reportFlag = true;
259
258
  errorType = 'dataError';
260
259
  subMsg = '接口请求返回数据异常';
261
260
  }
262
261
  } else {
263
262
  reportFlag = true;
264
263
  errorType = 'statusError';
265
264
  subMsg = '接口请求错误,h5请求statusCode非200,或hybrid请求status非0,或未返回data字段';
266
265
  }
267
266
  }
268
267
  reportFlag &&
269
268
  draInterfaceCustomReport({
270
269
  subMsg,
271
270
  url,
272
271
  source,
273
272
  requestType,
274
273
  errorType,
275
274
  functionId: reqData?.functionId,
276
275
  appid: reqData?.appId,
277
276
  client: reqData?.client,
278
277
  clientVersion: reqData?.clientVersion,
279
278
  statusCode: res?.statusCode,
280
279
  status: res?.status,
281
280
  code: res?.data?.code || res?.data?.subCode,
282
281
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
283
282
  originReqDataStr: JSON.stringify(reqData),
284
283
  originResDataStr: JSON.stringify(res),
285
284
  });
286
285
  }
286
+ import Taro from '@tarojs/taro';
287
287
  isSupportHybridHttpRequest,
288
288
  draInterfaceCustomReport,
289
289
  draBusinessCustomReport,
290
290
  jsonHeader = 'application/json;charset=utf-8',
291
291
  formDataHeader = 'application/x-www-form-urlencoded',
292
292
  HYBRID: 'httpRequest_hybrid',
293
293
  TARO: 'httpRequest_taro',
294
294
  #requestTimeStamp: number;
295
295
  #responseTimeStamp: number;
296
296
  #getResTimeStamp: number;
297
297
  #reportType: string;
298
298
  #callbackFunction: string;
299
299
 
300
300
  async request({
301
301
  url,
302
302
  method = 'POST',
303
303
  timeout = 7000,
304
304
  isColorVerify = false,
305
305
  ...otherOptions
306
306
  }): Promise<Taro.request.SuccessCallbackResult<any>> {
307
307
  const { header: otherHeader, ...otherOpts } = otherOptions;
308
308
  const header = {
309
309
  'content-type':
310
310
  method === 'POST'
311
311
  ? RequestHeaderContentType.formDataHeader
312
312
  : RequestHeaderContentType.jsonHeader,
313
313
  ...otherHeader,
314
314
  };
315
315
  let getRequestUrl = url;
316
316
  let requestTask;
317
317
  const data = otherOpts?.data;
318
318
  const isGatewayRequest = url === this.api.apiFunc && typeof data === 'object';
319
319
  if (isGatewayRequest) {
320
320
  getRequestUrl = this._handleSpecialGatewayUrl(url);
321
321
  const shouldUseHybridRequest = this._shouldUseHybridRequest(data);
322
322
  if (shouldUseHybridRequest && window?.XWebView && window?.XWebView?.callNative) {
323
323
  requestTask = this._hybridRequest(getRequestUrl, data);
324
324
  } else {
325
325
  otherOpts.data = await this._prepareGatewayReqData(data, isColorVerify);
326
326
  requestTask = this._taroRequest(getRequestUrl, otherOpts, method, timeout, header);
327
327
  }
328
328
  } else {
329
329
  requestTask = this._taroRequest(getRequestUrl, otherOpts, method, timeout, header);
330
330
  }
331
331
  const requestTimeoutPromise = new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
332
332
  setTimeout(() => {
333
333
  resolve({
334
334
  statusCode: 500,
335
335
  resTimeoutState: true,
336
336
  errMsg: 'request timeout',
337
337
  });
338
338
  }, timeout);
339
339
  });
340
340
  return Promise.race([requestTask, requestTimeoutPromise]).then((res: any) => {
341
341
  if (res && res.statusCode === 500 && res.resTimeoutState) {
342
342
  if (this.#reportType === HTTP_REQUEST_TYPE.HYBRID) {
343
343
  this._clearFunction(this.#callbackFunction);
344
344
  } else {
345
345
  requestTask.abort && requestTask.abort();
346
346
  }
347
347
  }
348
348
  this._handleReportInterfaceError(url, data, timeout, res);
349
349
  return res;
350
350
  });
351
351
  }
352
352
 
353
353
  _handleSpecialGatewayUrl(url: string): string {
354
354
  if (isPc && window.location.hostname.includes('.jd.hk')) {
355
355
  return this.api.hkApiFunc;
356
356
  }
357
357
  if (
358
358
  isJdApp &&
359
359
  window?.shopGlobalSwitch?.dualProtocol &&
360
360
  !window.location.href.includes('jshopx_vconsole')
361
361
  ) {
362
362
  return window?.shopGlobalSwitch?.dualProtocol?.apiTestApp || url;
363
363
  }
364
364
  return url;
365
365
  }
366
366
 
367
367
  _shouldUseHybridRequest(data: any): boolean {
368
368
  try {
369
369
  const isWhxFunctionId = /^whx\_/.test(data?.functionId);
370
370
  const isGlobalOpenHybirdHttpRequest =
371
371
  window?.shopGlobalSwitch?.openHybirdHttpRequest === 'true';
372
372
  if (
373
373
  !isJdApp ||
374
374
  !isSupportHybridHttpRequest ||
375
375
  !isGlobalOpenHybirdHttpRequest ||
376
376
  isWhxFunctionId ||
377
377
  isJdAndHarmonyDevice
378
378
  ) {
379
379
  return false;
380
380
  }
381
381
  const configData = global.getDynamicConfig('hybridHttpSwitch');
382
382
  const { globalOn = false, grayscale = {} } = configData || {};
383
383
  const buildType = process.env.BUILD_TYPE || '';
384
384
  const isInvokeGray = globalOn || grayscale[buildType];
385
385
  console.log(
386
386
  '使用hybrid请求是否命中灰度,isInvokeGray:',
387
387
  isInvokeGray,
388
388
  '获取mpaas配置hybridHttpSwitch原始数据configData',
389
389
  configData,
390
390
  );
391
391
  const hasWindowXWebView = !!window.XWebView;
392
392
  return isInvokeGray && hasWindowXWebView;
393
393
  } catch (e) {
394
394
  console.log('获取是否使用Hybrid请求出错,e:', e);
395
395
  return false;
396
396
  }
397
397
  }
398
398
 
399
399
  _hybridRequest(url: string, data: any): Promise<any> {
400
400
  return new Promise((resolve, reject) => {
401
401
  try {
402
402
  const changeCurrentUrl = url.startsWith('//') ? `https:${url}` : url;
403
403
  const { functionId, body, ...otherH5Param } = data;
404
404
  const reqParams = {
405
405
  url: isIosDevice ? `${changeCurrentUrl}/` : changeCurrentUrl,
406
406
  functionId: functionId,
407
407
  body: body,
408
408
  headerType: '0',
409
409
  param: {
410
410
  ...otherH5Param,
411
411
  },
412
412
  header: {
413
413
  Referer: window.location.origin,
414
414
  },
415
415
  };
416
416
  const callbackFunction = this._generateCallbackFunction();
417
417
  this.#callbackFunction = callbackFunction;
418
418
  this.#requestTimeStamp = Date.now();
419
419
  this.#reportType = HTTP_REQUEST_TYPE.HYBRID;
420
420
  window.XWebView.callNative(
421
421
  'ColorQueryPlugin',
422
422
  'colorRequest',
423
423
  JSON.stringify(reqParams),
424
424
  callbackFunction,
425
425
  '1',
426
426
  );
427
427
  window[callbackFunction] = (result) => {
428
428
  this.#responseTimeStamp = Date.now();
429
429
  try {
430
430
  const resultObj = typeof result === 'string' ? JSON.parse(result) : result;
431
431
  resolve(resultObj);
432
432
  } catch (error) {
433
433
  const errorMessage = 'hybrid网络请求JSON解析失败, error: ' + error;
434
434
  draBusinessCustomReport({
435
435
  eventName: 'parseData',
436
436
  errorName: `shop_${HTTP_REQUEST_TYPE.HYBRID}_error`,
437
437
  errorMessage,
438
438
  });
439
439
  reject({ errMsg });
440
440
  }
441
441
  this._clearFunction(callbackFunction);
442
442
  };
443
443
  } catch (error) {
444
444
  reject({
445
445
  errMsg: 'hybrid网络请求,App下调用window.XWebView.callNative出错, error: ' + error,
446
446
  });
447
447
  }
448
448
  });
449
449
  }
450
450
 
451
451
  _generateCallbackFunction() {
452
452
  return `hybridHttpRequestCallback_${Date.now()}_${Math.ceil(Math.random() * 100000)}`;
453
453
  }
454
454
 
455
455
  _clearFunction(functionName: string) {
456
456
  try {
457
457
  delete window[functionName];
458
458
  } catch (e) {
459
459
  window[functionName] = undefined;
460
460
  }
461
461
  }
462
462
 
463
463
  async _prepareGatewayReqData(data: any, isColorVerify: boolean): Promise<any> {
464
464
  const { functionId } = data;
465
465
  console.log('获取当前是否需要color加固', isColorVerify, functionId);
466
466
  if (isColorVerify) {
467
467
  const { h5st } = await colorSign.paramsSign(data);
468
468
  h5st && (data.h5st = encodeURI(h5st));
469
469
  console.log(`${functionId}的apiReq_h5st===>:${h5st}`);
470
470
  }
471
471
  const { jsToken } = await colorSign.getFmInfo();
472
472
  console.log(`${functionId}的api jsToken指纹===>:${jsToken}`);
473
473
  jsToken && (data['x-api-eid-token'] = jsToken);
474
474
  return data;
475
475
  }
476
476
 
477
477
  _taroRequest(
478
478
  url: string,
479
479
  otherOpts: any,
480
480
  method: string,
481
481
  timeout: number,
482
482
  header: string,
483
483
  ): Promise<any> {
484
484
  const reqParam = {
485
485
  url,
486
486
  method,
487
487
  timeout,
488
488
  header,
489
489
  credentials: 'include',
490
490
  ...otherOpts,
491
491
  };
492
492
  this.#requestTimeStamp = Date.now();
493
493
  this.#reportType = HTTP_REQUEST_TYPE.TARO;
494
494
  return Taro.request(reqParam);
495
495
  }
496
496
 
497
497
  _reportRequestTime(url: string, data: any): void {
498
498
  this.#getResTimeStamp = Date.now();
499
499
  if (this.#reportType === HTTP_REQUEST_TYPE.TARO) {
500
500
  this.#responseTimeStamp = this.#getResTimeStamp;
501
501
  }
502
502
  draInterfaceCustomReport(
503
503
  {
504
504
  type: `${this.#reportType}_consumeTime`,
505
505
  url,
506
506
  functionId: data?.functionId,
507
507
  requestTimeStamp: this.#requestTimeStamp,
508
508
  responseTimeStamp: this.#responseTimeStamp,
509
509
  errMsg: `使用${this.#reportType}调用接口请求响应耗时`,
510
510
  source: 'remote',
511
511
  },
512
512
  {
513
513
  consumeTime: `${this.#responseTimeStamp - this.#requestTimeStamp}ms`,
514
514
  getResTime: `${this.#getResTimeStamp - this.#requestTimeStamp}ms`,
515
515
  },
516
516
  );
517
517
  }
518
518
 
519
519
  _handleReportInterfaceError(url: string, reqData: any, timeOut: any, res: any): void {
520
520
  const source = 'remote';
521
521
  const requestType = this.#reportType;
522
522
  let errorMessage = '';
523
523
  let reportFlag = false;
524
524
  if (res) {
525
525
  const { statusCode, data, status, resTimeoutState } = res;
526
526
  if ((statusCode === 200 || status === '0') && data) {
527
527
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
528
528
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
529
529
  ? Number(data.subCode)
530
530
  : -1;
531
531
  const isSuccess =
532
532
  data.success === true ||
533
533
  data.isSuccess ||
534
534
  resCode === 0 ||
535
535
  resCode === 200 ||
536
536
  subCode === 0;
537
537
  if (!isSuccess && resCode !== 3) {
538
538
  reportFlag = true;
539
539
  errorMessage = `接口返回code码为${res?.data?.code}`;
540
540
  reportFlag &&
541
541
  draInterfaceCustomReport({
542
542
  eventName: 'apiCode',
543
543
  errorName:`shop_${reqData?.functionId}_error`,
544
544
  errorMessage,
545
545
  url,
546
546
  source,
547
547
  requestType,
548
548
  functionId: reqData?.functionId,
549
549
  appid: reqData?.appId,
550
550
  client: reqData?.client,
551
551
  clientVersion: reqData?.clientVersion,
552
552
  statusCode: res?.statusCode,
553
553
  status: res?.status,
554
554
  code: res?.data?.code || res?.data?.subCode,
555
555
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
556
556
  originReqDataStr: JSON.stringify(reqData),
557
557
  originResDataStr: JSON.stringify(res),
558
558
  });
559
559
  }
560
560
  } else {
561
561
  reportFlag = true;
562
562
  errorMessage = `接口返回statusCode为${res?.statusCode || res?.status}`;
563
563
  reportFlag &&
564
564
  draInterfaceCustomReport({
565
565
  eventName: 'apiStatusCode',
566
566
  errorName:`shop_${reqData?.functionId}_error`,
567
567
  errorMessage,
568
568
  url,
569
569
  source,
570
570
  requestType,
571
571
  functionId: reqData?.functionId,
572
572
  appid: reqData?.appId,
573
573
  client: reqData?.client,
574
574
  clientVersion: reqData?.clientVersion,
575
575
  statusCode: res?.statusCode,
576
576
  status: res?.status,
577
577
  code: res?.data?.code || res?.data?.subCode,
578
578
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
579
579
  originReqDataStr: JSON.stringify(reqData),
580
580
  });
581
581
  }
582
582
  }
583
583
  }
@@ -0,0 +1 @@
1
+ import Taro from '@tarojs/taro'
2
  const requestParams = chain.requestParams
1
3
  const { header, data } = requestParams
2
4
  const { wqCookie, wqVisitkey = '-1' } = global?.info?.userInfo
3
5
  header['wqreferer'] = `https://wq.jd.com/wxapp/pages/shopx/pages/index/index`
4
6
  header['Cookie'] = wqCookie
5
7
  if (data && data['functionId'] && data['uuid'] && wqVisitkey !== '-1') {
6
8
  data['uuid'] = wqVisitkey
7
9
  }
8
10
  return chain.proceed(requestParams).then((res) => {
9
11
  if (res.statusCode === HttpStatus.SUCCESS) {
10
12
  return res
11
13
  } else {
12
14
  return {
13
15
  statusCode: res.statusCode,
14
16
  msg: httpStatusMsg[res.statusCode] || defaultHttpStatusMsg,
15
17
  }
16
18
  }
17
19
  })