Browse Source

curl_request

master
林一峰 7 years ago
parent
commit
5e856a540a
  1. 2
      .env.example
  2. 8
      app/Common/function.php
  3. 1
      app/Http/Controllers/Api/ArticleController.php
  4. 17
      app/Http/Controllers/Weixin/IndexController.php
  5. 2
      app/Http/Model/Article.php
  6. 2
      resources/views/weixin/index/index.blade.php
  7. 6
      routes/web.php

2
.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

8
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
)
);

1
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;

17
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);
}

2
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);

2
resources/views/weixin/index/index.blade.php

@ -1,5 +1,5 @@
<!DOCTYPE html><html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>商城</title><meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
<title>商城</title><meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
<link href="<?php echo env('APP_URL'); ?>/css/weixin/style.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="<?php echo env('APP_WEIXIN_URL'); ?>/js/jquery.min.js"></script>
<meta name="keywords" content="关键词"><meta name="description" content="描述"></head><body>

6
routes/web.php

@ -16,7 +16,7 @@ Route::group(['domain' => env('APP_SUBDOMAIN'), 'namespace' => 'Wap'], function
Route::get('/', 'IndexController@index')->name('wap_home');
Route::get('/page404', 'IndexController@page404')->name('wap_page404'); //404页面
Route::get('/tags', 'IndexController@tags')->name('wap_tags');
Route::get('/search/{id}', 'IndexController@search')->name('wap_search'); //搜页面
Route::get('/search/{id}', 'IndexController@search')->name('wap_search'); //搜页面
Route::get('/p/{id}', 'IndexController@detail')->name('wap_detail'); //详情页
Route::get('/cat{cat}/{page}', 'IndexController@category'); //分类页,分页
Route::get('/cat{cat}', 'IndexController@category')->name('wap_category'); //分类页
@ -35,7 +35,7 @@ Route::group(['namespace' => 'Home'], function () {
Route::get('/', 'IndexController@index')->name('home');
Route::get('/page404', 'IndexController@page404')->name('page404'); //404页面
Route::get('/tags', 'IndexController@tags')->name('home_tags');
Route::get('/search/{id}', 'IndexController@search')->name('home_search'); //搜页面
Route::get('/search/{id}', 'IndexController@search')->name('home_search'); //搜页面
Route::get('/p/{id}', 'IndexController@detail')->name('home_detail'); //详情页
Route::get('/cat{cat}/{page}', 'IndexController@category'); //分类页,分页
Route::get('/cat{cat}', 'IndexController@category')->name('home_category'); //分类页
@ -58,7 +58,7 @@ Route::group(['prefix' => 'weixin', 'namespace' => 'Weixin'], function () {
Route::get('/', 'IndexController@index')->name('weixin');
Route::get('/page404', 'IndexController@page404')->name('weixin_page404'); //404页面
Route::get('/tags', 'IndexController@tags')->name('weixin_tags');
Route::get('/search/{id}', 'IndexController@search')->name('weixin_search'); //搜页面
Route::get('/search/{id}', 'IndexController@search')->name('weixin_search'); //搜页面
Route::get('/p/{id}', 'IndexController@detail')->name('weixin_article_detail'); //文章详情页
Route::get('/cat{cat}', 'IndexController@category')->name('weixin_article_category'); //分类页
Route::get('/tag{tag}', 'IndexController@tag')->name('weixin_tag'); //标签页

Loading…
Cancel
Save