Skip to content

Commit

Permalink
add admin api
Browse files Browse the repository at this point in the history
  • Loading branch information
Helperhaps committed Dec 15, 2017
1 parent 921b491 commit dd03e86
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
14 changes: 14 additions & 0 deletions examples/admin_example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
// 这只是使用样例,不应该直接用于实际生产环境中 !!

require 'config.php';

use JPush\AdminClient as Admin;

$admin = new Admin($dev_key, $dev_secret);
$response = $admin->createApp('aaa', 'cn.jpush.app');
print_r($response);

$appKey = $response['body']['app_key'];
$response = $admin->deleteApp($appKey);
print_r($response);
42 changes: 42 additions & 0 deletions src/JPush/AdminClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
namespace JPush;

class AdminClient {

const ADMIN_URL = 'https://admin.jpush.cn/v1/app/';

private $devKey;
private $devSecret;
private $retryTimes;
private $logFile;

function __construct($devKey, $devSecret) {
if (!is_string($devKey) || !is_string($devSecret)) {
throw new InvalidArgumentException("Invalid devKey or devSecret");
}
$this->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, []);
}
}
2 changes: 1 addition & 1 deletion src/JPush/version.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
namespace JPush;

const VERSION = '3.5.23';
const VERSION = '3.5.24';

0 comments on commit dd03e86

Please sign in to comment.