ku6api.class.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. <?php
  2. /**
  3. *
  4. * ----------------------------
  5. * ku6api class
  6. * ----------------------------
  7. *
  8. * An open source application development framework for PHP 5.0 or newer
  9. *
  10. * 这是个接口类,主要负责视频模型跟ku6vms之间的通信
  11. * @package PHPCMS V9.1.16
  12. * @author chenxuewang
  13. * @copyright CopyRight (c) 2006-2012 上海盛大网络发展有限公司
  14. *
  15. */
  16. class ku6api {
  17. public $ku6api_sn, $ku6api_key;
  18. private $ku6api_url,$http,$xxtea;
  19. /**
  20. *
  21. * 构造方法 初始化用户身份识别码、加密密钥等
  22. * @param string $ku6api_skey vms系统中的身份识别码
  23. * @param string $ku6api_sn vms系统中配置的通信加密密钥
  24. *
  25. */
  26. public function __construct($ku6api_sn = '', $ku6api_skey = '') {
  27. $this->ku6api_skey = $ku6api_skey;
  28. $this->ku6api_sn = $ku6api_sn;
  29. if (!$this->ku6api_sn) {
  30. $this->set_sn();
  31. }
  32. $this->ku6api_url = pc_base::load_config('ku6server', 'api_url');
  33. $this->ku6api_api = pc_base::load_config('ku6server', 'api');
  34. $this->http = pc_base::load_sys_class('http');
  35. $this->xxtea = pc_base::load_app_class('xxtea', 'video');
  36. }
  37. /**
  38. *
  39. * 设置身份识别码及身份密钥
  40. *
  41. */
  42. private function set_sn() {
  43. //获取短信平台配置信息
  44. $setting = getcache('video', 'video');
  45. if ($setting['sn'] && $setting['skey']) {
  46. $this->ku6api_skey = $setting['skey'];
  47. $this->ku6api_sn = $setting['sn'];
  48. }
  49. }
  50. /**
  51. *
  52. * vms_add 视频添加方法 系统中添加视频是调用,同步添加到vms系统中
  53. * @param array $data 添加是视频信息 视频标题、介绍等
  54. */
  55. public function vms_add($data = array()) {
  56. if (is_array($data) && !empty($data)) {
  57. //处理数据
  58. $data['tag'] = $this->get_tag($data);
  59. $data['v'] = 1;
  60. $data['channelid'] = $data['channelid'] ? intval($data['channelid']) : 1;
  61. //将gbk编码转为utf-8编码
  62. if (CHARSET == 'gbk') {
  63. $data = array_iconv($data);
  64. }
  65. $data['sn'] = $this->ku6api_sn;
  66. $data['method'] = 'VideoAdd';
  67. $data['posttime'] = SYS_TIME;
  68. $data['token'] = $this->xxtea->encrypt($data['posttime'], $this->ku6api_skey);
  69. //向vms post数据,并获取返回值
  70. $this->http->post($this->ku6api_url, $data);
  71. $get_data = $this->http->get_data();
  72. $get_data = json_decode($get_data, true);
  73. if($get_data['code'] != 200) {
  74. $this->error_msg = $get_data['msg'];
  75. return false;
  76. }
  77. return $get_data;
  78. } else {
  79. $this->error_msg = '';
  80. return false;
  81. }
  82. }
  83. /**
  84. * function vms_edit
  85. * 视频编辑时调用 视频改变时同步更新vms系统中对应的视频
  86. * @param array $data
  87. */
  88. public function vms_edit($data = array()) {
  89. if (is_array($data ) && !empty($data)) {
  90. //处理数据
  91. $data['tag'] = $this->get_tag($data);
  92. //将gbk编码转为utf-8编码
  93. if (CHARSET == 'gbk') {
  94. $data = array_iconv($data);
  95. }
  96. $data['sn'] = $this->ku6api_sn;
  97. $data['method'] = 'VideoEdit';
  98. $data['posttime'] = SYS_TIME;
  99. $data['token'] = $this->xxtea->encrypt($data['posttime'], $this->ku6api_skey);
  100. //向vms post数据,并获取返回值
  101. $this->http->post($this->ku6api_url, $data);
  102. $get_data = $this->http->get_data();
  103. $get_data = json_decode($get_data, true);
  104. if($get_data['code'] != 200) {
  105. $this->error_msg = $get_data['msg'];
  106. return false;
  107. }
  108. return true;
  109. } else {
  110. return false;
  111. }
  112. }
  113. /**
  114. * function delete_v
  115. * 删除视频时,通知vms系统接口。
  116. * @param string $ku6vid vms系统中ku6vid
  117. */
  118. public function delete_v($ku6vid = '') {
  119. if (!$ku6vid) return false;
  120. //构造post数据
  121. $data['sn'] = $this->ku6api_sn;
  122. $data['method'] = 'VideoDel';
  123. $data['posttime'] = SYS_TIME;
  124. $data['token'] = $this->xxtea->encrypt($data['posttime'], $this->ku6api_skey);
  125. $data['vid'] = $ku6vid;
  126. //向vms post数据
  127. $this->http->post($this->ku6api_url, $data);
  128. $get_data = $this->http->get_data();
  129. $get_data = json_decode($get_data, true);
  130. if($get_data['code'] != 200 && $get_data['code']!=112) {
  131. $this->error_msg = $get_data['msg'];
  132. return false;
  133. }
  134. return true;
  135. }
  136. /**
  137. *
  138. * 获取视频tag标签
  139. * @param array $data 视频信息数组
  140. * @return string $tag 标签
  141. */
  142. private function get_tag($data = array()) {
  143. if (is_array($data) && !empty($data)) {
  144. if ($data['keywords']) $tag = trim(strip_tags($data['keywords']));
  145. else $tag = $data['title'];
  146. return $tag;
  147. }
  148. }
  149. /**
  150. * function update_video_status_from_vms
  151. * 视频状态改变接口
  152. * @param array $get 视频信息
  153. */
  154. public function update_video_status_from_vms() {
  155. if (is_array($_GET) && !empty($_GET)) {
  156. $size = $_GET['size'];
  157. $timelen = intval($_GET['timelen']);
  158. $status = intval($_GET['ku6status']);
  159. $vid = $_GET['vid'];
  160. $picpath = format_url($_GET['picpath']);
  161. //验证数据
  162. /* 验证vid */
  163. if(!$vid) return json_encode(array('status'=>'101','msg'=>'vid not allowed to be empty'));
  164. /* 验证视频大小 */
  165. if($size<100) return json_encode(array('status'=>'103','msg'=>'size incorrect'));
  166. /* 验证视频时长 */
  167. if($timelen<1) return json_encode(array('status'=>'104','msg'=>'timelen incorrect'));
  168. $db = pc_base::load_model('video_store_model');
  169. $r = $db->get_one(array('vid'=>$vid));
  170. if ($r) {
  171. $db->update(array('size'=>$size, 'picpath'=>$picpath, 'status'=>$status), array('vid'=>$vid));
  172. if ($status==21) {
  173. $r = $video_store_db->get_one(array('vid'=>$vid), 'videoid'); //取出videoid,以便下面操作
  174. $videoid = $r['videoid'];
  175. /**
  176. * 加载视频内容对应关系数据模型,检索与删除视频相关的内容。
  177. * 在对应关系表中找出对应的内容id,并更新内容的静态页
  178. */
  179. $video_content_db = pc_base::load_model('video_content_model');
  180. $result = $video_content_db->select(array('videoid'=>$videoid));
  181. if (is_array($result) && !empty($result)) {
  182. //加载更新html类
  183. $html = pc_base::load_app_class('html', 'content');
  184. $content_db = pc_base::load_model('content_model');
  185. $url = pc_base::load_app_class('url', 'content');
  186. foreach ($result as $rs) {
  187. $modelid = intval($rs['modelid']);
  188. $contentid = intval($rs['contentid']);
  189. $content_db->set_model($modelid);
  190. $content_db->update(array('status'=>99), array('id'=>$contentid));
  191. $table_name = $content_db->table_name;
  192. $r1 = $content_db->get_one(array('id'=>$contentid));
  193. /**
  194. * 判断如果内容页生成了静态页,则更新静态页
  195. */
  196. if (ishtml($r1['catid'])) {
  197. $content_db->table_name = $table_name.'_data';
  198. $r2 = $content_db->get_one(array('id'=>$contentid));
  199. $r = array_merge($r1, $r2);unset($r1, $r2);
  200. if($r['upgrade']) {
  201. $urls[1] = $r['url'];
  202. } else {
  203. $urls = $url->show($r['id'], '', $r['catid'], $r['inputtime']);
  204. }
  205. $html->show($urls[1], $r, 0, 'edit');
  206. } else {
  207. continue;
  208. }
  209. }
  210. }
  211. } elseif ($data['status']<0 || $data['status']==24) {
  212. $r = $video_store_db->get_one(array('vid'=>$vid), 'videoid'); //取出videoid,以便下面操作
  213. $videoid = $r['videoid'];
  214. //$video_store_db->delete(array('vid'=>$vid)); //删除此视频
  215. /**
  216. * 加载视频内容对应关系数据模型,检索与删除视频相关的内容。
  217. * 在对应关系表中解除关系,并更新内容的静态页
  218. */
  219. $video_content_db = pc_base::load_model('video_content_model');
  220. $result = $video_content_db->select(array('videoid'=>$videoid));
  221. if (is_array($result) && !empty($result)) {
  222. //加载更新html类
  223. $html = pc_base::load_app_class('html', 'content');
  224. $content_db = pc_base::load_model('content_model');
  225. $url = pc_base::load_app_class('url', 'content');
  226. foreach ($result as $rs) {
  227. $modelid = intval($rs['modelid']);
  228. $contentid = intval($rs['contentid']);
  229. $video_content_db->delete(array('videoid'=>$videoid, 'contentid'=>$contentid, 'modelid'=>$modelid));
  230. $content_db->set_model($modelid);
  231. $table_name = $content_db->table_name;
  232. $r1 = $content_db->get_one(array('id'=>$contentid));
  233. /**
  234. * 判断如果内容页生成了静态页,则更新静态页
  235. */
  236. if (ishtml($r1['catid'])) {
  237. $content_db->table_name = $table_name.'_data';
  238. $r2 = $content_db->get_one(array('id'=>$contentid));
  239. $r = array_merge($rs, $r2);unset($r1, $r2);
  240. if($r['upgrade']) {
  241. $urls[1] = $r['url'];
  242. } else {
  243. $urls = $url->show($r['id'], '', $r['catid'], $r['inputtime']);
  244. }
  245. $html->show($urls[1], $r, 0, 'edit');
  246. } else {
  247. continue;
  248. }
  249. }
  250. }
  251. }
  252. return json_encode(array('status'=>'200','msg'=>'Success'));
  253. } else {
  254. return json_encode(array('status'=>'107','msg'=>'Data is empty!'));
  255. }
  256. }
  257. json_encode(array('status'=>'107','msg'=>'Data is empty!'));
  258. }
  259. /**
  260. * function get_categroys
  261. * 将cms系统中视频模型的栏目取出来,并通过接口传到vms系统中
  262. * @param bloon $isreturn 是否返回option
  263. * @param int $catid 被选中的栏目 id
  264. */
  265. public function get_categorys($isreturn = false, $catid = 0) {
  266. $siteid = get_siteid();
  267. $sitemodel_field = pc_base::load_model('sitemodel_field_model');
  268. $result = $sitemodel_field->select(array('formtype'=>'video', 'siteid'=>$siteid), 'modelid');
  269. if (is_array($result)) {
  270. $models = '';
  271. foreach ($result as $r) {
  272. $models .= $r['modelid'].',';
  273. }
  274. }
  275. $models = substr(trim($models), 0, -1);
  276. $cat_db = pc_base::load_model('category_model');
  277. if ($models) {
  278. $where = '`modelid` IN ('.$models.') AND `type`=0 AND `siteid`=\''.$siteid.'\'';
  279. $result = $cat_db->select($where, '`catid`, `catname`, `parentid`, `siteid`, `child`');
  280. if (is_array($result)) {
  281. $data = $return_data = array();
  282. foreach ($result as $r) {
  283. $sitename = $this->get_sitename($r['siteid']);
  284. $data[] = array('catid'=>$r['catid'], 'catname'=>$r['catname'], 'parentid'=>$r['parentid'], 'siteid'=>$r['siteid'], 'sitename'=>$sitename, 'child'=>$r['child']);
  285. $r['disabled'] = $r['child'] ? 'disabled' : '';
  286. if ($r['catid'] == $catid) {
  287. $r['selected'] = 'selected';
  288. }
  289. $return_data[$r['catid']] = $r;
  290. }
  291. //将gbk编码转为utf-8编码
  292. if (strtolower(CHARSET) == 'gbk') {
  293. $data = array_iconv($data);
  294. }
  295. $data = json_encode($data);
  296. $postdata['sn'] = $this->ku6api_sn;
  297. $postdata['method'] = 'UserCat';
  298. $postdata['posttime'] = SYS_TIME;
  299. $postdata['token'] = $this->xxtea->encrypt($postdata['posttime'], $this->ku6api_skey);
  300. $postdata['data'] = $data;
  301. //向vms post数据,并获取返回值
  302. $this->http->post($this->ku6api_url, $postdata);
  303. $get_data = $this->http->get_data();
  304. $get_data = json_decode($get_data, true);
  305. if($get_data['code'] != 200) {
  306. $this->error_msg = $get_data['msg'];
  307. return false;
  308. } elseif ($isreturn) {
  309. $tree = pc_base::load_sys_class('tree');
  310. $str = "<option value='\$catid' \$selected \$disabled>\$spacer \$catname</option>";
  311. $tree->init($return_data);
  312. $string = $tree->get_tree(0, $str);
  313. return $string;
  314. } else {
  315. return true;
  316. }
  317. }
  318. }
  319. return array();
  320. }
  321. /**
  322. * function get_ku6_channels
  323. * 获取ku6的频道信息
  324. */
  325. public function get_subscribetype() {
  326. //构造post数据
  327. $postdata['method'] = 'SubscribeType';
  328. //向vms post数据,并获取返回值
  329. if ($data = $this->post($postdata)) {
  330. return $data['data'];
  331. }
  332. return false;
  333. }
  334. /**
  335. * function get_ku6_channels
  336. * 获取ku6的频道信息
  337. */
  338. public function get_ku6_channels() {
  339. //构造post数据
  340. $postdata['method'] = 'Ku6Channel';
  341. //向vms post数据,并获取返回值
  342. if ($data = $this->post($postdata)) {
  343. return $data['data'];
  344. }
  345. return false;
  346. }
  347. /**
  348. * function subscribe 订阅处理
  349. * 该方法将用户的订阅信息post到vms里面记录
  350. * @param array $data 推送信息 例如: array(array('channelid'=>102000, 'catid'=>16371, 'posid'=>8))
  351. */
  352. public function subscribe($datas = array()) {
  353. //构造post数据
  354. $postdata['method'] = 'SubscribeAdd';
  355. $postdata['channelid'] = $datas['channelid'];
  356. $postdata['catid'] = $datas['catid'];
  357. $postdata['posid'] = $datas['posid'] ? $datas['posid'] : 0;
  358. //向vms post数据,并获取返回值
  359. if ($data = $this->post($postdata)) {
  360. return $data;
  361. }
  362. return false;
  363. }
  364. /**
  365. * function checkusersubscribe 判断用户是否已经订阅
  366. */
  367. public function checkusersubscribe($datas = array()) {
  368. $postdata['method'] = 'CheckUserSubscribe';
  369. $postdata['userid'] = $datas['userid'];
  370. //向vms post数据,并获取返回值
  371. if ($data = $this->post($postdata)) {
  372. return $data;
  373. }
  374. return false;
  375. }
  376. /**
  377. * function subscribe 按用户订阅处理
  378. * 该方法将用户的订阅信息post到vms里面记录
  379. * @param array $data 推送信息 例如: array(array('userid'=>102000, 'catid'=>16371, 'posid'=>8))
  380. */
  381. public function usersubscribe($datas = array()) {
  382. //构造post数据
  383. $postdata['method'] = 'UserSubscribeAdd';
  384. $postdata['userid'] = $datas['userid'];
  385. $postdata['catid'] = $datas['catid'];
  386. $postdata['posid'] = $datas['posid'] ? $datas['posid'] : 0;
  387. //向vms post数据,并获取返回值
  388. if ($data = $this->post($postdata)) {
  389. return $data;
  390. }
  391. return false;
  392. }
  393. /**
  394. * Function sub_del 删除订阅
  395. * 用户删除订阅
  396. * @param int $id 订阅id
  397. */
  398. public function sub_del($id = 0) {
  399. if (!$id) return false;
  400. //构造post数据
  401. $postdata['method'] = 'SubscribeDel';
  402. $postdata['sid'] = $id;
  403. //向vms post数据,并获取返回值
  404. if ($data = $this->post($postdata)) {
  405. return true;
  406. }
  407. return false;
  408. }
  409. /**
  410. * Function user_sub_del 删除订阅用户
  411. * 删除订阅用户
  412. * @param int $id 订阅id
  413. */
  414. public function user_sub_del($id = 0) {
  415. if (!$id) return false;
  416. //构造post数据
  417. $postdata['method'] = 'UserSubscribeDel';
  418. $postdata['sid'] = $id;
  419. //向vms post数据,并获取返回值
  420. if ($data = $this->post($postdata)) {
  421. return true;
  422. }
  423. return false;
  424. }
  425. /**
  426. * fucntion get_subscribe 获取订阅
  427. * 获取自己的订阅信息
  428. */
  429. public function get_subscribe() {
  430. //构造post数据
  431. $postdata['method'] = 'SubscribeSearch';
  432. //向vms post数据,并获取返回值
  433. if ($data = $this->post($postdata)) {
  434. return $data['data'];
  435. } else {
  436. return false;
  437. }
  438. }
  439. /**
  440. * fucntion get_subscribe 获取用户订阅
  441. * 获取用户自己的订阅信息
  442. */
  443. public function get_usersubscribe() {
  444. //构造post数据
  445. $postdata['method'] = 'UserSubscribeSearch';
  446. //向vms post数据,并获取返回值
  447. if ($data = $this->post($postdata)) {
  448. return $data['data'];
  449. } else {
  450. return false;
  451. }
  452. }
  453. /**
  454. * Function flashuploadparam 获取flash上传条属性
  455. * 获取flash上传条属性
  456. */
  457. public function flashuploadparam () {
  458. //构造post数据
  459. $postdata['method'] = 'GetFlashUploadParam';
  460. //向vms post数据,并获取返回值
  461. if ($data = $this->post($postdata)) {
  462. return $data['data'];
  463. } else {
  464. return FALSE;
  465. }
  466. }
  467. /**
  468. * Function get_albums
  469. * 获取ku6专辑列表
  470. * @param int $page 当前页数
  471. * @param int $pagesize 每页数量
  472. * @return array 返回专辑数组
  473. */
  474. public function get_albums($page = 1, $pagesize = 20) {
  475. //构造post数据
  476. if ($_GET['start_time']) {
  477. $postdata['start_time'] = strtotime($_GET['start_time']);
  478. }
  479. if ($_GET['end_time']) {
  480. $postdata['end_time'] = strtotime($_GET['end_time']);
  481. }
  482. if ($_GET['keyword']) {
  483. $postdata['key'] = addslashes($_GET['keyword']);
  484. }
  485. if ($_GET['categoryid']) {
  486. $postdata['categoryid'] = intval($_GET['categoryid']);
  487. }
  488. $postdata['method'] = 'AlbumList';
  489. $postdata['start'] = ($page-1)*$pagesize;
  490. $postdata['size'] = $pagesize;
  491. //向vms post数据,并获取返回值
  492. if ($data = $this->post($postdata)) {
  493. return $data;
  494. } else {
  495. return false;
  496. }
  497. }
  498. /**
  499. * Function get_album_videoes
  500. * 获取某专辑下的视频列表
  501. * @param int $albumid 专辑ID
  502. * @param int $page 当前页
  503. * @param int $pagesize 每页数量
  504. * @return array 视频数组
  505. */
  506. public function get_album_videoes($albumid = 0, $page = 1, $pagesize = 20) {
  507. //构造post数据
  508. $postdata['method'] = 'AlbumVideoList';
  509. $postdata['p'] = $page;
  510. $postdata['playlistid'] = $albumid;
  511. $postdata['s'] = $pagesize;
  512. //向vms post数据,并获取返回值
  513. if ($data = $this->post($postdata)) {
  514. return $data['data'];
  515. } else {
  516. return false;
  517. }
  518. }
  519. /**
  520. * Function get_album_info
  521. * 获取专辑的详细信息
  522. * @param int $albumid 专辑id
  523. */
  524. public function get_album_info($albumid = 0) {
  525. $albumid = intval($albumid);
  526. if (!$albumid) return false;
  527. $arr = array('method'=>'GetOneAlbum', 'id'=>$albumid);
  528. if ($data = $this->post($arr)) {
  529. return $data['list'];
  530. } else {
  531. return false;
  532. }
  533. }
  534. /**
  535. * Function add_album_subscribe
  536. * 添加专辑订阅
  537. * @param array $data 订阅数组 如:array(0=>array('specialid'=>1, 'id'=>1232131), 1=>array('specialid'=>2, 'id'=>4354323))
  538. */
  539. public function add_album_subscribe($data = array()) {
  540. if (!is_array($data) || empty($data)) {
  541. return false;
  542. }
  543. //构造post数据
  544. $postdata['method'] = 'AlbumVideoSubscribe';
  545. $postdata['data'] = $data;
  546. //向vms post数据,并获取返回值
  547. if ($data = $this->post($postdata)) {
  548. return true;
  549. } else {
  550. return false;
  551. }
  552. }
  553. /**
  554. * Function member_login_vms
  555. * 登陆后台同时登陆vms
  556. * @param array $data
  557. */
  558. public function member_login_vms() {
  559. //构造post数据
  560. $postdata = array();
  561. $postdata['method'] = 'SynLogin';
  562. //向vms post数据,并获取返回值
  563. if ($data = $this->post($postdata)) {
  564. return true;
  565. } else {
  566. return false;
  567. }
  568. }
  569. /**
  570. * Function check_status
  571. * 登陆后台同时登陆vms
  572. * @param array $data
  573. */
  574. public function check_status($vid = '') {
  575. if (!$vid) return false;
  576. //构造post数据
  577. $postdata = array();
  578. $postdata['method'] = 'VideoStatusCheck';
  579. $postdata['vid'] = $vid;
  580. //向vms post数据,并获取返回值
  581. if ($data = $this->post($postdata)) {
  582. return $data;
  583. } else {
  584. return false;
  585. }
  586. }
  587. /**
  588. * Function http
  589. * 执行http post数据到接口
  590. * @param array $datas post数据参数 如:array('method'=>'AlbumVideoList', 'p'=>1, 's'=>6,....)
  591. */
  592. private function post($datas = array()) {
  593. //构造post数据
  594. $data['sn'] = $this->ku6api_sn;
  595. $data['posttime'] = SYS_TIME;
  596. $data['token'] = $this->xxtea->encrypt($data['posttime'], $this->ku6api_skey);
  597. if (strtolower(CHARSET) == 'gbk') {
  598. $datas = array_iconv($datas, 'gbk', 'utf-8');
  599. }
  600. if (is_array($datas)) {
  601. foreach ($datas as $_k => $d) {
  602. if (is_array($d)) {
  603. $data[$_k] = json_encode($d);
  604. } else {
  605. $data[$_k] = $d;
  606. }
  607. }
  608. }
  609. //向vms post数据,并获取返回值
  610. $this->http->post($this->ku6api_url, $data);
  611. $get_data = $this->http->get_data();
  612. $get_data = json_decode($get_data, true);
  613. //成功时vms返回code=200 而ku6返回status=1
  614. if ($get_data['code'] == 200 || $get_data['status'] == 1) {
  615. //将gbk编码转为utf-8编码
  616. if (strtolower(CHARSET) == 'gbk') {
  617. $get_data = array_iconv($get_data, 'utf-8', 'gbk');
  618. }
  619. return $get_data;
  620. } else {
  621. return $get_data;
  622. }
  623. }
  624. /**
  625. * Function CHECK
  626. * 向vms发送vid
  627. * @param string $vid vid
  628. */
  629. public function check($vid = '') {
  630. if (!$vid) return false;
  631. //构造post数据
  632. $postdata['method'] = 'GetVid';
  633. $postdata['vid'] = $vid;
  634. $postdata['url'] = APP_PATH . 'api.php?op=video_api';
  635. //向vms post数据,并获取返回值
  636. if ($data = $this->post($postdata)) {
  637. return true;
  638. } else {
  639. return false;
  640. }
  641. }
  642. /**
  643. * Function vms_update_video
  644. * 更新视频库视频到新系统
  645. * @param array $data array of video
  646. */
  647. public function vms_update_video($data = array()) {
  648. if (empty($data)) return false;
  649. //构造post数据
  650. $postdata['method'] = 'VideoUpdate';
  651. $postdata['data'] = $data;
  652. //向vms post数据,并获取返回值
  653. if ($data = $this->post($postdata)) {
  654. return $data;
  655. } else {
  656. return false;
  657. }
  658. }
  659. /**
  660. * Function Preview
  661. * 向vms请求vid
  662. * @param string $vid vid
  663. */
  664. public function Preview($vid = '') {
  665. if (!$vid) return false;
  666. //构造post数据
  667. $postdata['method'] = 'Preview';
  668. $postdata['vid'] = $vid;
  669. //向vms post数据,并获取返回值
  670. if ($data = $this->post($postdata)) {
  671. return $data;
  672. } else {
  673. return false;
  674. }
  675. }
  676. /**
  677. * Function Ku6search
  678. * 向vms请求搜索
  679. * @param string $vid vid
  680. */
  681. public function Ku6search($keyword,$pagesize,$page,$srctype,$len,$fenlei,$fq) {
  682. //构造post数据
  683. $postdata['method'] = 'search';
  684. $postdata['pagesize'] = $pagesize;
  685. $postdata['keyword'] = $keyword;
  686. $postdata['page'] = $page;
  687. $postdata['fenlei'] = $fenlei;
  688. $postdata['srctype'] = $srctype;
  689. $postdata['len'] = $len;
  690. $postdata['fq'] = $fq;
  691. //向vms post数据,并获取返回值
  692. if ($data = $this->post($postdata)) {
  693. return $data;
  694. } else {
  695. return false;
  696. }
  697. }
  698. /**
  699. * Function get_sitename
  700. * 获取站点名称
  701. */
  702. private function get_sitename($siteid) {
  703. static $sitelist;
  704. if (!$sitelist) {
  705. $sitelist = getcache('sitelist', 'commons');
  706. }
  707. return $sitelist[$siteid]['name'];
  708. }
  709. /**
  710. * Function update_vms
  711. * @升级视频系统,向新系统添加用户
  712. * @param $data POST数据
  713. */
  714. public function update_vms_member($data = array()) {
  715. if (empty($data)) return false;
  716. //构造post数据
  717. $data['sn'] = $this->ku6api_sn;
  718. $data['skey'] = $this->ku6api_skey;
  719. $postdata['data'] = json_encode($data);
  720. $api_url = pc_base::load_config('sub_config','member_add_dir').'MemberUpgrade.php';
  721. $data = $this->post_api($api_url, $postdata);
  722. //向vms post数据,并获取返回值
  723. if ($data) {
  724. return $data;
  725. } else {
  726. return $data;
  727. return false;
  728. }
  729. }
  730. /**
  731. * Function testapi
  732. * 测试接口配置是否正确
  733. */
  734. public function testapi() {
  735. $postdata['method'] = 'Test';
  736. $data = $this->post($postdata);
  737. if ($data['code']==200) {
  738. return true;
  739. } else {
  740. return false;
  741. }
  742. }
  743. /******************以下为视频统计使用*****************/
  744. /*
  745. * 最近视频播放量走势图
  746. */
  747. public function get_stat_bydate($start_time,$end_time,$pagesize,$page){
  748. //构造post数据
  749. $postdata['pagesize'] = $pagesize;
  750. $postdata['page'] = $page;
  751. $postdata['start_time'] = $start_time;
  752. $postdata['end_time'] = $end_time;
  753. $postdata['method'] = 'GetStatBydate';
  754. //向vms post数据,并获取返回值
  755. $data = $this->post($postdata);
  756. return $data;
  757. }
  758. /*
  759. * 根据关键字来搜索视频
  760. */
  761. public function get_video_bykeyword($type,$keyword){
  762. $postdata['type'] = $type;
  763. $postdata['keyword'] = $keyword;
  764. $postdata['method'] = 'GetVideoBykeyword';
  765. //向vms post数据,并获取返回值
  766. $data = $this->post($postdata);
  767. if ($data['code']==200) {
  768. return $data;
  769. } else {
  770. echo '搜索出现错误,请联系管理员!';exit;
  771. return false;
  772. }
  773. }
  774. /*
  775. * 查看视频流量走势
  776. */
  777. public function show_video_stat($vid){
  778. if(!$vid) return false;
  779. $postdata['vid'] = $vid;
  780. $postdata['method'] = 'ShowVideoStat';
  781. //向vms post数据,并获取返回值
  782. $data = $this->post($postdata);
  783. if ($data['code']==200) {
  784. return $data;
  785. } else {
  786. echo '查看视频统计出错,请联系管理员!';
  787. return false;
  788. }
  789. }
  790. /*
  791. * 视频流量总体趋势图
  792. */
  793. public function vv_trend(){
  794. $postdata['method'] = 'VvTrend';
  795. $data = $this->post($postdata);
  796. if ($data['code']==200) {
  797. return $data;
  798. } else {
  799. echo '视频流量总体趋势图!';
  800. return false;
  801. }
  802. }
  803. /*
  804. * 按时间查看当日视频播放排行榜,以播放次数倒叙
  805. * $date 2012-02-03
  806. */
  807. /* 王参加注释,这个是否还有用?
  808. public function get_stat_single($date){
  809. //构造post数据
  810. $postdata['method'] = 'get_stat_single';
  811. $postdata['pagesize'] = $pagesize;
  812. $postdata['date'] = $date;
  813. $postdata['page'] = $page;
  814. //向vms post数据,并获取返回值
  815. if ($data = $this->post($postdata)) {
  816. return $data;
  817. } else {
  818. echo '没有返回查询时间点的数据!';exit;
  819. return false;
  820. }
  821. }
  822. */
  823. //完善资料
  824. public function complete_info($data){
  825. //构造post数据
  826. $postdata = $data;
  827. $postdata['user_back'] = APP_PATH . 'api.php?op=video_api';
  828. //向vms post数据,并获取返回值
  829. $url = $this->ku6api_api."CompleteInfo.php";
  830. $return_data = $this->post_api($url, $postdata);
  831. if ($return_data['code']=='200') {
  832. return $return_data['data'];
  833. } else {
  834. return '-1';
  835. }
  836. }
  837. /*
  838. * 获得用户填写的详细资料
  839. * 返回值: 用户完善的资料
  840. */
  841. public function Get_Complete_Info($data){
  842. if (empty($data)) return false;
  843. $url = $this->ku6api_api."Get_Complete_Info.php";
  844. $return_data = $this->post_api($url, $data);
  845. if ($return_data['code']=='200') {
  846. return $return_data['data'];
  847. } else {
  848. return false;
  849. }
  850. }
  851. /*
  852. * 获得用户填写的详细资料
  853. * 返回值: 用户完善的资料
  854. */
  855. public function check_user_back($url){
  856. if (empty($url)) return false;
  857. $data['url'] = $url;
  858. $url = $this->ku6api_api."Check_User_Back.php";
  859. $return_data = $this->post_api($url, $data);
  860. if ($return_data['code']=='200') {
  861. return 200;
  862. } else {
  863. return -200;
  864. }
  865. }
  866. //发送验证码到指定邮件
  867. public function send_code($data){
  868. if (empty($data)) return false;
  869. $new_data['email'] = $data['email'];
  870. $new_data['url'] = $data['url'];
  871. $url = $this->ku6api_api."Send_Code.php";
  872. $return_data = $this->post_api($url, $new_data);
  873. return $return_data;
  874. }
  875. //验证信箱和验证码,包含email and code
  876. public function check_email_code($data){
  877. if (empty($data)) return false;
  878. $url = $this->ku6api_api."Check_Email_Code.php";
  879. $return_data = $this->post_api($url, $data);
  880. if($return_data['code']=='200'){
  881. return $return_data['data'];
  882. }else{
  883. return false;
  884. }
  885. }
  886. /**
  887. * Function
  888. * 获取播放器列表
  889. */
  890. public function player_list() {
  891. $postdata['method'] = 'PlayerList';
  892. $data = $this->post($postdata);
  893. if ($data['code']==200) {
  894. return $data;
  895. } else {
  896. return false;
  897. }
  898. }
  899. /**
  900. * Function
  901. * 获取播放器列表
  902. */
  903. public function player_edit($field,$style) {
  904. $postdata['method'] = 'PlayerEdit';
  905. $postdata['field'] = $field;
  906. $postdata['style'] = $style;
  907. $data = $this->post($postdata);
  908. if ($data['code']==200) {
  909. return $data;
  910. } else {
  911. return false;
  912. }
  913. }
  914. /**
  915. * FUNCTION post_api
  916. * @post数据到api,post方法是post数据到api下面的v5,而post_api是post到api下面
  917. * @$data array post数据
  918. */
  919. private function post_api($url = '', $data = array()) {
  920. if (empty($url) || !preg_match("/^(http:\/\/)?([a-z0-9\.]+)(\/api)(\/[a-z0-9\._]+)/i", $url) || empty($data)) return false;
  921. $ch = curl_init();
  922. curl_setopt($ch, CURLOPT_URL, $url);
  923. curl_setopt($ch, CURLOPT_POST, 1);
  924. curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1);
  925. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  926. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  927. curl_setopt($ch, CURLOPT_USERAGENT, 'Client SDK ');
  928. $output = curl_exec($ch);
  929. $return_data = json_decode($output,true);
  930. return $return_data;
  931. }
  932. }