人人商城

news.php 874B

123456789101112131415161718192021222324252627
  1. <?php
  2. $url = 'https://way.jd.com/jisuapi/get?channel=头条&num=10&start=0&appkey=f8a020a5d840f7a24997c9561b7d3da3';
  3. $resp = ihttp_get($url);
  4. if ($resp['code'] == 200 && $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('没有找到结果, 要不过一会再试试?');