Index.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Think\Cache;
  5. use think\Db;
  6. use wxpay;
  7. use Qcloud\Cos\Client;
  8. use Qcloud\Cos\Exception\ServiceResponseException;
  9. /**
  10. * 首页接口
  11. */
  12. class Index extends Api
  13. {
  14. protected $noNeedLogin = ['banner', 'activelist', 'personaltype', 'personalactivetype', 'car', 'leader', 'personaldirection', 'activeinfo', 'position', 'gamelist', 'special_models', 'app_error','indexdata','tudingc'];
  15. protected $noNeedRight = ['*'];
  16. /**
  17. * 首页
  18. *
  19. */
  20. public function index()
  21. {
  22. $this->success('请求成功');
  23. }
  24. //视频分类列表
  25. public function videotype() {
  26. $type = input('type', 0, 'intval'); //分类类型:0=老年大学,1=普法课堂
  27. if (!in_array($type, [0, 1])) {
  28. $this->error('参数错误');
  29. }
  30. $list = Db::name('video_type')->field('id, name, image')->where(['type' => $type])
  31. ->page($this->page, $this->pagenum)->order('weigh, id')->select();
  32. $list = list_domain_image($list, ['image']);
  33. $this->success('分类', $list);
  34. }
  35. //视频列表
  36. public function video() {
  37. $type_id = input('type_id', 0, 'intval'); //分类id
  38. if (!$type_id) {
  39. $this->error('您的网络开小差了~');
  40. }
  41. $list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $type_id, 'status' => 1, 'inject_status' => 2])->page($this->page, $this->pagenum)->order('weigh, id desc')->select();
  42. $list = list_domain_image($list, ['image']);
  43. $this->success('视频', $list);
  44. }
  45. //视频详情
  46. public function videoinfo() {
  47. /*$id = 0;
  48. $session_video_id_time = Cache::get('session_video_id_time' . $this->auth->id);
  49. if ($session_video_id_time) {
  50. $session_video_id_time = explode('-', $session_video_id_time);
  51. $times = $session_video_id_time[1];
  52. if ($times > 0) {
  53. $id = $session_video_id_time[0];
  54. $next_times = $times - 1;
  55. cache('session_video_id_time' . $this->auth->id, $session_video_id_time[0] . '-' . $next_times, 10);
  56. } else {
  57. cache('session_video_id_time' . $this->auth->id, 0, 10);
  58. }
  59. }
  60. if (!$id) {*/
  61. $id = input('id', 0, 'intval'); //视频id
  62. // }
  63. if (!$id) {
  64. $this->error('您的网络开小差了');
  65. }
  66. $info = Db::name('video')->field('id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
  67. ->where(['id' => $id])->find();
  68. if (!$info) {
  69. $this->error('数据不存在');
  70. }
  71. if ($info['status'] != 1) {
  72. $this->error('视频丢失');
  73. }
  74. if ($info['inject_status'] != 2) {
  75. $this->error('视频丢失');
  76. }
  77. $info['neirong']='内容如有侵权,请联系删除';
  78. $info['neirong1']='为您推荐';
  79. $info['image'] = one_domain_image($info['image']);
  80. $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  81. $this->success('详情', $info);
  82. }
  83. /** * * @param string $string 需要加密的字符串 * @param string $key 密钥 * @return string */
  84. public function encrypt($string, $key) {
  85. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  86. $data = openssl_encrypt($string, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  87. $data = bin2hex($data);
  88. return $data;
  89. }
  90. /** * @param string $string 需要解密的字符串 * @param string $key 密钥 * @return string */
  91. public function decrypt($string, $key) {
  92. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  93. $decrypted = openssl_decrypt(hex2bin($string), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  94. return $decrypted;
  95. }
  96. //视频播放记录
  97. public function playrecord() {
  98. $id = input('id', 0, 'intval');
  99. $total_time = input('total_time', 0, 'intval'); //总时长
  100. $start_time = input('start_time', 0, 'intval'); //开始看时间:相对时间
  101. $end_time = input('end_time', 0, 'intval'); //结束看时间:相对时间
  102. $log_type = input('log_type', 'watching', 'trim'); //begin:开始播放;watching:正在播放;end:结束播放
  103. if (!$id) {
  104. $this->error('您的网络开小差了');
  105. }
  106. $info = Db::name('video')->where(['id' => $id])->find();
  107. if (!$info) {
  108. $this->error('数据不存在');
  109. }
  110. if ($info['inject_status'] != 2) {
  111. $this->error('视频丢失');
  112. }
  113. $info['image'] = one_domain_image($info['image']);
  114. $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyHistoryRecord';
  115. $content = [
  116. 'cpPrvdName' => '健康e家',
  117. 'cpPrvCode' => '41000144',
  118. 'cpPrvType' => '1006',
  119. 'contentName' => $info['title'],
  120. 'ChnName' => '健康',
  121. 'ChnCode' => '1000020',
  122. 'contentId' => (string)$info['movieid'],
  123. 'extraContentID' => '',
  124. 'isEffective' => $info['status'],
  125. 'isPaid' => $info['is_pay'],
  126. 'contentTotalTime' => $total_time,
  127. 'startWatchTime' => $start_time,
  128. 'endWatchTime' => $end_time,
  129. 'playTime' => $end_time - $start_time,
  130. 'logType' => $log_type,
  131. 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
  132. 'cpPermission' => 'GITV',
  133. 'intent' => [
  134. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  135. 'package' => 'com.huxiu.heh.tv',
  136. 'component' => [
  137. 'pkg' => 'com.huxiu.heh.tv',
  138. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  139. ],
  140. 'extras' => [
  141. /*'cmd' => '',
  142. 'from' => '',
  143. 'media_id' => ''*/
  144. 'type_id' => $info['video_type_id'],
  145. 'id' => $info['id']
  146. ]
  147. ],
  148. 'imageURL' => $info['image']
  149. ];
  150. $content = json_encode($content, 320);
  151. $rt = httpRequest($url, 'POST', $content);
  152. file_put_contents('bofang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
  153. if (!$rt) {
  154. // $this->error('同步失败');
  155. }
  156. $rt = json_decode($rt, true);
  157. if ($rt['code'] != 0) {
  158. // $this->error('同步失败');
  159. }
  160. $this->success('同步成功');
  161. }
  162. //视频收藏/取消收藏
  163. public function collectionrecord() {
  164. $id = input('id', 0, 'intval');
  165. if (!$id) {
  166. $this->error('您的网络开小差了');
  167. }
  168. $info = Db::name('video')->where(['id' => $id])->find();
  169. if (!$info) {
  170. $this->error('数据不存在');
  171. }
  172. //var_dump($info);exit;
  173. $info['image'] = one_domain_image($info['image']);
  174. //查询是否收藏
  175. $count = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  176. //开启事务
  177. if ($count) {
  178. $result = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
  179. } else {
  180. $result = Db::name('video_collection')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
  181. }
  182. if (!$result) {
  183. Db::rollback();
  184. $this->error('操作失败');
  185. }
  186. $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyCollectionRecord';
  187. $content = [
  188. 'cpPrvdName' => '健康e家',
  189. 'cpPrvCode' => '41000144',
  190. 'cpPrvType' => '1006',
  191. 'content' => $info['title'],
  192. 'ChnCode' => '1000020',
  193. 'contentId' => (string)$info['movieid'],
  194. 'extraContentID' => '',
  195. 'isEffective' => $info['status'],
  196. 'isPaid' => $info['is_pay'],
  197. 'collectionFlag' => $count ? 0 : 1,
  198. 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
  199. 'cpPermission' => 'GITV',
  200. 'intent' => [
  201. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  202. 'package' => 'com.huxiu.heh.tv',
  203. 'component' => [
  204. 'pkg' => 'com.huxiu.heh.tv',
  205. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  206. ],
  207. 'extras' => [
  208. /*'cmd' => '',
  209. 'from' => '',
  210. 'media_id' => ''*/
  211. 'type_id' => $info['video_type_id'],
  212. 'id' => $info['id']
  213. ]
  214. ],
  215. 'imageURL' => $info['image']
  216. ];
  217. $content = json_encode($content, 320);
  218. $rt = httpRequest($url, 'POST', $content);
  219. file_put_contents('shoucang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
  220. if (!$rt) {
  221. Db::rollback();
  222. $this->error('操作失败');
  223. }
  224. $rt = json_decode($rt, true);
  225. if ($rt['code'] != 0) {
  226. Db::rollback();
  227. $this->error('操作失败');
  228. }
  229. //大数据上报
  230. $data = [
  231. 'favid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
  232. 'UserID' => $this->auth->mobile,
  233. 'time' => date('Y-m-d H:i:s'),
  234. 'type' => $count ? 0 : 1,
  235. 'cpid' => config('data_cp_id'),
  236. 'albumid' => $id,
  237. 'albumname' => $info['title']
  238. ];
  239. $data = join(json_decode('"\u0001"', true), $data);
  240. $filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.dat';
  241. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.chk';
  242. error_log(print_r($data, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  243. error_log('', 3, './dashuju/' . $check_filename);
  244. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userfavdata.finish';
  245. error_log('', 3, './dashuju/' . $finish_filename);
  246. Db::commit();
  247. $this->success('操作成功');
  248. }
  249. //用户观看行为(大数据)
  250. public function userplay() {
  251. $id = input('id', 0, 'intval'); //视频id
  252. $sn = input('sn', '', 'trim'); //SN号
  253. $start_time = input('start_time', '', 'trim'); //YYYY-MM-DD HH:MM:SS(24小时制)节目开始播放时间
  254. $end_time = input('end_time', '', 'trim'); //YYYY-MM-DD HH:MM:SS(24小时制)节目结束播放时间
  255. $csource = input('csource', 0, ''); //1:从搜索结果访问2:从用户收藏/书签访问3:从EPG访问4:从推荐页面访问5:从猜你喜欢个性化推荐页面访问(带上推荐接口的trace_id)99:其他
  256. $trace_id = input('trace_id', '', 'trim');
  257. $istry = input('istry', 0, 'intval'); //0非试看 1试看
  258. $start_posi = input('start_posi', 0, 'intval'); //播放起始点相对于影片起始点的时长,单位秒,例如从影片第 600 秒开始观看
  259. if (!$id) {
  260. $this->error('您的网络开小差了');
  261. }
  262. $info = Db::name('video')->where(['id' => $id])->find();
  263. if (!$info) {
  264. $this->error('数据不存在');
  265. }
  266. $content = [
  267. 'playid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
  268. 'UserID' => $this->auth->mobile,
  269. 'SN' => $sn,
  270. 'start_time' => $start_time,
  271. 'end_time' => $end_time,
  272. 'service_type' => 1,
  273. 'cpid' => config('data_cp_id'),
  274. 'albumid' => $id,
  275. 'albumname' => $info['title'],
  276. 'videoid' => $id,
  277. 'videoname' => $info['title'],
  278. 'csource' => $csource,
  279. 'trace_id' => $trace_id,
  280. 'fee_type' => $info['is_pay'] == 1 ? 1 : 4,
  281. 'istry' => $istry,
  282. 'iscon' => 0,
  283. 'start_posi' => $start_posi
  284. ];
  285. $content = join(json_decode('"\u0001"', true), $content);
  286. $filename = date('Ymd').'_'.config('data_cp_id').'_userplaydata_1.dat';
  287. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userplaydata_1.chk';
  288. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  289. error_log('', 3, './dashuju/' . $check_filename);
  290. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userplaydata.finish';
  291. error_log('', 3, './dashuju/' . $finish_filename);
  292. $this->success('');
  293. }
  294. //用户行为feedback
  295. //前端没用到,废弃
  296. public function userfeedback() {
  297. $type = input('type', '', 'trim'); //曝光display/播放play/点击click/订购order/搜索 search/收藏 fav
  298. $itemid = input('itemid', '', 'trim'); //视频id,研究院推荐内容上报
  299. $otherid = input('otherid', '', 'trim'); //视频id,非研究院推荐内容上报
  300. $prodid = input('prodid', '', 'trim'); //订购行为必填;其余行为可选
  301. $trace_id = input('trace_id', '', 'trim'); //大数据推荐内容有trace_id
  302. $signal = input('signal', '', 'trim'); //所属板块编号,0异形、1头部、3电影,后续查看服务接口标识;非推荐内容所有行为为空;推荐内容所有行为必填
  303. $pos = input('pos', '', 'trim'); //所在位置编号,从左至右第1、2…个推荐位; 非推荐内容所有行为为空;推荐内容所有行为必填
  304. $play_duration = input('play_duration', 0, 'trim'); //单位毫秒,在播放结束时反馈该值
  305. $url = 'http://jscp.agency.gitv.tv/v2/feedback';
  306. $content['userid'] = $this->auth->mobile;
  307. $content['type'] = $type;
  308. if ($itemid) {
  309. $content['itemid'] = config('data_cp_id') . '|' . $itemid;
  310. }
  311. if ($otherid) {
  312. $content['otherid'] = config('data_cp_id') . '|' . $otherid;
  313. }
  314. if ($prodid) {
  315. $content['prodid'] = $prodid;
  316. }
  317. if ($trace_id) {
  318. $content['trace_id'] = 'v2_1_2_1000035_' . $this->auth->mobile . '_153672384859_123456_01';
  319. } else {
  320. $content['trace_id'] = '';
  321. }
  322. if ($signal) {
  323. $content['signal'] = $signal;
  324. } else {
  325. $content['signal'] = '';
  326. }
  327. if ($pos) {
  328. $content['pos'] = $pos;
  329. } else {
  330. $content['pos'] = '';
  331. }
  332. if ($play_duration) {
  333. $content['play_duration'] = $play_duration;
  334. } else {
  335. $content['play_duration'] = '';
  336. }
  337. $content['operate_time'] = getMillisecond();
  338. $content = http_build_query($content);
  339. $url = $url . '?' . $content;
  340. $rt = file_get_contents($url);
  341. if (!$rt) {
  342. $this->error('上报失败');
  343. }
  344. $this->success('上报成功');
  345. }
  346. //用户观看行为(支付)
  347. public function payuserplay() {
  348. $id = input('id', 0, 'intval'); //视频id
  349. $sn = input('sn', '', 'trim'); //SN号
  350. $start_time = input('start_time', '', 'trim'); //yyyymmddhhmmss (24小时制),节目开始播放时间
  351. $end_time = input('end_time', '', 'trim'); //yyyymmddhhmmss (24小时制),节目结束播放时间,如果播放未结束,但是此时需要同步数据,填当前时间
  352. $csource = input('csource', 0, ''); //1:从搜索结果访问2:从用户收藏/书签访问3:从EPG访问4:从推荐页面访问5、其他
  353. if (!$id) {
  354. $this->error('您的网络开小差了');
  355. }
  356. $info = Db::name('video')->where(['id' => $id])->find();
  357. if (!$info) {
  358. $this->error('数据不存在');
  359. }
  360. $content = [
  361. 'UserID' => $this->auth->mobile,
  362. 'city' => '14',
  363. 'start_time' => $start_time,
  364. 'end_time' => $end_time,
  365. 'service_type' => 1,
  366. 'albumid' => $id,
  367. 'albumname' => $info['title'],
  368. 'csource' => $csource,
  369. 'SN' => $sn,
  370. 'ip' => request()->ip(),
  371. 'fee_type' => $info['is_pay'] == 1 ? 1 : '',
  372. 'flow' => '',
  373. 'product' => '',
  374. 'product_name' => '',
  375. 'info_source' => '02'
  376. ];
  377. $content = join('|', $content);
  378. $filename = date('YmdH').'_'.config('cp_id').'_userviewdata_1.dat';
  379. $check_filename = date('YmdH').'_'.config('cp_id').'_userviewdata_1.chk';
  380. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  381. error_log('', 3, './dashuju/' . $check_filename);
  382. $this->success('');
  383. }
  384. //首页数据范返回
  385. public function indexdata()
  386. {
  387. $data = [];
  388. $data['logo'] = 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/home/logo.webp';
  389. $data['tuiding'] ='退订咨询';
  390. $data['vip']='https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/home/vip.webp';
  391. $data['free']='https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/home/free.webp';
  392. $data['banner1'] = 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/home%2Fleft1.webp';
  393. //$data['vip1'] = '0'; //字符串 0 免费
  394. $data['banner2'] = 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/home%2Fleft2.webp';
  395. $data['banner3'] = 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/home%2Fcenter1.webp';
  396. $data['banner4'] = 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/home%2Fright1.webp';
  397. $data['banner5'] = 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/home%2Fright2.webp';
  398. $data['banner6'] = 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/home%2Fleft3.webp';
  399. $data['banner7'] = 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/home%2Fcenter2.webp';
  400. $data['banner8'] = 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/home%2Fcenter3.webp';
  401. $data['banner9'] = 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/home%2Fright3.webp';
  402. $data['rightcontent'] = ['服务电话:13625150009','服务时间:周一至周五8:00-18:00','收视路径:首页-应用中心-健康e家'];
  403. $data['leftbottom'] = '内容如有侵权,请联系删除';
  404. $data['beian']['top'] = '';
  405. $data['beian']['bottom'] = '';
  406. $this->success('', $data);
  407. }
  408. //生活服务
  409. public function life_service() {
  410. $list = Db::name('life_service')->field('id, name, images')->where(['status' => 1])->page($this->page, $this->pagenum)->order('weigh, id')->select();
  411. $list = list_domain_image($list, ['images']);
  412. if(!empty($list))
  413. {
  414. foreach ($list as &$key)
  415. {
  416. $key['bcontent'] = '本信息由"淮安天职天利家政服务有限公司"提供';
  417. }
  418. }
  419. $this->success('生活服务', $list);
  420. }
  421. //退订服务
  422. public function tudingc()
  423. {
  424. $data = ['亲爱的用户:','如果您想退订健康e家业务,可以通过以下方式:','1、电视屏 一家庭专区一个人中心-我的订单,点击退订取消订购','2、收到成功订购健康e家业务短信的1小时内,根据短信内容,发送指定数字至10086901,即可取消业务不再收取费用','3、发送0000至10086获取最新的增值业务订购信息,根据短信内容回复“业务序号”取消对应业务','4、就近的营业厅办理增值业务退订','5、拨打10086客服热线进行退订
  425. ','6、登录中国移动网上营业厅:http://10086.cn 掌上营业厅:wap.10086.cn“已开服务一增值业务”进行退订'];
  426. $this->success('', $data);
  427. }
  428. //获取特殊机型
  429. public function special_models() {
  430. $special_models = config('site.special_models');
  431. $special_models = explode(',', $special_models);
  432. $this->success('获取特殊机型', $special_models);
  433. }
  434. //前端报错记录
  435. public function app_error() {
  436. $this->success('');
  437. }
  438. }