From 5e856a540a27e2c99840ee13ec26ef7c83e0de33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=80=E5=B3=B0?= <1feng.0595@gmail.com> Date: Tue, 26 Sep 2017 00:26:52 +0800 Subject: [PATCH] curl_request --- .env.example | 2 +- app/Common/function.php | 8 +++----- app/Http/Controllers/Api/ArticleController.php | 1 + app/Http/Controllers/Weixin/IndexController.php | 17 ++++++++--------- app/Http/Model/Article.php | 2 +- resources/views/weixin/index/index.blade.php | 2 +- routes/web.php | 6 +++--- 7 files changed, 18 insertions(+), 20 deletions(-) diff --git a/.env.example b/.env.example index e931227..740cabd 100644 --- a/.env.example +++ b/.env.example @@ -3,7 +3,7 @@ APP_ENV=local APP_KEY=base64:KcBF6sf3T6Pv8CsflCK93UT6j7Xh6Zdyj+/H1XG1WYc= APP_DEBUG=true APP_LOG_LEVEL=debug -APP_URL=http://localhost +APP_URL=http://www.lqycms.com APP_DOMAIN=www.lqycms.com APP_SUBDOMAIN=m.lqycms.com APP_API_URL=http://www.lqycms.com/dataapi diff --git a/app/Common/function.php b/app/Common/function.php index fa0c2f1..cf93616 100644 --- a/app/Common/function.php +++ b/app/Common/function.php @@ -2,7 +2,7 @@ // 公共函数文件 if (! function_exists('curl_request')) { - function curl_request($api, $method = 'GET', $params = array(), $headers = array()) + function curl_request($api, $params = array(), $method = 'GET', $headers = array()) { $curl = curl_init(); @@ -29,7 +29,7 @@ if (! function_exists('curl_request')) curl_setopt($curl, CURLOPT_POSTFIELDS, $params); break; } - + curl_setopt($curl, CURLOPT_URL, $api); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); @@ -865,9 +865,7 @@ function http_request_post($url,$data,$type='POST') $options = array( 'http' => array( 'method' => $type, - 'header' => - "Content-type: application/x-www-form-urlencoded\r\n" . - "Content-length: $content_length\r\n", + 'header' => "Content-type: application/x-www-form-urlencoded\r\n" . "Content-length: $content_length\r\n", 'content' => $content ) ); diff --git a/app/Http/Controllers/Api/ArticleController.php b/app/Http/Controllers/Api/ArticleController.php index 4c10a8a..aec6265 100644 --- a/app/Http/Controllers/Api/ArticleController.php +++ b/app/Http/Controllers/Api/ArticleController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Api\CommonController; use Illuminate\Http\Request; +use Log; use App\Common\ReturnData; use App\Http\Model\Article; diff --git a/app/Http/Controllers/Weixin/IndexController.php b/app/Http/Controllers/Weixin/IndexController.php index 7111c12..e1a946a 100644 --- a/app/Http/Controllers/Weixin/IndexController.php +++ b/app/Http/Controllers/Weixin/IndexController.php @@ -20,7 +20,7 @@ class IndexController extends CommonController 'offset' => 0 ); $url = env('APP_API_URL')."/slide_list"; - $slide_list = json_decode(http_request_post($url,$postdata,'GET'),true); + $slide_list = json_decode(curl_request($url,$postdata,'GET'),true); $data['slide_list'] = $slide_list['data']['list']; //最新资讯 @@ -29,7 +29,7 @@ class IndexController extends CommonController 'offset' => 0 ); $url = env('APP_API_URL')."/article_list"; - $article_list = json_decode(http_request_post($url,$postdata,'GET'),true); + $article_list = json_decode(curl_request($url,$postdata,'GET'),true); $data['article_list'] = $article_list['data']['list']; //商品列表 @@ -38,7 +38,7 @@ class IndexController extends CommonController 'offset' => 0 ); $url = env('APP_API_URL')."/goods_list"; - $goods_list = json_decode(http_request_post($url,$postdata,'GET'),true); + $goods_list = json_decode(curl_request($url,$postdata,'GET'),true); $data['goods_list'] = $goods_list['data']['list']; return view('weixin.index.index',$data); @@ -84,15 +84,14 @@ class IndexController extends CommonController //文章详情页 public function detail($id) { - //文章详情 + //最新资讯 $postdata = array( - 'id' => $id, - 'aa' => 1 + 'id' => $id ); $url = env('APP_API_URL')."/article_detail"; - $article_detail = json_decode(http_request_post($url,$postdata,'GET'),true);dd(http_request_post($url,$postdata,'GET')); - //if(empty($article_detail['data'])){return redirect()->route('weixin_page404');} - //$data['article_detail'] = $article_detail['data']; + $article_detail = curl_request($url,$postdata,'GET'); + if(empty($article_detail['data'])){return redirect()->route('weixin_page404');} + $data['post'] = $article_detail['data']; return view('weixin.index.detail', $data); } diff --git a/app/Http/Model/Article.php b/app/Http/Model/Article.php index 96394c9..ba2dcc7 100644 --- a/app/Http/Model/Article.php +++ b/app/Http/Model/Article.php @@ -103,7 +103,7 @@ class Article extends BaseModel return $res; } - public static function getOne($param) + public static function getOne(array $param) { extract($param); diff --git a/resources/views/weixin/index/index.blade.php b/resources/views/weixin/index/index.blade.php index da40e13..5f11a38 100644 --- a/resources/views/weixin/index/index.blade.php +++ b/resources/views/weixin/index/index.blade.php @@ -1,5 +1,5 @@
-