From 2bb4110990e4e1a1b0d911b9d618f59380aac3e8 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Tue, 18 Apr 2017 13:22:15 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E4=BC=98=E5=8C=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BD=93=E9=AA=8C=EF=BC=8C=E5=AE=8C=E5=96=84JPush=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Admin/View/ApiManage/index.html | 2 +- Application/Home/ORG/ApiLog.class.php | 22 ++++++++---- Application/Home/ORG/JPush/Push.class.php | 38 ++++++++++----------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/Application/Admin/View/ApiManage/index.html b/Application/Admin/View/ApiManage/index.html index e4ad516..8b50e13 100644 --- a/Application/Admin/View/ApiManage/index.html +++ b/Application/Admin/View/ApiManage/index.html @@ -22,7 +22,7 @@ {$i} {$vo['apiName']} - {$vo['hash']} + {$vo['hash']} 生效 diff --git a/Application/Home/ORG/ApiLog.class.php b/Application/Home/ORG/ApiLog.class.php index 2bbca22..6f25db3 100644 --- a/Application/Home/ORG/ApiLog.class.php +++ b/Application/Home/ORG/ApiLog.class.php @@ -9,12 +9,13 @@ namespace Home\ORG; class ApiLog { - private static $appInfo = null; - private static $apiInfo = null; - private static $request = null; - private static $requestAfterFilter = null; - private static $response = null; - private static $header = null; + private static $appInfo = 'null'; + private static $apiInfo = 'null'; + private static $request = 'null'; + private static $requestAfterFilter = 'null'; + private static $response = 'null'; + private static $header = 'null'; + private static $userInfo = 'null'; public static function setAppInfo($data) { self::$appInfo = $data['app_id'] . "({$data['app_name']}) {$data['device_id']}"; @@ -30,6 +31,13 @@ class ApiLog { self::$apiInfo = $data['apiName'] . ' ' . $data['hash']; } + public static function setUserInfo($data) { + if (is_array($data)) { + $data = json_encode($data); + } + self::$userInfo = $data; + } + public static function setRequest($data) { if (is_array($data)) { $data = json_encode($data); @@ -54,7 +62,7 @@ class ApiLog { public static function save() { $logPath = APP_PATH . '/ApiLog/' . date('YmdH') . '.log'; $logStr = self::$apiInfo . ' ' . date('H:i:s') . ' ' . self::$request . ' ' . self::$header . ' ' - . self::$response . ' ' . self::$requestAfterFilter . ' ' . self::$appInfo."\n"; + . self::$response . ' ' . self::$requestAfterFilter . ' ' . self::$appInfo.' '.self::$userInfo."\n"; @file_put_contents($logPath, $logStr, FILE_APPEND); } diff --git a/Application/Home/ORG/JPush/Push.class.php b/Application/Home/ORG/JPush/Push.class.php index 75782d1..90c0753 100644 --- a/Application/Home/ORG/JPush/Push.class.php +++ b/Application/Home/ORG/JPush/Push.class.php @@ -221,9 +221,11 @@ class Push { * @author zhaoxiang * @return $this */ - public function iosNotification($alert, $notification = array()) { + public function iosNotification($alert = null, $notification = array()) { $ios = array(); - $ios['alert'] = (is_string($alert) || is_array($alert)) ? $alert : ''; + if (!is_null($alert)) { + $ios['alert'] = (is_string($alert) || is_array($alert)) ? $alert : ''; + } if (!empty($notification)) { if (isset($notification['sound']) && is_string($notification['sound'])) { $ios['sound'] = $notification['sound']; @@ -262,9 +264,11 @@ class Push { * @author zhaoxiang * @return $this */ - public function androidNotification($alert, array $notification = array()) { + public function androidNotification($alert = null, array $notification = array()) { $android = array(); - $android['alert'] = is_string($alert) ? $alert : ''; + if (!is_null($alert)) { + $android['alert'] = is_string($alert) ? $alert : ''; + } if (!empty($notification)) { if (isset($notification['title']) && is_string($notification['title'])) { $android['title'] = $notification['title']; @@ -394,43 +398,39 @@ class Push { if (is_null($this->androidNotification['alert'])) { if (is_null($this->notificationAlert)) { Response::error(ReturnCode::EXCEPTION, 'Android alert can not be null'); - } else { - $notification['android']['alert'] = $this->notificationAlert; } - } - } else { - if (!is_null($this->extras)) { - $notification['android']['extras'] = $this->extras; + } else { + $notification['android']['alert'] = $this->androidNotification['alert']; } } + if (!is_null($this->extras)) { + $notification['android']['extras'] = $this->extras; + } + if (!is_null($this->iosNotification)) { $notification['ios'] = $this->iosNotification; if (is_null($this->iosNotification['alert'])) { if (is_null($this->notificationAlert)) { Response::error(ReturnCode::EXCEPTION, 'iOS alert can not be null'); - } else { - $notification['ios']['alert'] = $this->notificationAlert; } + } else { + $notification['ios']['alert'] = $this->iosNotification['alert']; } - } else { - if (!is_null($this->extras)) { - $notification['ios']['extras'] = $this->extras; - } + } + if (!is_null($this->extras)) { + $notification['ios']['extras'] = $this->extras; } if (count($notification) > 0) { $payload['notification'] = $notification; } - if (count($this->message) > 0) { $payload['message'] = $this->message; } - if (!array_key_exists('notification', $payload) && !array_key_exists('message', $payload)) { Response::error(ReturnCode::EXCEPTION, 'notification and message can not all be null'); } - if (!is_null($this->options)) { $payload['options'] = $this->options; }