Commit 81b5eb5c by 庄欣

旅拍城市

parent c73719d8
......@@ -2,7 +2,6 @@
namespace App\Http\Controllers\Category\Controller;
use App\Http\Controllers\ControllerBase;
use App\Lib\Client\CurlClient;
use App\Lib\Response\Response;
class Category extends ControllerBase
......@@ -34,9 +33,7 @@ class Category extends ControllerBase
{
try {
$client = app("client");
$client->setUrl($this->prefix."/$id/child");
$client->setMethod("get");
$res = $client->curl();
$res = $client->get($this->prefix."/".$id."/child");
return Response::success($res);
} catch (\Exception $e) {
return Response::error($e->getMessage());
......
......@@ -37,5 +37,16 @@ class City extends ControllerBase
return parent::show($id, $query, false);
}
public function travel()
{
empty($query) && $query = request()->getQueryString();
try {
$client = app("client");
$res = $client->get($this->prefix.'/travel'."?".$query);
return Response::success($res);
} catch (\Exception $e) {
return Response::error($e->getMessage());
}
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ namespace App\Http\Controllers;
use App\Exceptions\ApiNotFound;
use App\Exceptions\ApiUnauthorized;
use App\Lib\Client\CurlClient;
use App\Lib\Response\Response;
use \Illuminate\Http\Request;
use \Closure;
......@@ -20,7 +21,6 @@ class ControllerBase
{
public function getAuth()
{
return 3;
return request("uuid",3);
static $id;
if (!$id) {
......@@ -146,6 +146,7 @@ class ControllerBase
protected function isAllowed($id,$data = [])
{
return true;
$uid = $this->getAuth();
$result = false;
if (!empty($data)) {
......
......@@ -3,7 +3,7 @@
namespace App\Lib\Client;
use App\Lib\Response\HttpStatus;
use Illuminate\Http\Request;
class CurlClient
{
......@@ -12,9 +12,9 @@ class CurlClient
protected $config;
protected $data;
protected $url;
private $format = "JSON";
private $format = "";
protected $header = [];
protected $base;
protected $base = "http://api.yuepai.com/";
protected $Exceptions = [
HttpStatus::HttpNotFound => \App\Exceptions\ApiNotFound::class,
......@@ -25,10 +25,6 @@ class CurlClient
HttpStatus::HttpTimeout => \App\Exceptions\ApiTimeout::class,
];
public function __construct($header = [])
{
$this->base = config("app.apiurl");
}
public function setUrl($url)
{
......@@ -98,14 +94,15 @@ class CurlClient
curl_setopt($http, CURLOPT_POSTFIELDS, $this->data);
}
$res = curl_exec($http);
$curlinfo = curl_getinfo($http);
curl_close($http);
if ($curlinfo == false || (is_array($curlinfo) && $curlinfo['http_code'] != 200)) {
unset($http);
if ($res == false) {
throw new \Exception("服务器无反应,请稍候再试");
}
$res = json_decode($res);
if (json_last_error() > 0) {
throw new \Exception(json_last_error_msg());
var_dump($this->base.$this->url);
var_dump($res);
throw new \Exception("数据解析错误");
}
if ($res->code >= 200 && $res->code < 400) {
return $res->data;
......
......@@ -71,7 +71,7 @@ class RouteServiceProvider extends ServiceProvider
*/
protected function mapApiRoutes()
{
self::$Version = request("v",1);
self::$Version = 1;
require base_path('routes/api.php');
}
}
......@@ -8,7 +8,8 @@
"php": ">=5.6.4",
"laravel/framework": "5.3.*",
"upyun/sdk": "^2.2",
"endroid/qrcode": "^1.7"
"endroid/qrcode": "^1.7",
"php-curl-class/php-curl-class": "^7.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
......
......@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "85dcd43d8857b90493159b1eb4533486",
"content-hash": "f7b64f068d4ca676e77d98c96c95bff2",
"hash": "bf734e2a443fd6298851f4354ee7daaf",
"content-hash": "975b80f43c6b5437ccbd947576a2033a",
"packages": [
{
"name": "classpreloader/classpreloader",
......@@ -837,6 +837,63 @@
"time": "2016-04-03 06:00:07"
},
{
"name": "php-curl-class/php-curl-class",
"version": "7.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-curl-class/php-curl-class.git",
"reference": "459231fae786dea2b10c373e763faac7f65e178c"
},
"dist": {
"type": "zip",
"url": "https://packagist.phpcomposer.com/files/php-curl-class/php-curl-class/459231fae786dea2b10c373e763faac7f65e178c.zip",
"reference": "459231fae786dea2b10c373e763faac7f65e178c",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.3"
},
"require-dev": {
"phpunit/phpunit": "*",
"squizlabs/php_codesniffer": "*"
},
"type": "library",
"autoload": {
"psr-4": {
"Curl\\": "src/Curl/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Unlicense"
],
"authors": [
{
"name": "Zach Borboa"
}
],
"description": "PHP Curl Class is an object-oriented wrapper of the PHP cURL extension.",
"homepage": "https://github.com/php-curl-class/php-curl-class",
"keywords": [
"api",
"class",
"client",
"curl",
"framework",
"http",
"http client",
"json",
"php",
"requests",
"rest",
"restful",
"web service",
"xml"
],
"time": "2016-09-27 07:35:34"
},
{
"name": "psr/log",
"version": "1.0.1",
"source": {
......
......@@ -129,6 +129,8 @@ Route::group(["prefix" => "category", 'namespace' => Provider::getNamespace("cat
Route::group(["prefix" => "city", 'namespace' => Provider::getNamespace("city")],function() {
//列表
Route::get("/", "City@index");
Route::get("/travel", "City@travel");
//上一级信息
Route::get("/{id}/parent","City@getParent");
//获取详细信息
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment