From fdd1b65eba3140dba7d9a34c6850fd82f5d73397 Mon Sep 17 00:00:00 2001 From: wispx <1591788658@qq.com> Date: Fri, 7 Dec 2018 16:49:57 +0800 Subject: [PATCH] up --- application/index/controller/admin/Images.php | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/application/index/controller/admin/Images.php b/application/index/controller/admin/Images.php index 2013bcaf..5428c124 100644 --- a/application/index/controller/admin/Images.php +++ b/application/index/controller/admin/Images.php @@ -11,6 +11,7 @@ namespace app\index\controller\admin; use app\common\model\Images as ImagesModel; use app\common\model\Users; use GuzzleHttp\Client; +use GuzzleHttp\Exception\RequestException; use think\facade\Config; use think\Db; use think\Exception; @@ -115,16 +116,23 @@ class Images extends Base public function getIpInfo() { if ($this->request->isPost()) { - $ip = $this->request->post('ip'); - $client = new Client(); - $response = $client->get('http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip); - if ($response->getStatusCode() == 200) { - $data = json_decode($response->getBody()->getContents(), true); - if (isset($data['code']) && $data['code'] == 0) { - return $this->success('获取成功', null, isset($data['data']) ? $data['data'] : null); + try { + $data = null; + $ip = $this->request->post('ip'); + $client = new Client(); + $response = $client->get('http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip); + if ($response->getStatusCode() == 200) { + $data = json_decode($response->getBody()->getContents(), true); + if (isset($data['code']) && $data['code'] == 0) { + $data = isset($data['data']) ? $data['data'] : null; + } } + } catch (Exception $e) { + return $this->error('获取失败'); + } catch (RequestException $e) { + return $this->error('淘宝接口异常'); } - return $this->error('获取失败'); + return $this->success('获取成功', null, $data); } } }