Ver código fonte

视频收藏,视频点赞

lizhen_gitee 9 meses atrás
pai
commit
5c61c67071
1 arquivos alterados com 140 adições e 0 exclusões
  1. 140 0
      application/api/controller/Tvindex.php

+ 140 - 0
application/api/controller/Tvindex.php

@@ -254,4 +254,144 @@ class Tvindex extends Api
         $this->success('视频', $list);
     }
 
+    //视频收藏/取消收藏
+    public function video_collection() {
+
+        $id = input('id', 0, 'intval');
+        if (!$id) {
+            $this->error('您的网络开小差了');
+        }
+
+        $info = Db::name('video')->where(['id' => $id])->find();
+        if (!$info) {
+            $this->error('数据不存在');
+        }
+        $info['image'] = one_domain_image($info['image']);
+        //查询是否收藏
+        $count = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
+        //开启事务
+        if ($count) {
+            $result = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
+            Db::name('video')->where('id',$id)->setDec('collect_number',1); //收藏数减少
+        } else {
+            $result = Db::name('video_collection')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
+            Db::name('video')->where('id',$id)->setInc('collect_number',1); //收藏数增加
+        }
+        if (!$result) {
+            Db::rollback();
+            $this->error('操作失败');
+        }
+
+        $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyCollectionRecord';
+        $content = [
+            'cpPrvdName' => '健康e家',
+            'cpPrvCode' => '41000144',
+            'cpPrvType' => '1006',
+            'content' => $info['title'],
+            'ChnCode' => '1000020',
+            'contentId' => (string)$info['movieid'],
+            'extraContentID' => '',
+            'isEffective' => $info['status'],
+            'isPaid' => $info['is_pay'],
+            'collectionFlag' => $count ? 0 : 1,
+            'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
+            'cpPermission' => 'GITV',
+            'intent' => [
+                'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
+                'package' => 'com.huxiu.heh.tv',
+                'component' => [
+                    'pkg' => 'com.huxiu.heh.tv',
+                    'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
+                ],
+                'extras' => [
+                    /*'cmd' => '',
+                    'from' => '',
+                    'media_id' => ''*/
+                    'type_id' => $info['video_type_id'],
+                    'id' => $info['id']
+                ]
+            ],
+            'imageURL' => $info['image']
+        ];
+
+        $content = json_encode($content, 320);
+
+        $rt = httpRequest($url, 'POST', $content);
+        file_put_contents('shoucang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
+        if (!$rt) {
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $rt = json_decode($rt, true);
+        if (empty($rs) || $rt['code'] != 0) {
+            Db::rollback();
+            $this->error('操作失败');
+        }
+
+        //大数据上报
+        $data = [
+            'favid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
+            'UserID' => $this->auth->mobile,
+            'time' => date('Y-m-d H:i:s'),
+            'type' => $count ? 0 : 1,
+            'cpid' => config('data_cp_id'),
+            'albumid' => $id,
+            'albumname' => $info['title']
+        ];
+
+        $data = join(json_decode('"\u0001"', true), $data);
+        $filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.dat';
+        $check_filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.chk';
+
+        error_log(print_r($data, 1) . PHP_EOL, 3, './dashuju/' . $filename);
+        error_log('', 3, './dashuju/' . $check_filename);
+        $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userfavdata.finish';
+        error_log('', 3, './dashuju/' . $finish_filename);
+
+        Db::commit();
+        $this->success('操作成功');
+    }
+
+    //点赞视频、取消点赞
+    public function video_good() {
+
+        $id = input('id', 0, 'intval');
+        if (!$id) {
+            $this->error('您的网络开小差了');
+        }
+
+        $info = Db::name('video')->where(['id' => $id])->find();
+        if (!$info) {
+            $this->error('数据不存在');
+        }
+        //查询是否收藏
+        $check = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->find();
+        //开启事务
+        if ($check) {
+            $result = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
+            Db::name('video')->where('id',$id)->setDec('good_number',1); //点赞数减少
+        } else {
+            $result = Db::name('video_good')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
+            Db::name('video')->where('id',$id)->setInc('good_number',1); //点赞数增加
+        }
+
+        $this->success('操作成功');
+    }
+
+
+
+    /** * * @param string $string 需要加密的字符串 * @param string $key 密钥 * @return string */
+    private function encrypt($string, $key) {
+//        $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
+        $data = openssl_encrypt($string, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
+        $data = bin2hex($data);
+        return $data;
+    }
+
+    /** * @param string $string 需要解密的字符串 * @param string $key 密钥 * @return string */
+    private function decrypt($string, $key) {
+//        $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
+        $decrypted = openssl_decrypt(hex2bin($string), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
+        return $decrypted;
+    }
 }