Tvindex.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use Redis;
  6. class Tvindex extends Api
  7. {
  8. protected $noNeedLogin = ['indexdata','video_list','videoinfo','image_childcate','image_list','videoinfo_simple','zhuanti','tudingc','search','history','app_error'];
  9. protected $noNeedRight = '*';
  10. //首页
  11. public function indexdata(){
  12. //背景图
  13. $data['index_bg_image'] = localpath_to_netpath(config('site.index_bg_image'));
  14. //左上角 logo,名称,4个按钮,账号
  15. $data['index_logo'] = localpath_to_netpath(config('site.index_logo'));
  16. $data['index_appname'] = config('site.index_appname');
  17. $data['index_tuiding_switch'] = config('site.index_tuiding_switch');
  18. $data['index_search_switch'] = config('site.index_search_switch');
  19. $data['index_history_switch'] = config('site.index_history_switch');
  20. $data['index_shoucang_switch'] = config('site.index_shoucang_switch');
  21. $data['index_dinggou_switch'] = config('site.index_dinggou_switch');
  22. $data['index_account_switch'] = config('site.index_account_switch');
  23. //右上角 三行
  24. $data['index_right_1'] = config('site.index_right_1');
  25. $data['index_right_2'] = config('site.index_right_2');
  26. $data['index_right_3'] = config('site.index_right_3');
  27. $data['index_right_4'] = config('site.index_right_4');
  28. //主视频
  29. $index_top_video_id = config('site.index_top_video_id');
  30. $index_top_video = Db::name('video')->field('id,image,programid,movieid')->where('id',$index_top_video_id)->where('inject_status',2)->find();
  31. if(!empty($index_top_video)){
  32. $index_top_video['image'] = localpath_to_netpath($index_top_video['image']);
  33. }
  34. $data['index_top_video'] = $index_top_video;
  35. //问诊四个
  36. $page_wenzhen = Db::name('page_wenzhen')->field('id,name,image,url')->where('status',1)->order('weigh asc')->select();
  37. $data['page_wenzhen'] = list_domain_image($page_wenzhen,['image']);
  38. //大分类+剧集
  39. $video_cate = Db::name('video_cate')->field('id,name,showtype,is_zhuanti')->where('status',1)->order('weigh asc, id desc')->select();
  40. $video_childcate = Db::name('video_childcate')->field('id, cate_id, name, image, bg_image')->where('status',1)->order('weigh asc, id desc')->select();
  41. $video_childcate = list_domain_image($video_childcate, ['image','bg_image']);
  42. //子分类数量
  43. $video_count = Db::name('video')->field('childcate_id,count(id)')->group('childcate_id')->where('childcate_id','neq','0')->where('status',1)->where('inject_status',2)->column('childcate_id,count(id)');
  44. foreach($video_childcate as $key => $val){
  45. $video_childcate[$key]['video_number'] = isset($video_count[$val['id']]) ? $video_count[$val['id']] : 0;
  46. }
  47. //分布:1=左一右四,2=两行八个,3=一行四个,4=一行三个
  48. foreach($video_cate as $key => $cate){
  49. $cate['child'] = [];
  50. //循环放入child
  51. $child = [];
  52. foreach($video_childcate as $k => $v){
  53. if($cate['id'] == $v['cate_id']){
  54. $child[] = $v;
  55. }
  56. }
  57. $cate['child'] = $child;
  58. $video_cate[$key] = $cate;
  59. }
  60. $data['video_cate'] = $video_cate;
  61. //图片大分类+子类
  62. $image_cate = Db::name('image_cate')->field('id,name,image')->where('status',1)->order('weigh asc, id desc')->select();
  63. $image_cate = list_domain_image($image_cate, ['image']);
  64. $data['image_cate'] = $image_cate;
  65. $this->success('首页',$data);
  66. }
  67. //更多页,应该是没用了
  68. //视频列表
  69. /*public function video_list() {
  70. $type_id = input('type_id', 0, 'intval'); //分类id
  71. if (!$type_id) {
  72. $this->error('您的网络开小差了~');
  73. }
  74. $video_type = Db::name('video_type')->where('id',$type_id)->value('name');
  75. $list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $type_id, 'status' => 1, 'inject_status' => 2])
  76. ->order('weigh asc, id desc')->select();
  77. $list = list_domain_image($list, ['image']);
  78. $result = [
  79. 'typename' => $video_type,
  80. 'videolist' => $list,
  81. ];
  82. $this->success('视频更多', $result);
  83. }*/
  84. //视频详情
  85. public function videoinfo() {
  86. $id = input('id', 0, 'intval'); //视频id
  87. $childcate_id = input('child_id',0,'intval'); //子分类id
  88. if (!$id && !$childcate_id) {
  89. $this->error('您的网络开小差了');
  90. }
  91. if($id){
  92. $info = Db::name('video')->field('id,video_type_id,childcate_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
  93. ->where(['id' => $id])->find();
  94. }else{
  95. $info = Db::name('video')->field('id,video_type_id,childcate_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
  96. ->where(['childcate_id' => $childcate_id])->where(['status'=>1,'inject_status'=>2])->order('weigh asc,id desc')->find();
  97. }
  98. if (!$info && !empty($childcate_id)) {
  99. $this->success(1,'{}');
  100. }
  101. if (!$info) {
  102. $this->error('不存在的视频');
  103. }
  104. if ($info['status'] != 1) {
  105. $this->error('视频丢失');
  106. }
  107. if ($info['inject_status'] != 2) {
  108. $this->error('视频丢失');
  109. }
  110. $info['image'] = one_domain_image($info['image']);
  111. $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $info['id']])->count('id');
  112. $info['is_good'] = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $info['id']])->count('id');
  113. //剧集列表
  114. $juji = [];
  115. $video_list = Db::name('video')->field('id, title, image, is_pay')->where(['childcate_id' => $info['childcate_id'], 'status' => 1, 'inject_status' => 2])
  116. ->order('weigh asc, id desc')->select();
  117. if(!empty($video_list)){
  118. $video_list = list_domain_image($video_list, ['image']);
  119. $video_list = array_chunk($video_list,10);
  120. foreach($video_list as $page => $ten){
  121. $juji[] = [
  122. 'name'=> ($page*10 + 1) .'-'. ($page*10 + count($ten)),
  123. 'list'=>$ten,
  124. ];
  125. }
  126. }
  127. //猜你喜欢
  128. $juji_ids = array_column($juji,'id');
  129. $guess_list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->where('id','NOTIN',$juji_ids)
  130. ->orderRaw('rand()')->limit(6)->select();
  131. $guess_list = list_domain_image($guess_list, ['image']);
  132. //记录浏览历史,给浏览历史列表用的,即时的
  133. if($this->auth->isLogin()){
  134. $view_map = [
  135. 'user_id' => $this->auth->id,
  136. 'video_id' => $info['id'],
  137. ];
  138. $check_view = Db::name('video_view')->where($view_map)->find();
  139. if($check_view){
  140. Db::name('video_view')->where($view_map)->update(['updatetime'=>time()]);
  141. }else{
  142. $view_map['createtime'] = time();
  143. $view_map['updatetime'] = time();
  144. Db::name('video_view')->insertGetId($view_map);
  145. }
  146. }
  147. //记录pv,uv
  148. $this->video_pvuv($info['id']);
  149. //
  150. $result = [
  151. 'video_info' => $info,
  152. 'juji_list' => $juji,
  153. 'guess_list' => $guess_list,
  154. ];
  155. $this->success('详情', $result);
  156. }
  157. public function videoinfo_simple() {
  158. $id = input('id', 0, 'intval'); //视频id
  159. if (!$id) {
  160. $this->error('您的网络开小差了');
  161. }
  162. $info = Db::name('video')->field('id,video_type_id,childcate_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
  163. ->where(['id' => $id])->find();
  164. if (!$info) {
  165. $this->error('数据不存在');
  166. }
  167. if ($info['status'] != 1) {
  168. $this->error('视频丢失');
  169. }
  170. if ($info['inject_status'] != 2) {
  171. $this->error('视频丢失');
  172. }
  173. $info['image'] = one_domain_image($info['image']);
  174. $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $info['id']])->count('id');
  175. $info['is_good'] = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $info['id']])->count('id');
  176. //记录浏览历史,给浏览历史列表用的,即时的
  177. if($this->auth->isLogin()){
  178. $view_map = [
  179. 'user_id' => $this->auth->id,
  180. 'video_id' => $info['id'],
  181. ];
  182. $check_view = Db::name('video_view')->where($view_map)->find();
  183. if($check_view){
  184. Db::name('video_view')->where($view_map)->update(['updatetime'=>time()]);
  185. }else{
  186. $view_map['createtime'] = time();
  187. $view_map['updatetime'] = time();
  188. Db::name('video_view')->insertGetId($view_map);
  189. }
  190. }
  191. //记录pv,uv
  192. $this->video_pvuv($info['id']);
  193. //
  194. $result = [
  195. 'video_info' => $info,
  196. ];
  197. $this->success('详情', $result);
  198. }
  199. //专题页
  200. public function zhuanti(){
  201. $childcate_id = input('child_id', 0, 'intval'); //子分类id
  202. if (!$childcate_id) {
  203. $this->error('您的网络开小差了~');
  204. }
  205. $video_childcate = Db::name('video_childcate')->field('id,name,bg_image')->where('id',$childcate_id)->find();
  206. $video_childcate = info_domain_image($video_childcate,['bg_image']);
  207. $list = Db::name('video')->field('id, title, image, is_pay, status, inject_status, seriesid, programid, movieid')->where(['childcate_id' => $childcate_id, 'status' => 1, 'inject_status' => 2])->order('weigh asc, id desc')->limit(5)->select();
  208. $list = list_domain_image($list, ['image']);
  209. $result = [
  210. 'info' => $video_childcate,
  211. 'list' => $list,
  212. ];
  213. $this->success('视频', $result);
  214. }
  215. //退订服务
  216. public function tudingc()
  217. {
  218. $data = config('site.text_tuiding');
  219. $this->success('', $data);
  220. }
  221. //搜索页
  222. public function search(){
  223. $keyword = input('keyword','');
  224. //热门推荐4个
  225. if(empty($keyword)){
  226. $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])
  227. ->orderRaw('rand()')->limit(12)->select();
  228. $list = list_domain_image($list, ['image']);
  229. }else{
  230. $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->where('search_title','LIKE','%'.$keyword.'%')->order('is_pay asc,weigh asc,id desc')->select();
  231. $list = list_domain_image($list, ['image']);
  232. }
  233. $this->success('视频', $list);
  234. }
  235. //浏览历史
  236. public function history(){
  237. if($this->auth->isLogin()){
  238. $video_view = Db::name('video_view')->where('user_id',$this->auth->id)->order('updatetime desc')->group('video_id')->column('video_id,updatetime');
  239. if(!empty($video_view)){
  240. $video_ids = implode(',',array_keys($video_view));
  241. $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->where('id','IN',$video_ids)->orderRaw('field(id,'.$video_ids.')')->page($this->page,$this->pagenum)->select();
  242. $list = list_domain_image($list, ['image']);
  243. foreach($list as $key => $val){
  244. $list[$key]['history_time'] = $video_view[$val['id']];
  245. }
  246. }else{
  247. $list = [];
  248. }
  249. }else{
  250. $list = [];
  251. }
  252. $this->success('视频', $list);
  253. }
  254. //视频收藏列表
  255. public function shoucang_list(){
  256. if($this->auth->isLogin()){
  257. $video_view = Db::name('video_collection')->where('user_id',$this->auth->id)->order('createtime desc')->group('video_id')->column('video_id,createtime');
  258. if(!empty($video_view)){
  259. $video_ids = implode(',',array_keys($video_view));
  260. $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->where('id','IN',$video_ids)->orderRaw('field(id,'.$video_ids.')')->page($this->page,$this->pagenum)->select();
  261. $list = list_domain_image($list, ['image']);
  262. foreach($list as $key => $val){
  263. $list[$key]['shoucang_time'] = $video_view[$val['id']];
  264. }
  265. }else{
  266. $list = [];
  267. }
  268. }else{
  269. $list = [];
  270. }
  271. $this->success('视频', $list);
  272. }
  273. //视频收藏/取消收藏
  274. public function video_collection() {
  275. $id = input('id', 0, 'intval');
  276. if (!$id) {
  277. $this->error('您的网络开小差了');
  278. }
  279. $info = Db::name('video')->where(['id' => $id])->find();
  280. if (!$info) {
  281. $this->error('数据不存在');
  282. }
  283. //var_dump($info);exit;
  284. $info['image'] = one_domain_image($info['image']);
  285. //查询是否收藏
  286. $count = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  287. //开启事务
  288. if ($count) {
  289. $result = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
  290. Db::name('video')->where('id',$id)->setDec('collect_number',1); //收藏数减少
  291. } else {
  292. $result = Db::name('video_collection')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
  293. Db::name('video')->where('id',$id)->setInc('collect_number',1); //收藏数增加
  294. }
  295. if (!$result) {
  296. /*Db::rollback();
  297. $this->error('操作失败');*/
  298. $this->success('操作成功');
  299. }
  300. $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyCollectionRecord';
  301. $content = [
  302. 'cpPrvdName' => '健康e家',
  303. 'cpPrvCode' => '41000144',
  304. 'cpPrvType' => '1006',
  305. 'content' => $info['title'],
  306. 'ChnCode' => '1000020',
  307. 'contentId' => (string)$info['movieid'],
  308. 'extraContentID' => '',
  309. 'isEffective' => $info['status'],
  310. 'isPaid' => $info['is_pay'],
  311. 'collectionFlag' => $count ? 0 : 1,
  312. 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
  313. 'cpPermission' => 'GITV',
  314. 'intent' => [
  315. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  316. 'package' => 'com.huxiu.heh.tv',
  317. 'component' => [
  318. 'pkg' => 'com.huxiu.heh.tv',
  319. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  320. ],
  321. 'extras' => [
  322. /*'cmd' => '',
  323. 'from' => '',
  324. 'media_id' => ''*/
  325. 'type_id' => $info['video_type_id'],
  326. 'id' => $info['id']
  327. ]
  328. ],
  329. 'imageURL' => $info['image']
  330. ];
  331. $content = json_encode($content, 320);
  332. $rt = httpRequest($url, 'POST', $content);
  333. file_put_contents('shoucang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
  334. if (!$rt) {
  335. /*Db::rollback();
  336. $this->error('操作失败');*/
  337. $this->success('操作成功');
  338. }
  339. $rt = json_decode($rt, true);
  340. if (empty($rs) || $rt['code'] != 0) {
  341. /*Db::rollback();
  342. $this->error('操作失败');*/
  343. $this->success('操作成功');
  344. }
  345. //大数据上报
  346. $data = [
  347. 'favid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
  348. 'UserID' => $this->auth->mobile,
  349. 'time' => date('Y-m-d H:i:s'),
  350. 'type' => $count ? 0 : 1,
  351. 'cpid' => config('data_cp_id'),
  352. 'albumid' => $id,
  353. 'albumname' => $info['title']
  354. ];
  355. $data = join(json_decode('"\u0001"', true), $data);
  356. $filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.dat';
  357. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.chk';
  358. error_log(print_r($data, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  359. error_log('', 3, './dashuju/' . $check_filename);
  360. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userfavdata.finish';
  361. error_log('', 3, './dashuju/' . $finish_filename);
  362. Db::commit();
  363. $this->success('操作成功');
  364. }
  365. //点赞视频、取消点赞
  366. public function video_good() {
  367. $id = input('id', 0, 'intval');
  368. if (!$id) {
  369. $this->error('您的网络开小差了');
  370. }
  371. $info = Db::name('video')->where(['id' => $id])->find();
  372. if (!$info) {
  373. $this->error('数据不存在');
  374. }
  375. //查询是否收藏
  376. $check = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->find();
  377. //开启事务
  378. if ($check) {
  379. $result = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
  380. Db::name('video')->where('id',$id)->setDec('good_number',1); //点赞数减少
  381. } else {
  382. $result = Db::name('video_good')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
  383. Db::name('video')->where('id',$id)->setInc('good_number',1); //点赞数增加
  384. }
  385. $this->success('操作成功');
  386. }
  387. //用户观看行为(支付)
  388. public function payuserplay() {
  389. $id = input('id', 0, 'intval'); //视频id
  390. $sn = input('sn', '', 'trim'); //SN号
  391. $start_time = input('start_time', '', 'trim'); //yyyymmddhhmmss (24小时制),节目开始播放时间
  392. $end_time = input('end_time', '', 'trim'); //yyyymmddhhmmss (24小时制),节目结束播放时间,如果播放未结束,但是此时需要同步数据,填当前时间
  393. $csource = input('csource', 0, ''); //1:从搜索结果访问2:从用户收藏/书签访问3:从EPG访问4:从推荐页面访问5、其他
  394. if (!$id) {
  395. $this->error('您的网络开小差了');
  396. }
  397. $info = Db::name('video')->where(['id' => $id])->find();
  398. if (!$info) {
  399. $this->error('数据不存在');
  400. }
  401. //播放日志
  402. $play_data = [
  403. 'user_id' => $this->auth->id,
  404. 'video_id' => $id,
  405. 'sn' => $sn,
  406. 'start_time' => $start_time,
  407. 'end_time' => $end_time,
  408. 'csource' => $csource,
  409. 'createtime' => time(),
  410. 'updatetime' => time(),
  411. ];
  412. Db::name('video_play_payuserplay')->insertGetId($play_data);
  413. $content = [
  414. 'UserID' => $this->auth->mobile,
  415. 'city' => '14',
  416. 'start_time' => $start_time,
  417. 'end_time' => $end_time,
  418. 'service_type' => 1,
  419. 'albumid' => $id,
  420. 'albumname' => $info['title'],
  421. 'csource' => $csource,
  422. 'SN' => $sn,
  423. 'ip' => request()->ip(),
  424. 'fee_type' => $info['is_pay'] == 1 ? 1 : '',
  425. 'flow' => '',
  426. 'product' => '',
  427. 'product_name' => '',
  428. 'info_source' => '02'
  429. ];
  430. $content = join('|', $content);
  431. $filename = date('YmdH').'_'.config('cp_id').'_userviewdata_1.dat';
  432. $check_filename = date('YmdH').'_'.config('cp_id').'_userviewdata_1.chk';
  433. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  434. error_log('', 3, './dashuju/' . $check_filename);
  435. $this->success('');
  436. }
  437. //视频播放记录
  438. public function playrecord() {
  439. $id = input('id', 0, 'intval');
  440. $total_time = input('total_time', 0, 'intval'); //总时长
  441. $start_time = input('start_time', 0, 'intval'); //开始看时间:相对时间
  442. $end_time = input('end_time', 0, 'intval'); //结束看时间:相对时间
  443. $log_type = input('log_type', 'watching', 'trim'); //begin:开始播放;watching:正在播放;end:结束播放
  444. if (!$id) {
  445. $this->error('您的网络开小差了');
  446. }
  447. $info = Db::name('video')->where(['id' => $id])->find();
  448. if (!$info) {
  449. $this->error('数据不存在');
  450. }
  451. if ($info['inject_status'] != 2) {
  452. $this->error('视频丢失');
  453. }
  454. //播放日志
  455. $play_data = [
  456. 'user_id' => $this->auth->id,
  457. 'video_id' => $id,
  458. 'total_time' => $total_time,
  459. 'start_time' => $start_time,
  460. 'end_time' => $end_time,
  461. 'log_type' => $log_type,
  462. 'createtime' => time(),
  463. 'updatetime' => time(),
  464. ];
  465. Db::name('video_play_playrecord')->insertGetId($play_data);
  466. $info['image'] = one_domain_image($info['image']);
  467. $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyHistoryRecord';
  468. $content = [
  469. 'cpPrvdName' => '健康e家',
  470. 'cpPrvCode' => '41000144',
  471. 'cpPrvType' => '1006',
  472. 'contentName' => $info['title'],
  473. 'ChnName' => '健康',
  474. 'ChnCode' => '1000020',
  475. 'contentId' => (string)$info['movieid'],
  476. 'extraContentID' => '',
  477. 'isEffective' => $info['status'],
  478. 'isPaid' => $info['is_pay'],
  479. 'contentTotalTime' => $total_time,
  480. 'startWatchTime' => $start_time,
  481. 'endWatchTime' => $end_time,
  482. 'playTime' => $end_time - $start_time,
  483. 'logType' => $log_type,
  484. 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
  485. 'cpPermission' => 'GITV',
  486. 'intent' => [
  487. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  488. 'package' => 'com.huxiu.heh.tv',
  489. 'component' => [
  490. 'pkg' => 'com.huxiu.heh.tv',
  491. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  492. ],
  493. 'extras' => [
  494. /*'cmd' => '',
  495. 'from' => '',
  496. 'media_id' => ''*/
  497. 'type_id' => $info['video_type_id'],
  498. 'id' => $info['id']
  499. ]
  500. ],
  501. 'imageURL' => $info['image']
  502. ];
  503. $content = json_encode($content, 320);
  504. $rt = httpRequest($url, 'POST', $content);
  505. file_put_contents('bofang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
  506. if (!$rt) {
  507. //$this->error('同步失败');
  508. }
  509. $rt = json_decode($rt, true);
  510. if (isset($rt['code']) && $rt['code'] != 0) {
  511. //$this->error('同步失败');
  512. }
  513. $this->success('同步成功');
  514. }
  515. //用户观看行为(大数据)
  516. public function userplay() {
  517. $id = input('id', 0, 'intval'); //视频id
  518. $sn = input('sn', '', 'trim'); //SN号
  519. $start_time = input('start_time', '', 'trim'); //YYYY-MM-DD HH:MM:SS(24小时制)节目开始播放时间
  520. $end_time = input('end_time', '', 'trim'); //YYYY-MM-DD HH:MM:SS(24小时制)节目结束播放时间
  521. $csource = input('csource', 0, ''); //1:从搜索结果访问2:从用户收藏/书签访问3:从EPG访问4:从推荐页面访问5:从猜你喜欢个性化推荐页面访问(带上推荐接口的trace_id)99:其他
  522. $trace_id = input('trace_id', '', 'trim');
  523. $istry = input('istry', 0, 'intval'); //0非试看 1试看
  524. $start_posi = input('start_posi', 0, 'intval'); //播放起始点相对于影片起始点的时长,单位秒,例如从影片第 600 秒开始观看
  525. if (!$id) {
  526. $this->error('您的网络开小差了');
  527. }
  528. $info = Db::name('video')->where(['id' => $id])->find();
  529. if (!$info) {
  530. $this->error('数据不存在');
  531. }
  532. //播放日志
  533. $play_data = [
  534. 'user_id' => $this->auth->id,
  535. 'video_id' => $id,
  536. 'sn' => $sn,
  537. 'start_time' => $start_time,
  538. 'end_time' => $end_time,
  539. 'csource' => $csource,
  540. 'trace_id' => $trace_id,
  541. 'istry' => $istry,
  542. 'start_posi' => $start_posi,
  543. 'createtime' => time(),
  544. 'updatetime' => time(),
  545. ];
  546. Db::name('video_play_userplay')->insertGetId($play_data);
  547. $content = [
  548. 'playid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
  549. 'UserID' => $this->auth->mobile,
  550. 'SN' => $sn,
  551. 'start_time' => $start_time,
  552. 'end_time' => $end_time,
  553. 'service_type' => 1,
  554. 'cpid' => config('data_cp_id'),
  555. 'albumid' => $id,
  556. 'albumname' => $info['title'],
  557. 'videoid' => $id,
  558. 'videoname' => $info['title'],
  559. 'csource' => $csource,
  560. 'trace_id' => $trace_id,
  561. 'fee_type' => $info['is_pay'] == 1 ? 1 : 4,
  562. 'istry' => $istry,
  563. 'iscon' => 0,
  564. 'start_posi' => $start_posi
  565. ];
  566. $content = join(json_decode('"\u0001"', true), $content);
  567. $filename = date('Ymd').'_'.config('data_cp_id').'_userplaydata_1.dat';
  568. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userplaydata_1.chk';
  569. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  570. error_log('', 3, './dashuju/' . $check_filename);
  571. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userplaydata.finish';
  572. error_log('', 3, './dashuju/' . $finish_filename);
  573. $this->success('');
  574. }
  575. //获取特殊机型
  576. public function special_models() {
  577. $special_models = config('site.special_models');
  578. $special_models = explode(',', $special_models);
  579. $this->success('获取特殊机型', $special_models);
  580. }
  581. //前端报错记录
  582. public function app_error() {
  583. $this->success('');
  584. }
  585. //图片页
  586. public function image_childcate(){
  587. $cate_id = input('cate_id',0);
  588. $childcate = Db::name('image_childcate')->field('id,cate_id,name')->where('cate_id',$cate_id)->where('status',1)->order('weigh asc,id desc')->select();
  589. $image_list = [];
  590. if(!empty($childcate)){
  591. $childcate_id = $childcate[0]['id'];
  592. $image_list = Db::name('image')->field('id,title,image')->where('childcate_id',$childcate_id)->where('status',1)->order('weigh asc,id desc')->select();
  593. $image_list = list_domain_image($image_list,['image']);
  594. }
  595. $result = [
  596. 'childcate' => $childcate,
  597. 'image_list' => $image_list,
  598. ];
  599. $this->success(1,$result);
  600. }
  601. //图片列表
  602. public function image_list(){
  603. $childcate_id = input('child_id',0);
  604. $image_list = Db::name('image')->field('id,title,image')->where('childcate_id',$childcate_id)->where('status',1)->order('weigh asc,id desc')->select();
  605. $image_list = list_domain_image($image_list,['image']);
  606. $this->success(1,$image_list);
  607. }
  608. /** * * @param string $string 需要加密的字符串 * @param string $key 密钥 * @return string */
  609. private function encrypt($string, $key) {
  610. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  611. $data = openssl_encrypt($string, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  612. $data = bin2hex($data);
  613. return $data;
  614. }
  615. /** * @param string $string 需要解密的字符串 * @param string $key 密钥 * @return string */
  616. private function decrypt($string, $key) {
  617. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  618. $decrypted = openssl_decrypt(hex2bin($string), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  619. return $decrypted;
  620. }
  621. //共有方法,
  622. private function video_pvuv($video_id = 0){
  623. if(empty($video_id)) {return true;}
  624. //开启redis
  625. $redis = new Redis();
  626. $config = config('redis');
  627. $redis->connect($config['redis_host'], $config['redis_port']);
  628. if ($config['redis_pwd']) {
  629. $redis->auth($config['redis_pwd']);
  630. }
  631. if($config['redis_selectdb'] > 0){
  632. $redis->select($config['redis_selectdb']);
  633. }
  634. //今天
  635. $today = date('Y-m-d');
  636. //今日pv+1
  637. $today_pv_key = $today.'_video_pv_'.$video_id;
  638. $redis->incr($today_pv_key,1);
  639. //今日uv+1
  640. if($this->auth->isLogin() && $this->auth->id){
  641. $today_uv_key = $today.'_video_uv_'.$video_id;
  642. $uid = $this->auth->id;
  643. $redis->sAdd($today_uv_key,$uid);
  644. }
  645. //今日视频id列表
  646. $today_video_key = $today.'_video_list';
  647. $redis->sAdd($today_video_key,$video_id);
  648. }
  649. /*public function test(){
  650. $this->video_pvuv(input('video_id',0));
  651. }*/
  652. }