Tvindex.php 25 KB

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