From dd03e86257c7a47a566168c7571092559e87751a Mon Sep 17 00:00:00 2001 From: Helperhaps Date: Fri, 15 Dec 2017 09:28:07 +0000 Subject: [PATCH] add admin api --- examples/admin_example.php | 14 +++++++++++++ src/JPush/AdminClient.php | 42 ++++++++++++++++++++++++++++++++++++++ src/JPush/version.php | 2 +- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 examples/admin_example.php create mode 100644 src/JPush/AdminClient.php diff --git a/examples/admin_example.php b/examples/admin_example.php new file mode 100644 index 0000000..9b95551 --- /dev/null +++ b/examples/admin_example.php @@ -0,0 +1,14 @@ +createApp('aaa', 'cn.jpush.app'); +print_r($response); + +$appKey = $response['body']['app_key']; +$response = $admin->deleteApp($appKey); +print_r($response); diff --git a/src/JPush/AdminClient.php b/src/JPush/AdminClient.php new file mode 100644 index 0000000..cfe96fd --- /dev/null +++ b/src/JPush/AdminClient.php @@ -0,0 +1,42 @@ +devKey = $devKey; + $this->devSecret = $devSecret; + $this->retryTimes = 1; + $this->logFile = null; + } + + public function getAuthStr() { return $this->devKey . ":" . $this->devSecret; } + public function getRetryTimes() { return $this->retryTimes; } + public function getLogFile() { return $this->logFile; } + + public function createApp($appName, $androidPackage, $groupName=null) { + $url = AdminClient::ADMIN_URL; + $body = [ + 'app_name' => $appName, + 'android_package'=> $androidPackage, + 'group_name' => $groupName + + ]; + return Http::post($this, $url, $body); + } + + public function deleteApp($appKey) { + $url = AdminClient::ADMIN_URL . $appKey . '/delete'; + return Http::post($this, $url, []); + } +} diff --git a/src/JPush/version.php b/src/JPush/version.php index b85439d..8d970c1 100644 --- a/src/JPush/version.php +++ b/src/JPush/version.php @@ -1,4 +1,4 @@