qb-pc-sdk 1.0.8 → 1.0.9

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "qb-pc-sdk",
3
- "version": "1.0.8",
4
- "description": "趣变广告 SDK 封装器 - 隐藏自动请求微信sdk",
3
+ "version": "1.0.9",
4
+ "description": "趣变广告 SDK 封装器 - 更新正式sdk",
5
5
  "main": "index.js",
6
6
  "files": [
7
7
  "index.js",
@@ -285,8 +285,8 @@
285
285
 
286
286
  // 内部常量配置
287
287
  const API_CONFIG = {
288
- INIT: 'http://test.qubiankeji.com:8084/pc/init',
289
- POSITION: 'http://test.qubiankeji.com:8084/pc/position',
288
+ INIT: 'http://app.qubiankeji.com:8084/pc/init',
289
+ POSITION: 'http://app.qubiankeji.com:8084/pc/position',
290
290
  GDT_SDK_ID: 2 // 标识
291
291
  };
292
292
 
@@ -347,14 +347,33 @@
347
347
  fetch(`${API_CONFIG.POSITION}?positionId=${this.config.placementId}`).then(r => r.json())
348
348
  ]);
349
349
 
350
+ // 处理返回数据结构:支持 { data: {...} } 或直接返回数据
351
+ const initData = initRes.data || initRes;
352
+ const posData = posRes.data || posRes;
353
+
350
354
  // 2. 提取 AppID
351
- this.gdtAppId = initRes.thirdIdMap ? initRes.thirdIdMap[String(API_CONFIG.GDT_SDK_ID)] : null;
355
+ this.gdtAppId = initData.thirdIdMap ? initData.thirdIdMap[String(API_CONFIG.GDT_SDK_ID)] : null;
352
356
 
353
357
  // 3. 执行广告位筛选逻辑
354
- this.gdtPlacementId = this._selectPlacementId(posRes);
358
+ this.gdtPlacementId = this._selectPlacementId(posData);
359
+
360
+ // 添加调试日志(始终输出,便于排查问题)
361
+ console.log('[AdSDK] 初始化数据:', {
362
+ initRes: initRes,
363
+ posRes: posRes,
364
+ initData: initData,
365
+ posData: posData,
366
+ gdtAppId: this.gdtAppId,
367
+ gdtPlacementId: this.gdtPlacementId
368
+ });
355
369
 
356
370
  if (!this.gdtAppId || !this.gdtPlacementId) {
357
- throw new Error('未找到匹配的(sdkId:2)配置信息');
371
+ const errorMsg = `未找到匹配的(sdkId:2)配置信息 - AppId: ${this.gdtAppId}, PlacementId: ${this.gdtPlacementId}`;
372
+ console.error('[AdSDK]', errorMsg, {
373
+ initData: initData,
374
+ posData: posData
375
+ });
376
+ throw new Error(errorMsg);
358
377
  }
359
378
 
360
379
  this._checkAndRun();
@@ -368,21 +387,62 @@
368
387
  * 规则:headSetList优先;否则选positionSetList中优先级最高的
369
388
  */
370
389
  _selectPlacementId(data) {
390
+ if (!data) {
391
+ console.error('[AdSDK] _selectPlacementId: data 为空');
392
+ return null;
393
+ }
394
+
395
+ // 添加调试信息
396
+ console.log('[AdSDK] _selectPlacementId 输入数据:', data);
397
+ const targetSdkId = API_CONFIG.GDT_SDK_ID;
398
+ console.log('[AdSDK] 查找 sdkId (类型:', typeof targetSdkId, '值:', targetSdkId, ')');
399
+
371
400
  // A. 优先检查 headSetList
372
- if (data.headSetList && data.headSetList.length > 0) {
373
- const headAd = data.headSetList.find(item => item.sdkId === API_CONFIG.GDT_SDK_ID);
374
- if (headAd) return headAd.positionId;
401
+ if (data.headSetList && Array.isArray(data.headSetList) && data.headSetList.length > 0) {
402
+ console.log('[AdSDK] 检查 headSetList:', data.headSetList);
403
+ const headAd = data.headSetList.find(item => {
404
+ // 支持数字和字符串类型的比较
405
+ const itemSdkId = Number(item.sdkId);
406
+ const match = itemSdkId === targetSdkId || String(item.sdkId) === String(targetSdkId);
407
+ if (!match) {
408
+ console.log('[AdSDK] headSetList 项不匹配:', item, 'sdkId:', item.sdkId, '类型:', typeof item.sdkId);
409
+ }
410
+ return match;
411
+ });
412
+ if (headAd) {
413
+ console.log('[AdSDK] ✅ 在 headSetList 中找到匹配项:', headAd);
414
+ return headAd.positionId;
415
+ }
375
416
  }
376
417
 
377
418
  // B. 检查 positionSetList
378
- if (data.positionSetList && data.positionSetList.length > 0) {
419
+ if (data.positionSetList && Array.isArray(data.positionSetList) && data.positionSetList.length > 0) {
420
+ console.log('[AdSDK] 检查 positionSetList:', data.positionSetList);
379
421
  const sortedList = data.positionSetList
380
- .filter(item => item.sdkId === API_CONFIG.GDT_SDK_ID)
381
- .sort((a, b) => b.callbackPriority - a.callbackPriority); // 按优先级从大到小排序
382
-
383
- return sortedList.length > 0 ? sortedList[0].positionId : null;
422
+ .filter(item => {
423
+ // 支持数字和字符串类型的比较
424
+ const itemSdkId = Number(item.sdkId);
425
+ const match = itemSdkId === targetSdkId || String(item.sdkId) === String(targetSdkId);
426
+ console.log('[AdSDK] positionSetList 项检查:', {
427
+ item: item,
428
+ itemSdkId: item.sdkId,
429
+ itemSdkIdType: typeof item.sdkId,
430
+ targetSdkId: targetSdkId,
431
+ targetSdkIdType: typeof targetSdkId,
432
+ match: match
433
+ });
434
+ return match;
435
+ })
436
+ .sort((a, b) => (b.callbackPriority || 0) - (a.callbackPriority || 0)); // 按优先级从大到小排序
437
+
438
+ console.log('[AdSDK] 筛选后的列表:', sortedList);
439
+ if (sortedList.length > 0) {
440
+ console.log('[AdSDK] ✅ 在 positionSetList 中找到匹配项:', sortedList[0]);
441
+ return sortedList[0].positionId;
442
+ }
384
443
  }
385
444
 
445
+ console.error('[AdSDK] ❌ 未找到匹配的 sdkId:', targetSdkId, '数据:', data);
386
446
  return null;
387
447
  }
388
448
 
@@ -39,8 +39,8 @@
39
39
 
40
40
  // 初始化广告
41
41
  new window.AdSDK({
42
- appId: '1999336062823956569',
43
- placementId: '1999381081819709520',
42
+ appId: '1999364640831725629',
43
+ placementId: '2003009002186760245',
44
44
  container: '#ad-slot-1',
45
45
  onAdLoaded: () => console.log('✅ 广告加载完成'),
46
46
  onAdError: (err, msg) => console.log('❌ 广告报错:', err, msg),