diff --git a/components/charge-dialog/charge-dialog.vue b/components/charge-dialog/charge-dialog.vue index 9167a12..bd2e51e 100644 --- a/components/charge-dialog/charge-dialog.vue +++ b/components/charge-dialog/charge-dialog.vue @@ -6,7 +6,7 @@ 解锁后可继续观看 - @@ -38,9 +38,9 @@ {{ item.pay_num }}金豆+{{ item.pay_give_num }}豆 - - {{ item.pay_num }}金豆 - + + {{ item.pay_num }}金豆 + 全部影片免费观看 本剧订阅全集 @@ -68,10 +68,11 @@ {{ item.remark ? item.remark : '' }} - + + 看广告解锁 充值代表接受 《充值/退款协议》 @@ -81,23 +82,7 @@ 本小程序共有{{ allVideoNum }}部剧正在热播 - - - - - - - - 用户只能发起一次邀请 - 有效时间为24小时 - 分享好友拼团,拼成退差价 - - - - - - @@ -107,6 +92,8 @@ } from '@/utils/request' import PAY from '@/utils/pay' const playletPlugin = requirePlugin('playlet-plugin') + import config from "@/utils/config"; + import insertAd from '@/utils/insertAd' export default { name: "payDom", props: { @@ -145,7 +132,8 @@ payItemData: {}, g_order_id: "", is_check: false, - allVideoNum: 0 + allVideoNum: 0, + adLoaded: false } }, watch: { @@ -154,10 +142,10 @@ this.is_check = uni.getStorageSync('config').is_check == 1 ? true : false; this.userInfo = uni.getStorageSync('userinfo'); this.system = uni.getSystemInfoSync().osName; - this.initChargeDialog(); + this.initChargeDialog(); this.getVideoData(); - this.getAllVideoNum(); - this.getPayList(); + this.getPayList(); + this.initAd(); }, playerId(newValue, oldvalue) { console.log('this.initChargeDialog', newValue) @@ -165,6 +153,31 @@ }, methods: { + // 初始化广告 + initAd() { + let pms = this.getPlayerManager(); + // 监听加载成功 → 显示按钮 + insertAd.insertAdonLoad(() => { + this.adLoaded = true; + }); + // 监听加载失败 → 隐藏按钮 + insertAd.insertAdonError(() => { + this.adLoaded = false; + }); + // 监听关闭 + insertAd.insertAdonClose((isEnded) => { + if (isEnded) { + console.log('广告看完,发放奖励'); + // TODO: 调用你的解锁接口 + pms.emitCustomEvent('adEnd', this.im) + } + }); + // 开始加载广告 + insertAd.insertAdload(); + }, + showAd() { + insertAd.insertAdshow(); + }, goAgreement(num) { const pm = this.getPlayerManager() pm.navigateTo({ @@ -200,16 +213,16 @@ return playletPlugin.PlayletManager.getPageManager(this.playerId); }, onShowChargeDialog() { - console.log('onShowChargeDialog bbs') + console.log('onShowChargeDialog bbs') this.getPayList(); }, onHideChargeDialog() { // this.$refs.back_ref.close(); }, - close_pay_box(){ - const pm = this.getPlayerManager() - pm.hideChargeDialog(); - }, + close_pay_box() { + const pm = this.getPlayerManager() + pm.hideChargeDialog(); + }, getAllVideoNum() { httpRequest({ url: "/api/video/videoCount", @@ -249,15 +262,15 @@ video_list_id: this.vid } }).then(res => { - if(res.code == 1){ - this.payListGroupId = uni.getStorageSync('config').pay_tpl; - // this.payListGroupId = 2; - this.list_pay = res.data - }else if(res.code ==50){ - this.is_check = true; - } + if (res.code == 1) { + this.payListGroupId = uni.getStorageSync('config').pay_tpl; + // this.payListGroupId = 2; + this.list_pay = res.data + } else if (res.code == 50) { + this.is_check = true; + } - }).catch(err => { + }).catch(err => { console.log(err) }) }, @@ -381,89 +394,20 @@ }) }, - // wxxcx_xuni(data) { - // console.log(data) - // let that = this, - // pms = that.getPlayerManager(); - // uni.requestVirtualPayment({ - // signData: JSON.stringify({ - // buyQuantity: data.signData.buyQuantity, - // currencyType: data.signData.currencyType, - // env: data.signData.env, - // goodsPrice: data.signData.goodsPrice, - // offerId: data.signData.offerId, - // outTradeNo: data.signData.outTradeNo, - // platform: data.signData.platform, - // productId: data.signData.productId, - // attach: data.signData.attach, - // }), - // paySig: data.paySig, - // signature: data.signature, - // mode: 'short_series_coin', - // success(res) { - // let payParam = { - // status: 'paySuccess', - // serialNo: that.serialNo, - // gOrderId: "", - // vid: that.vid, - // oid: data.oid - // } - // if (that.payItemData.pay_type == 4) { - // // that.$refs.back_ref.open('center'); - // that.payEnd(payParam) - // } else { - // pms.emitCustomEvent('chargeEnd', payParam) - // } - // }, - // fail({errMsg, errCode}) { - // console.log(errMsg, errCode, data.signature) - // }, - // }) - // }, - // wxxcx(data) { - // let that = this, - // pms = that.getPlayerManager(); - // uni.requestPayment({ - // "provider": 'wxpay', - // "appId": data.appId, - // "timeStamp": data.timeStamp + '', - // "nonceStr": data.nonceStr, - // "package": data.package, - // "signType": 'MD5', - // "paySign": data.sign, - // success: function (res1) { - // let payParam = { - // status: 'paySuccess', - // serialNo: that.serialNo, - // gOrderId: "", - // vid: that.vid, - // oid: data.oid - // } - // if (that.payItemData.pay_type == 4) { - // // that.$refs.back_ref.open('center'); - // - // that.payEnd(payParam) - // } else { - // pms.emitCustomEvent('chargeEnd', payParam) - // } - // console.log('success:' + JSON.stringify(res1)); - // }, - // fail: function (err1) { - // console.log('fail:' + JSON.stringify(err1)); - // } - // }); - // }, - - - closePup() { - // this.$refs.back_ref.close(); - } }, } \ No newline at end of file diff --git a/utils/insertAd.js b/utils/insertAd.js new file mode 100644 index 0000000..125e584 --- /dev/null +++ b/utils/insertAd.js @@ -0,0 +1,66 @@ +let showtype = false + +// 激励视频广告实例(微信小程序) +const rewardedAd = wx.createRewardedVideoAd({ + adUnitId: 'adunit-xxxxxxxxxx', // TODO: 替换为你的微信激励广告单元ID +}); + +// 加载激励视频广告 +function insertAdload() { + rewardedAd.load().catch((err) => { + console.log('激励广告加载失败', err); + }); +} + +// 显示激励视频广告 +function insertAdshow() { + if (showtype) { + console.log("显示广告"); + rewardedAd.show().catch((err) => { + console.log('激励广告显示失败', err); + rewardedAd.load(); + }); + } +} + +// 监听广告加载成功(支持回调) +function insertAdonLoad(onSuccess) { + rewardedAd.onLoad(() => { + showtype = true; + console.log('激励广告加载成功'); + onSuccess && onSuccess(); + }); +} + +// 监听错误(支持回调) +function insertAdonError(onFail) { + rewardedAd.onError((err) => { + console.log('激励广告错误', err); + showtype = false; + onFail && onFail(); + setTimeout(() => { + insertAdload(); + }, 30000); + }); +} + +// 监听广告关闭(微信特有:可判断是否看完) +function insertAdonClose(callback) { + rewardedAd.onClose((res) => { + console.log('激励广告关闭', res); + if (res && res.isEnded) { + callback && callback(true); + } else { + callback && callback(false); + } + insertAdload(); + }); +} + +export default { + insertAdload, + insertAdshow, + insertAdonError, + insertAdonLoad, + insertAdonClose +} diff --git a/utils/login.js b/utils/login.js index 1dddb81..383e924 100644 --- a/utils/login.js +++ b/utils/login.js @@ -1,66 +1,69 @@ +import { + httpRequest +} from "./request.js"; +const login = { + wxLogin() { + return new Promise((resolve, reject) => { + uni.login({ + provider: 'weixin', + success: (res) => { + httpRequest({ + url: '/api/user/getOpenid', + data: { + code: res.code, //wx.login 登录成功后的code + ad_code: uni.getStorageSync('get_ad_code'), + invite: uni.getStorageSync("invite_number") + }, -import {httpRequest} from "./request.js"; -const login={ - wxLogin(){ - return new Promise((resolve,reject)=>{ - uni.login({ - provider: 'weixin', - success: (res) => { - httpRequest({ - url:'/api/user/getOpenid', - data:{ - code: res.code, //wx.login 登录成功后的code - ad_code: uni.getStorageSync('get_ad_code'), - invite: uni.getStorageSync("invite_number") - }, + }).then((opRes) => { + if (res.code == 1) { + uni.setStorageSync("openid", opRes.data.openid) + if (opRes.msg == '登录成功') { + uni.setStorageSync("userinfo", opRes.data.userinfo); + uni.setStorageSync("token", opRes.data.userinfo.token); + uni.setStorageSync("config", opRes.data.config); + resolve('login success') + } else { + this.Loginops(opRes).then(opRes => { + resolve('login success') + }).catch(logPErr => { + reject(logPErr) + }) + } + } + }).catch(opErr => { + reject(opErr) + }) + }, + fail: (err) => { + reject(err) + } + }); - }).then((opRes)=>{ - uni.setStorageSync("openid", opRes.data.openid) - if (opRes.msg == '登录成功') { - uni.setStorageSync("userinfo", opRes.data.userinfo); - uni.setStorageSync("token", opRes.data.userinfo.token); - uni.setStorageSync("config", opRes.data.config); - resolve('login success') - } else { - this.Loginops(opRes).then(opRes => { - resolve('login success') - }).catch(logPErr => { - reject(logPErr) - }) - } - }).catch(opErr=>{ - reject(opErr) - }) - }, - fail: (err) => { - reject(err) - } - }); - - }) - }, - Loginops(openData) { - return new Promise((resolve, reject) => { - httpRequest({ - url:'/api/user/getphone', - method: 'GET', - data: { - openid: openData.data.openid, - pid: '0', - invite: uni.getStorageSync('invite_number') ||'', - ad_code: uni.getStorageSync('get_ad_code') || '' - }, - }).then(uRes=>{ - if(uRes.code ==1){ - uni.setStorageSync("userinfo", uRes.data.userinfo); - uni.setStorageSync("token", uRes.data.userinfo.token); - uni.setStorageSync("config", uRes.data.config); - resolve('login success') - } - }).catch(uErr=>{ - reject(uErr) - }) - }) - }, + }) + }, + Loginops(openData) { + return new Promise((resolve, reject) => { + httpRequest({ + url: '/api/user/getphone', + method: 'GET', + data: { + openid: openData.data.openid, + pid: '0', + invite: uni.getStorageSync('invite_number') || '', + ad_code: uni.getStorageSync('get_ad_code') || '' + }, + }).then(uRes => { + if (uRes.code == 1) { + uni.setStorageSync("userinfo", uRes.data.userinfo); + uni.setStorageSync("token", uRes.data.userinfo.token); + uni.setStorageSync("config", uRes.data.config); + resolve('login success') + } + }).catch(uErr => { + reject(uErr) + }) + }) + }, } - export default login \ No newline at end of file +export default login \ No newline at end of file diff --git a/utils/playerManager.js b/utils/playerManager.js index 462642c..1f235e5 100644 --- a/utils/playerManager.js +++ b/utils/playerManager.js @@ -1,423 +1,509 @@ var playletPlugin = requirePlugin("playlet-plugin"); +var serialNo = null import configs from '@/utils/config.js'; -import {httpRequest} from '@/utils/request' -import {login} from './login' +import { + httpRequest +} from '@/utils/request' +import { + login +} from './login' import PAY from '@/utils/pay' // 点击按钮触发此函数跳转到播放器页面 function navigateToPlayer(obj) { - // 下面的${dramaId}变量,需要替换成小程序管理后台的媒资管理上传的剧的dramaId - // 变量${srcAppid}是提审方appid - // 变量${serialNo}第几集 - // 变量${extParam}是分享参数,分享的卡片和二维码会在分享的链接上携带此参数 - const { extParam, dramaId, srcAppid=configs.mini_appid,serialNo=1 } = obj - wx.navigateTo({ - url: `plugin-private://wx94a6522b1d640c3b/pages/playlet/playlet?dramaId=${dramaId}&srcAppid=${srcAppid}&serialNo=${serialNo}&extParam=${extParam || ''}` - }) + // 下面的${dramaId}变量,需要替换成小程序管理后台的媒资管理上传的剧的dramaId + // 变量${srcAppid}是提审方appid + // 变量${serialNo}第几集 + // 变量${extParam}是分享参数,分享的卡片和二维码会在分享的链接上携带此参数 + const { + extParam, + dramaId, + srcAppid = configs.mini_appid, + serialNo = 1 + } = obj + wx.navigateTo({ + url: `plugin-private://wx94a6522b1d640c3b/pages/playlet/playlet?dramaId=${dramaId}&srcAppid=${srcAppid}&serialNo=${serialNo}&extParam=${extParam || ''}` + }) } + function deepClone(obj) { - if (typeof obj !== 'object' || !obj) return obj - let newObj = obj instanceof Array ? [] : {} - for (let key in obj) { - if (typeof obj[key] === 'object') { - newObj[key] = deepClone(obj[key]) - } else { - newObj[key] = obj[key] - } - } - return newObj + if (typeof obj !== 'object' || !obj) return obj + let newObj = obj instanceof Array ? [] : {} + for (let key in obj) { + if (typeof obj[key] === 'object') { + newObj[key] = deepClone(obj[key]) + } else { + newObj[key] = obj[key] + } + } + return newObj } const proto = { - data: { // 可通过this.data访问 - playerId: '',//播放器id - arr: [], - vid:"",//剧id - info:{}, - mid:"",//剧集id - userInfo:{}, - is_record:0,//是否追剧 0未追 1已追 - pay_oid:'', - }, - _onPlayerLoad(info) { - let that = this, - shareInterval = null; - console.log("_onPlayerLoad",info); - if(info.extParam){ - if(info.extParam.indexOf("%")<0){ - this.data.info = info; - }else if(info.extParam){ - info.extParam = decodeURIComponent(info.extParam ) - this.data.info = info; - }else{} - this.data.vid = JSON.parse(info.extParam).vid; - if(JSON.parse(info.extParam).g_order_id){//存储分享后的gid - uni.setStorageSync('g_order_id',JSON.parse(info.extParam).g_order_id); - uni.setStorageSync('g_order_vid',JSON.parse(info.extParam).vid); - } - } - this.data.playerId = info.playerId - const pm = playletPlugin.PlayletManager.getPageManager(info.playerId) - this.pm = pm + data: { // 可通过this.data访问 + playerId: '', //播放器id + arr: [], + vid: "", //剧id + info: {}, + mid: "", //剧集id + userInfo: {}, + is_record: 0, //是否追剧 0未追 1已追 + pay_oid: '', + }, + _onPlayerLoad(info) { + let that = this, + shareInterval = null; + console.log("_onPlayerLoad", info); + if (info.extParam) { + if (info.extParam.indexOf("%") < 0) { + this.data.info = info; + } else if (info.extParam) { + info.extParam = decodeURIComponent(info.extParam) + this.data.info = info; + } else {} + this.data.vid = JSON.parse(info.extParam).vid; + if (JSON.parse(info.extParam).g_order_id) { //存储分享后的gid + uni.setStorageSync('g_order_id', JSON.parse(info.extParam).g_order_id); + uni.setStorageSync('g_order_vid', JSON.parse(info.extParam).vid); + } + } + this.data.playerId = info.playerId + const pm = playletPlugin.PlayletManager.getPageManager(info.playerId) + this.pm = pm - let user = uni.getStorageSync('userinfo'); - if(user.token){ - this.data.userInfo = uni.getStorageSync('userinfo'); - console.log('onPlayerLoad info', info, 'data', this.data) - that.getVideoId(); - that.getEncryptData({serialNo: info.serialNo}).then(setRes => { - // encryptedData是后台加密后的数据,具体实现见官方文档的加密章节 - let lists = [setRes.data]; - pm.setCanPlaySerialList({ - data: setRes.encryptedData, - freeList:lists - // freeList: [{ // 1~10集是免费剧,data里面的字段也必须至少设置1~10集可播放 - // start_serial_no: setRes.data.start_serial_no, - // end_serial_no: setRes.data.end_serial_no - // }], - }) - }); - }else{ - login.wxLogin().then(res=>{ - this.data.userInfo = uni.getStorageSync('userinfo'); - console.log('onPlayerLoad info', info, 'data', this.data) - that.getVideoId(); - that.getEncryptData({serialNo: info.serialNo}).then(setRes => { - // encryptedData是后台加密后的数据,具体实现见官方文档的加密章节 - let lists = [setRes.data]; - pm.setCanPlaySerialList({ - data: setRes.encryptedData, - freeList:lists - }) - }); - }); - } + let user = uni.getStorageSync('userinfo'); + if (user.token) { + this.data.userInfo = uni.getStorageSync('userinfo'); + console.log('onPlayerLoad info', info, 'data', this.data) + that.getVideoId(); + that.getEncryptData({ + serialNo: info.serialNo + }).then(setRes => { + // encryptedData是后台加密后的数据,具体实现见官方文档的加密章节 + let lists = [setRes.data]; + pm.setCanPlaySerialList({ + data: setRes.encryptedData, + freeList: lists + // freeList: [{ // 1~10集是免费剧,data里面的字段也必须至少设置1~10集可播放 + // start_serial_no: setRes.data.start_serial_no, + // end_serial_no: setRes.data.end_serial_no + // }], + }) + }); + } else { + login.wxLogin().then(res => { + this.data.userInfo = uni.getStorageSync('userinfo'); + console.log('onPlayerLoad info', info, 'data', this.data) + that.getVideoId(); + that.getEncryptData({ + serialNo: info.serialNo + }).then(setRes => { + // encryptedData是后台加密后的数据,具体实现见官方文档的加密章节 + let lists = [setRes.data]; + pm.setCanPlaySerialList({ + data: setRes.encryptedData, + freeList: lists + }) + }); + }); + } - // 需要解锁的事件 - pm.onCheckIsCanPlay(this.onCheckIsCanPlay); - // 页面返回事件 - pm.onBack(this.pageBack) - // 支付回调事件 - pm.onCustomEvent('chargeEnd', this.chargeEnd) - pm.setVisualEffectOnCapture({ - visualEffect: 'none', - }) - // 参考文档章节“数据上报” - pm.onDataReport((obj) => { - if(obj.event === playletPlugin.REPORT_DATA_EVENTS.LIKE || obj.event === playletPlugin.REPORT_DATA_EVENTS.UNLIKE){//监听点赞、取消点赞操作 - console.log("user like") - this.userLikeChange(); - }else if(obj.event === playletPlugin.REPORT_DATA_EVENTS.FAV || obj.event === playletPlugin.REPORT_DATA_EVENTS.UNFAV){//监听在追,取消在追操作 - console.log("user zhui ju") - this.changeStar() - }else if(obj.event === playletPlugin.REPORT_DATA_EVENTS.CHANGE_SERIAL){//监听切换剧集操作 - console.log("user changePlay log") - this.changePlayLog() - }else if(obj.event === playletPlugin.REPORT_DATA_EVENTS.SHARE){//监听分享操作 - console.log("user share") - }else { - // console.log("其他操作") - } + // 需要解锁的事件 + pm.onCheckIsCanPlay(this.onCheckIsCanPlay); + // 页面返回事件 + pm.onBack(this.pageBack) + // 支付回调事件 + pm.onCustomEvent('chargeEnd', this.chargeEnd) + pm.setVisualEffectOnCapture({ + visualEffect: 'none', + }) + // 参考文档章节“数据上报” + pm.onDataReport((obj) => { + if (obj.event === playletPlugin.REPORT_DATA_EVENTS.LIKE || obj.event === playletPlugin + .REPORT_DATA_EVENTS.UNLIKE) { //监听点赞、取消点赞操作 + console.log("user like") + this.userLikeChange(); + } else if (obj.event === playletPlugin.REPORT_DATA_EVENTS.FAV || obj.event === playletPlugin + .REPORT_DATA_EVENTS.UNFAV) { //监听在追,取消在追操作 + console.log("user zhui ju") + this.changeStar() + } else if (obj.event === playletPlugin.REPORT_DATA_EVENTS.CHANGE_SERIAL) { //监听切换剧集操作 + console.log("user changePlay log") + this.changePlayLog() + } else if (obj.event === playletPlugin.REPORT_DATA_EVENTS.SHARE) { //监听分享操作 + console.log("user share") + } else { + // console.log("其他操作") + } - }) - // 设置右侧固定运营位置跳转路径 - pm.setActivityInfo({ - url: '' - }) - // 设置运营区域 - pm.updateOpenArea({ - showLeft: false, - showRight: false, - leftsideAreaList: [ - { - left: 16, // 类似绝对定位的样式 - top: 20, - width: 72, - height: 32 - }, - ], - ext: 'extInfo', - }) - }, - _initShare() { - const pm = this.pm - // 关于分享的处理 - // 开启分享以及withShareTicket - pm.setDramaFlag({ - share: true, - withShareTicket: true - }) - // 获取分享参数,页面栈只有短剧播放器一个页面的时候可获取到此参数 - // 例如从分享卡片进入、从投流广告直接跳转到播放器页面,从二维码直接进入播放器页面等情况 - playletPlugin.getShareParams().then(res => { - console.log('getLaunch options query res', res) - // 关于extParam的处理,需要先做decodeURIComponent之后才能得到原值 - const extParam = decodeURIComponent(res.extParam) - console.log('getLaunch options extParam', extParam) - // 如果设置了withShareTicket为true,可通过文档的方法获取更多信息 - // https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html - const enterOptions = wx.getEnterOptionsSync() - console.log('getLaunch options shareTicket', enterOptions.shareTicket) - }).catch(err => { - console.log('getLaunch options query err', err) - }) - this.getVideoId() - // 设置分享参数 - pm.setExtParam(JSON.stringify({ - vid:this.data.vid, - fxpid:this.data.userInfo.id, - invite:this.data.userInfo.invite||'' - })) - }, - // 检测是否可以播放 - onCheckIsCanPlay(param) { - var that = this; - let intervalTime=null; - console.log('onCheckIsCanPlay param',param); - if(uni.getStorageSync('userinfo').token){ - that.getVideoId().then(video=>{ - that.beansPay(video.data.id,param.serialNo); - }) - }else{ - intervalTime = setInterval(()=>{ - if(uni.getStorageSync('userinfo').token){ - clearInterval(intervalTime) - that.getVideoId().then(video=>{ - that.beansPay(video.data.id,param.serialNo); - }) - }else { - console.log('no users login')} - },100) - } - }, - getEncryptData(obj) { - const {code, serialNo } = obj; - let that = this; - // TODO: 此接口请求后台,返回下面的setCanPlaySerialList接口需要的加密参数 - const { srcAppid, dramaId } = this.pm.getInfo() + }) + // 设置右侧固定运营位置跳转路径 + pm.setActivityInfo({ + url: '' + }) + // 设置运营区域 + pm.updateOpenArea({ + showLeft: false, + showRight: false, + leftsideAreaList: [{ + left: 16, // 类似绝对定位的样式 + top: 20, + width: 72, + height: 32 + }, ], + ext: 'extInfo', + }) + }, + _initShare() { + const pm = this.pm + // 关于分享的处理 + // 开启分享以及withShareTicket + pm.setDramaFlag({ + share: true, + withShareTicket: true + }) + // 获取分享参数,页面栈只有短剧播放器一个页面的时候可获取到此参数 + // 例如从分享卡片进入、从投流广告直接跳转到播放器页面,从二维码直接进入播放器页面等情况 + playletPlugin.getShareParams().then(res => { + console.log('getLaunch options query res', res) + // 关于extParam的处理,需要先做decodeURIComponent之后才能得到原值 + const extParam = decodeURIComponent(res.extParam) + console.log('getLaunch options extParam', extParam) + // 如果设置了withShareTicket为true,可通过文档的方法获取更多信息 + // https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html + const enterOptions = wx.getEnterOptionsSync() + console.log('getLaunch options shareTicket', enterOptions.shareTicket) + }).catch(err => { + console.log('getLaunch options query err', err) + }) + this.getVideoId() + // 设置分享参数 + pm.setExtParam(JSON.stringify({ + vid: this.data.vid, + fxpid: this.data.userInfo.id, + invite: this.data.userInfo.invite || '' + })) + }, + // 检测是否可以播放 + onCheckIsCanPlay(param) { + var that = this; + let intervalTime = null; + serialNo = param.serialNo + console.log('onCheckIsCanPlay param', param); + if (uni.getStorageSync('userinfo').token) { + that.getVideoId().then(video => { + that.beansPay(video.data.id, param.serialNo); + }) + } else { + intervalTime = setInterval(() => { + if (uni.getStorageSync('userinfo').token) { + clearInterval(intervalTime) + that.getVideoId().then(video => { + that.beansPay(video.data.id, param.serialNo); + }) + } else { + console.log('no users login') + } + }, 100) + } + }, + getEncryptData(obj) { + const { + code, + serialNo + } = obj; + let that = this; + // TODO: 此接口请求后台,返回下面的setCanPlaySerialList接口需要的加密参数 + const { + srcAppid, + dramaId + } = this.pm.getInfo() - console.log('getEncryptData start', srcAppid, dramaId, serialNo) - return new Promise((resolve, reject) => { - // 获取免费剧集列表(包含用户已经支付的 ) - wx.login({ - success(res) { - // console.log('code',res.code) - httpRequest({ - url:"/api/video/videoInfoWechatV1", - method:"GET", - data:{ - code:res.code, - vid:that.data.vid, - oid:that.data.pay_oid - } - }).then(res=>{ - console.log('videoPlayer getCanPlayList res', res) - resolve({ - data:res.data.data, - encryptedData: res.data.enData - }) - }).catch(err=>{ - reject(err) - console.log(err) - }) - } - }) - }) - }, - pageBack(){ - let that = this; - if(that.data.is_record==1){ - // that.pm.navigateBack() - that.pm.switchTab({ - url: '/pages/tabs/home' - }) - }else{ - uni.showModal({ - title:"提示", - content:"是否将此剧加入追剧列表", - success(modelRes){ - if(modelRes.confirm){ - console.log('success'); - that.changeStar(); - } - that.pm.switchTab({ - url: '/pages/tabs/home' - }) - } - }) - } + console.log('getEncryptData start', srcAppid, dramaId, serialNo) + return new Promise((resolve, reject) => { + // 获取免费剧集列表(包含用户已经支付的 ) + wx.login({ + success(res) { + // console.log('code',res.code) + httpRequest({ + url: "/api/video/videoInfoWechatV1", + method: "GET", + data: { + code: res.code, + vid: that.data.vid, + oid: that.data.pay_oid + } + }).then(res => { + console.log('videoPlayer getCanPlayList res', res) + resolve({ + data: res.data.data, + encryptedData: res.data.enData + }) + }).catch(err => { + reject(err) + console.log(err) + }) + } + }) + }) + }, + pageBack() { + let that = this; + if (that.data.is_record == 1) { + // that.pm.navigateBack() + that.pm.switchTab({ + url: '/pages/tabs/home' + }) + } else { + uni.showModal({ + title: "提示", + content: "是否将此剧加入追剧列表", + success(modelRes) { + if (modelRes.confirm) { + console.log('success'); + that.changeStar(); + } + that.pm.switchTab({ + url: '/pages/tabs/home' + }) + } + }) + } - }, - getVideoId(){ - let that = this; - let infos = this.pm.getInfo(); - console.log('getVideoId start',infos); - // 获取当前需支付剧集ID(媒资库的ID不能用,需要用我们自己的剧集ID) - return new Promise((resolve, reject) => { - httpRequest({ - url:"/api/video/dramaIdToVideoId", - method:"GET", - data:{ - drama_id:infos.dramaId, - no:infos.serialNo - } - }).then(res=>{ - this.data.mid = res.data.id; - if(res.data.drama_vid != that.data.vid){ - that.data.vid = res.data.drama_vid - } - this.data.is_record = res.data.is_record - resolve(res) - }).catch(err=>{ - console.log(err) - reject(err) - }) - }) - }, + }, + getVideoId() { + let that = this; + let infos = this.pm.getInfo(); + console.log('getVideoId start', infos); + // 获取当前需支付剧集ID(媒资库的ID不能用,需要用我们自己的剧集ID) + return new Promise((resolve, reject) => { + httpRequest({ + url: "/api/video/dramaIdToVideoId", + method: "GET", + data: { + drama_id: infos.dramaId, + no: infos.serialNo + } + }).then(res => { + this.data.mid = res.data.id; + if (res.data.drama_vid != that.data.vid) { + that.data.vid = res.data.drama_vid + } + this.data.is_record = res.data.is_record + resolve(res) + }).catch(err => { + console.log(err) + reject(err) + }) + }) + }, - // 金豆购买剧集 - beansPay(mid,serialNo){ - let buyData = uni.getStorageSync("buydata"); - let that = this; - console.log('beansPay begin',mid,serialNo) - let upData={ - sum:1, - buytype:"金豆", - pricebuy:buyData.isvip ==2?buyData.vippriceq:buyData.priceq, - token:uni.getStorageSync("userinfo").token, - uid:uni.getStorageSync("userinfo").id, - ad_code:uni.getStorageSync('get_ad_code'), - lx:2,//1 全章购买 2单集购买 - smid:mid,//单集ID - wxlx:'wxxcx', - id:that.data.vid ,//剧ID - openid: uni.getStorageSync("openid") - } - // 支付 - PAY.pays.beansPay(upData).then((res)=>{ - console.log('beansPay res',res) - that.getEncryptData({serialNo: serialNo}).then(enRes => { - that.pm.isCanPlay({ - data: enRes.encryptedData, - serialNo: serialNo, - status:res.code ==1?1:2 - }) - }) - }).catch(err=>{ - if(err.msg =='金豆不足'){ - that.getEncryptData({serialNo: serialNo}).then(enRes => { - that.pm.isCanPlay({ - data: enRes.encryptedData, - serialNo: serialNo, - status:2 - }) - }) - } - console.log('jinDouPay fail',err) - }) + // 金豆购买剧集 + beansPay(mid, serialNo) { + let buyData = uni.getStorageSync("buydata"); + let that = this; + console.log('beansPay begin', mid, serialNo) + let upData = { + sum: 1, + buytype: "金豆", + pricebuy: buyData.isvip == 2 ? buyData.vippriceq : buyData.priceq, + token: uni.getStorageSync("userinfo").token, + uid: uni.getStorageSync("userinfo").id, + ad_code: uni.getStorageSync('get_ad_code'), + lx: 2, //1 全章购买 2单集购买 + smid: mid, //单集ID + wxlx: 'wxxcx', + id: that.data.vid, //剧ID + openid: uni.getStorageSync("openid") + } + // 支付 + PAY.pays.beansPay(upData).then((res) => { + console.log('beansPay res', res) + that.getEncryptData({ + serialNo: serialNo + }).then(enRes => { + that.pm.isCanPlay({ + data: enRes.encryptedData, + serialNo: serialNo, + status: res.code == 1 ? 1 : 2 + }) + }) + }).catch(err => { + if (err.msg == '金豆不足') { + that.getEncryptData({ + serialNo: serialNo + }).then(enRes => { + that.pm.isCanPlay({ + data: enRes.encryptedData, + serialNo: serialNo, + status: 2 + }) + }) + } + console.log('jinDouPay fail', err) + }) + }, + // 更新喜欢状态 + userLikeChange() { + let that = this; + that.getVideoId({ + dramaId: that.data.info.dramaId, + serialNo: that.data.info.serialNo + }).then(res => { + httpRequest({ + url: "/api/user/tapLove", + method: "GET", + data: { + vid: that.data.vid, + mid: res.data.id + } + }).then(res => { + console.log('userLikeChange res', res) + }) + }) + }, + // 更新追剧状态 + changeStar() { + let that = this; + let subData = { + vid: that.data.vid, + token: uni.getStorageSync("userinfo").token, + uid: uni.getStorageSync("userinfo").id, + mid: "" + } + that.getVideoId({ + dramaId: that.data.info.dramaId, + serialNo: that.data.info.serialNo + }).then(res => { - }, - // 更新喜欢状态 - userLikeChange(){ - let that = this; - that.getVideoId({dramaId:that.data.info.dramaId,serialNo:that.data.info.serialNo}).then(res=>{ - httpRequest({ - url:"/api/user/tapLove", - method:"GET", - data:{ - vid:that.data.vid, - mid:res.data.id - } - }).then(res=>{ - console.log('userLikeChange res',res) - }) - }) - }, - // 更新追剧状态 - changeStar(){ - let that = this; - let subData = { - vid:that.data.vid, - token:uni.getStorageSync("userinfo").token, - uid:uni.getStorageSync("userinfo").id, - mid:"" - } - that.getVideoId({dramaId:that.data.info.dramaId,serialNo:that.data.info.serialNo}).then(res=>{ + httpRequest({ + url: "/api/user/videorecord", + method: "GET", + data: { + vid: that.data.vid, + mid: res.data.id + } + }).then(rest => { + console.log('userLikeChange res', rest) + }).catch(errs => { + console.log(errs) + }) - httpRequest({ - url:"/api/user/videorecord", - method:"GET", - data:{ - vid:that.data.vid, - mid:res.data.id - } - }).then(rest=>{ - console.log('userLikeChange res',rest) - }).catch(errs=>{ - console.log(errs) - }) + }) + }, + // 更新播放记录 + changePlayLog() { + let that = this; + that.getVideoId({ + dramaId: that.data.info.dramaId, + serialNo: that.data.info.serialNo + }).then(res => { + console.log('changePlayLog mid', res) + httpRequest({ + url: "/api/video/bfjl", + method: "GET", + data: { + vid: that.data.vid, + mid: res.data.id + } + }).then(rest => { + console.log('changePlayLog res', rest) + }).catch(errs => { + console.log('change PlayLog fail', errs) + }) + }) + }, - }) - }, - // 更新播放记录 - changePlayLog(){ - let that = this; - that.getVideoId({dramaId:that.data.info.dramaId,serialNo:that.data.info.serialNo}).then(res=>{ - console.log('changePlayLog mid',res) - httpRequest({ - url:"/api/video/bfjl", - method:"GET", - data:{ - vid:that.data.vid, - mid:res.data.id - } - }).then(rest=>{ - console.log('changePlayLog res',rest) - }).catch(errs=>{ - console.log('change PlayLog fail',errs) - }) - }) - }, - // 支付完 - chargeEnd(payRes){ - let that = this; - console.log("paySuccess",payRes) - let share_g_order_vid = uni.getStorageSync('g_order_vid'); - if(payRes.status == "paySuccess"){ - that.data.pay_oid = payRes.oid; - this.onCheckIsCanPlay({dramaId:that.data.info.dramaId,serialNo:payRes.serialNo,oid:payRes.oid }) - that.pm.setExtParam(JSON.stringify({ - vid:this.data.vid, - fxpid:this.data.userInfo.id, - invite:this.data.userInfo.invite||'', - g_order_id:payRes.gOrderId, - g_order_vid:payRes.vid + adEnd(mid) { + let buyData = uni.getStorageSync("buydata"); + let that = this; + let upData = { + sum: 1, + buytype: 'adUnlock' + pricebuy: buyData.isvip == 2 ? buyData.vippriceq : buyData.priceq, + token: uni.getStorageSync("userinfo").token, + uid: uni.getStorageSync("userinfo").id, + ad_code: uni.getStorageSync('get_ad_code'), + lx: 2, //1 全章购买 2单集购买 + smid: mid, //单集ID + wxlx: 'wxxcx', + id: that.data.vid, //剧ID + openid: uni.getStorageSync("openid") + } + // 支付 + PAY.pays.beansPay(upData).then((res) => { + console.log('beansPay res', res) + that.getEncryptData({ + serialNo: serialNo.serialNo + }).then(enRes => { + that.pm.isCanPlay({ + data: enRes.encryptedData, + serialNo: serialNo.serialNo, + status: res.code == 1 ? 1 : 2 + }) + }) + }).catch(err => { + if (err.msg == '金豆不足') { + that.getEncryptData({ + serialNo: serialNo.serialNo + }).then(enRes => { + that.pm.isCanPlay({ + data: enRes.encryptedData, + serialNo: serialNo.serialNo, + status: 2 + }) + }) + } + console.log('jinDouPay fail', err) + }) + }, - })) - that.pm.hideChargeDialog(); - if(payRes.gOrderId && share_g_order_vid != payRes.vid){ - that.pm.updateOpenArea({showLeft: true}); - } + // 支付完 + chargeEnd(payRes) { + let that = this; + console.log("paySuccess", payRes) + let share_g_order_vid = uni.getStorageSync('g_order_vid'); + if (payRes.status == "paySuccess") { + that.data.pay_oid = payRes.oid; + this.onCheckIsCanPlay({ + dramaId: that.data.info.dramaId, + serialNo: payRes.serialNo, + oid: payRes.oid + }) + that.pm.setExtParam(JSON.stringify({ + vid: this.data.vid, + fxpid: this.data.userInfo.id, + invite: this.data.userInfo.invite || '', + g_order_id: payRes.gOrderId, + g_order_vid: payRes.vid - } - }, + })) + that.pm.hideChargeDialog(); + if (payRes.gOrderId && share_g_order_vid != payRes.vid) { + that.pm.updateOpenArea({ + showLeft: true + }); + } + + } + }, } function PlayerManager() { - var newProto = Object.assign({}, proto) - for (const k in newProto) { - if (typeof newProto[k] === 'function') { - this[k] = newProto[k].bind(this) - } else if (typeof newProto[k] === 'object') { - if (!newProto[k]) { - this[k] = newProto[k] - } else { - this[k] = deepClone(newProto[k]) - } - } - } + var newProto = Object.assign({}, proto) + for (const k in newProto) { + if (typeof newProto[k] === 'function') { + this[k] = newProto[k].bind(this) + } else if (typeof newProto[k] === 'object') { + if (!newProto[k]) { + this[k] = newProto[k] + } else { + this[k] = deepClone(newProto[k]) + } + } + } } PlayerManager.navigateToPlayer = navigateToPlayer -module.exports = PlayerManager +module.exports = PlayerManager \ No newline at end of file