Web.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\model\system;
  11. use app\model\BaseModel;
  12. use think\facade\Cache;
  13. class Web extends BaseModel
  14. {
  15. private $url = "https://www.niushop.com/api/%s";
  16. public function __construct()
  17. {
  18. }
  19. /**
  20. * 官网资讯
  21. */
  22. public function news()
  23. {
  24. $cache = Cache::get("new_day");
  25. if (!empty($cache)) {
  26. return $cache;
  27. }
  28. $url = sprintf($this->url, 'news/news');
  29. $post_data = [
  30. ];
  31. $result = $this->doPost($url, $post_data);
  32. $res = json_decode($result, true);
  33. if ($res["code"] >= 0) {
  34. Cache::set("new_day", $res, 86400);
  35. }
  36. return $res;
  37. }
  38. /**
  39. * post 服务器请求
  40. */
  41. private function doPost($post_url, $post_data)
  42. {
  43. $ch = curl_init();
  44. curl_setopt($ch, CURLOPT_URL, $post_url);
  45. curl_setopt($ch, CURLOPT_HEADER, 0);
  46. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  47. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  48. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  49. if ($post_data != '' && !empty($post_data)) {
  50. curl_setopt($ch, CURLOPT_POST, 1);
  51. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  52. }
  53. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  54. $result = curl_exec($ch);
  55. curl_close($ch);
  56. return $result;
  57. }
  58. }