diy_video.js 1.58 KB
Component({
  properties: {
    object: {
      type: Object,
      value: null
    },
    // 这里定义了innerText属性,属性值可以在组件使用时指定

  },
  data: {
    // 这里是一些组件内部数据
    someData: {},
    videoUrl: "",
  },

  ready: function () {
    this.create_url();
  },
  methods: {
    // 这里是一个自定义方法
    create_url: function () {
      console.log('create_url');
      var that = this;
      /*获取文本框中的值*/
      var text = this.properties.object.wxapp_code;
      /*console.log("整个的地址"+text);*/
      var arr = new Array(), arrs = new Array();
      arr = text.split('vid=');
      /*console.log("截取vid后面的"+arr[1]);*/
      arrs = arr[1].split('"');
      /*	console.log("截取&前面的的"+arrs[0]);*/
      var vipid = arrs[0];

      var url = "https://vv.video.qq.com/getinfo?vid=" + vipid + "&platform=101001&charge=0&otype=json";
      wx.request({
        url: url,
        success: function (res) {
          var dataJson = res.data.replace(/QZOutputJson=/, '') + "qwe";
          var dataJson1 = dataJson.replace(/;qwe/, '');
          var data = JSON.parse(dataJson1);
          if (data.vl != undefined) {
            var host = data['vl']['vi'][0]['ul']['ui'][2]['url']
            var fn = data.vl.vi[0].fn;
            var fvkey = data.vl.vi[0].fvkey;
            /* console.log("有参数吗"+fn+"有参数吗"+fvkey);*/
            var wxapp_url = host + fn + '?vkey=' + fvkey;
            that.setData({
              videoUrl: wxapp_url
            });
          }
        }
      })

    }
  }
})