收藏
回答

微信短剧播放组件,短剧已经审核成功,也跟着文档的要求进行了相应的配置,为什么一直卡在封面无法播放?

async goPlayer() {

    try {

        // **1. 获取加密数据**

        const encryptedData = await getEncryptData({

            openid: uni.getStorageSync('openid'),

            srcAppId: 'wxbc2e45b8f33c6094',

            dramaId: '101357',

            serialList: [

                { start_serial_no: 1, end_serial_no: 5, status: 1 }, // 1~5 集免费

                { start_serial_no: 6, end_serial_no: 20, status: 2 } // 6~20 需解锁

            ],

            dataExpireAt: Math.floor(Date.now() / 1000) + 7200 // 2 小时有效期

        });

        console.log("✅ 加密数据获取成功:", encryptedData);

        // **2. 禁止录屏**

        wx.setVisualEffectOnCapture({

            visualEffect: 'hidden',

        });

        // **3. 监听播放器加载,获取 `playerId`**

        plugin.onPageLoad((info) => {

            console.log("🎬 播放器加载完成:", info);

            if (!info.playerId) {

                console.error("❌ 无法获取 playerId");

                return;

            }

            // **4. 获取播放器管理实例 `pm`**

            const pm = plugin.PlayletManager.getPageManager(info.playerId);

console.log(plugin,'plugin');

            if (!pm) {

                console.error("❌ 获取播放器实例失败!");

                return;

            }

            console.log("✅ 成功获取播放器实例:", pm);

pm.isCanPlay({

    data:  encryptedData,

    serialNo:'101357',

    status: '1' // 1=可播放, 2=需解锁

});

            // **5. 设置可播放剧集**

            pm.setCanPlaySerialList({

                data: encryptedData,

                freeList: [{ start_serial_no: 1, end_serial_no: 5 }] // 1~5 集免费

            });

            // // **6. 监听解锁事件**

            // pm.onCheckIsCanPlay((param) => {

            //     console.log("🔓 需要检查是否可播放:", param);

            //     this.handleUnlock(param, pm);

            // });

            // // **7. 监听播放器错误**

            // pm.onPlayError((err) => {

            //     console.log("❌ 播放失败:", err);

            // });

        });

        // **8. 跳转到播放器**

        PlayerManager.navigateToPlayer({

            srcAppid: 'wxbc2e45b8f33c6094',

            dramaId: '101357',

            serialNo: 1, // ✅ 这里必须是数字

            extParam: encodeURIComponent('a=b&c=d') // ✅ 传递 extParam 避免 `getLaunch options` 失败

        });

let parms = {

userId : uni.getStorageSync('userId'),

playletId : '101357',

controlType :'watch'

}

userActionApi(parms).then(res=>{

console.log(res,'用户行为');

})

        console.log("🚀 已跳转到播放器,等待 onPageLoad 触发...");

    } catch (error) {

        console.error("❌ 加密数据失败:", error);

        uni.showToast({

            title: '获取加密数据失败',

            icon: 'none'

        });

    }

},

页面也没有报错,就是一直在播放页转圈

最后一次编辑于  1天前
回答关注问题邀请回答
收藏

2 个回答

  • 小程序短剧社区运营-Carina
    小程序短剧社区运营-Carina
    1天前

    您好,能否提供代码片段进一步定位问题呢?https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

    1天前
    有用
    回复 7
    查看更多(2)
  • S
    S
    1天前

    这是文档里要求需要给传递的信息加密,故封装的数据加密方法

    import CryptoJS from 'crypto-js';

    import { getKeyApi } from '../request/api';


    console.log("🔥 encrypt.js 被加载了!");


    export function getEncryptData({ serialList, openid, srcAppId, dramaId }) {

      console.log("✅ getEncryptData 被调用了!");

      console.log( serialList,'serialList',

    openid,'openid',

    srcAppId,'srcAppId',

    dramaId,'dramaId'

      );

      return new Promise((resolve, reject) => {

        const sessionKey = uni.getStorageSync('sessionKey');

        if (!sessionKey) {

          return reject('session_key 为空,请重新登录');

        }


        let key = sessionKey.slice(0, 16).padEnd(16, '\0');


        const lockData = {

    session_key:sessionKey,

    openid: openid || uni.getStorageSync('openid'),

    src_appid: srcAppId,

    drama_id: dramaId,

    serial_list: serialList,

    data_expire_at: Math.floor(Date.now() / 1000) + 7200 

        };


        try {

    getKeyApi(lockData).then(res=>{

    console.log(res,'res');

    const encryptedData = res.data

    resolve(encryptedData);

    })

          // const dataStr = JSON.stringify(lockData);

          // const encrypted = CryptoJS.AES.encrypt(dataStr, CryptoJS.enc.Utf8.parse(key), {

          //   mode: CryptoJS.mode.ECB,

          //   padding: CryptoJS.pad.Pkcs7

          // });


          // const encryptedData = encrypted.toString();

          // resolve(encryptedData);

        } catch (error) {

          reject('加密失败: ' + error);

        }

      });

    }

    1天前
    有用
    回复
登录 后发表内容