Juhe.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. namespace app\controller\api\article;
  3. use app\Request;
  4. use think\facade\Db;
  5. use crmeb\basic\BaseController;
  6. class Juhe extends BaseController
  7. {
  8. public static $key_tt = "4aea8d10a534112d7ae880b321d05268";
  9. public static $key_sp = "a92b764c1e53abddda3a99ccc91cf22c";
  10. /**
  11. * 新闻那头条1
  12. * author 爱代码的糖糖
  13. * time 2021 08 17 16:00:26
  14. */
  15. public function toutiao()
  16. {
  17. $url='http://v.juhe.cn/toutiao/index';
  18. for ($i=1;$i<=9;$i++){
  19. if($i==1 or $i==2){
  20. $type='guonei';
  21. }elseif($i==3){
  22. $type='guowai';
  23. }elseif($i==4){
  24. $type='yule';
  25. }elseif($i==6 or $i==7){
  26. $type='caijing';
  27. }elseif($i==8 or $i==9){
  28. $type='jiankang';
  29. }elseif($i==5){
  30. $type='keji';
  31. }
  32. $param=[
  33. 'type'=>$type,
  34. 'key'=>self::$key_tt,
  35. 'is_filter'=>1,
  36. 'page'=>$i,
  37. 'page_size'=>10
  38. ];
  39. $data= json_decode($this->curl($url,$param,'get'),true);
  40. if(empty($data['result']['data'])){
  41. break;
  42. }
  43. $result=$data['result']['data'];
  44. foreach ($result as $k=>$v){
  45. $insertData=[
  46. 'cid'=>23,
  47. 'admin_id'=>1,
  48. 'title'=>$v['title'],
  49. 'author'=>$v['author_name'],
  50. 'image_input'=>$v['thumbnail_pic_s'],
  51. 'create_time'=>$v['date'],
  52. 'status'=>1
  53. ];
  54. $urldetail='http://v.juhe.cn/toutiao/content';
  55. $paramdetail=[
  56. 'key'=>self::$key_tt,
  57. 'uniquekey'=>$v['uniquekey']
  58. ];
  59. $resultdetail=json_decode($this->curl($urldetail,$paramdetail,'post'),true);
  60. if(empty($resultdetail['result']['content'])){
  61. continue;
  62. }
  63. $id=Db::name('article')->insertGetId($insertData);
  64. $contentdata=[
  65. 'article_content_id'=>$id,
  66. 'content'=>$resultdetail['result']['content']
  67. ];
  68. Db::name('article_content')->insert($contentdata);
  69. }
  70. }
  71. return;
  72. }
  73. /**
  74. * 热门视频
  75. * author 爱代码的糖糖
  76. * time 2021 08 17 16:15:58
  77. */
  78. public function Getvideo()
  79. {
  80. $url='http://apis.juhe.cn/fapig/douyin/billboard';
  81. $param=[
  82. 'key'=>self::$key_sp,
  83. 'type'=>'hot_video',
  84. 'size'=>50,
  85. ];
  86. $data=json_decode($this->curl($url,$param,'post'),true);
  87. foreach ($data['result'] as $k=>$v){
  88. $insertData=[
  89. 'title'=>$v['title'],
  90. 'share_url'=>$v['share_url'],
  91. 'author'=>$v['author'],
  92. 'item_cover'=>$v['item_cover'],
  93. 'digg_count'=>$v['digg_count'],
  94. 'play_count'=>$v['play_count'],
  95. 'hot_value'=>$v['hot_value'],
  96. 'status'=>1,
  97. 'admin_id'=>1,
  98. ];
  99. Db::name('video')->insert($insertData);
  100. }
  101. return ;
  102. }
  103. //curl 请求
  104. public function curl($url , $data=array(),$option,$header=''){
  105. $ch = curl_init();//
  106. curl_setopt($ch, CURLOPT_URL, $url);//
  107. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  108. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  109. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  110. // POST数据
  111. if($option=='post'){
  112. curl_setopt($ch, CURLOPT_POST, 1);
  113. }
  114. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  115. $output = curl_exec($ch);
  116. curl_close($ch);
  117. return $output;
  118. }
  119. /**
  120. * APP获取新闻资讯
  121. * author 爱代码的糖糖
  122. * time 2021 08 17 17:00:15
  123. * 废弃
  124. */
  125. // public function getarticle()
  126. // {
  127. // $data=Db::name('article')
  128. // ->alias('a')
  129. // ->leftJoin('article_content ac','a.article_id=ac.article_content_id')
  130. // ->field('a.title,a.author,a.image_input,ac.content')
  131. // ->select()
  132. // ->toArray();
  133. // return app('json') -> success($data);
  134. //
  135. // }
  136. /**
  137. * APP获取热门视频
  138. * author 爱代码的糖糖
  139. * time 2021 08 17 17:04:19
  140. * param start 开始位置 默认0 limit 条数 默认10
  141. */
  142. public function getvideos()
  143. {
  144. try {
  145. [$page, $limit] = $this->getPage();
  146. $data=Db::name('video')
  147. ->withoutField('status,admin_id,mer_id')
  148. ->page($page, $limit)
  149. ->order("create_time desc")
  150. ->select()
  151. ->toArray();
  152. return app('json') -> success($data);
  153. }catch (\Throwable $e) {
  154. return app('json')->fail($e->getMessage());
  155. }
  156. }
  157. }