news.php 879 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. $url = 'https://way.jd.com/jisuapi/get?channel=头条&num=10&start=0&appkey=e61ea08206439db9cb30910865faad7c';
  3. $resp = ihttp_get($url);
  4. if (200 == $resp['code'] && $resp['content']) {
  5. $obj = json_decode($resp['content'], true);
  6. if (empty($obj['result']) || empty($obj['result']['result']) || empty($obj['result']['result']['num'])) {
  7. return $this->respText('没有找到结果, 要不过一会再试试?');
  8. }
  9. $num = $obj['result']['result']['num'];
  10. $data = $obj['result']['result']['list'];
  11. $sum = 0;
  12. for ($i = 0; $i < $num; ++$i) {
  13. if (empty($data[$i]['pic']) || $sum >= 8) {
  14. continue;
  15. }
  16. $news[] = array(
  17. 'title' => strval($data[$i]['title']),
  18. 'picurl' => strval($data[$i]['pic']),
  19. 'url' => strval($data[$i]['url']),
  20. );
  21. ++$sum;
  22. }
  23. return $this->respNews($news);
  24. }
  25. return $this->respText('没有找到结果, 要不过一会再试试?');