Skip to content

Commit dd03e86

Browse files
author
Helperhaps
committed
add admin api
1 parent 921b491 commit dd03e86

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

examples/admin_example.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
// 这只是使用样例,不应该直接用于实际生产环境中 !!
3+
4+
require 'config.php';
5+
6+
use JPush\AdminClient as Admin;
7+
8+
$admin = new Admin($dev_key, $dev_secret);
9+
$response = $admin->createApp('aaa', 'cn.jpush.app');
10+
print_r($response);
11+
12+
$appKey = $response['body']['app_key'];
13+
$response = $admin->deleteApp($appKey);
14+
print_r($response);

src/JPush/AdminClient.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
namespace JPush;
3+
4+
class AdminClient {
5+
6+
const ADMIN_URL = 'https://admin.jpush.cn/v1/app/';
7+
8+
private $devKey;
9+
private $devSecret;
10+
private $retryTimes;
11+
private $logFile;
12+
13+
function __construct($devKey, $devSecret) {
14+
if (!is_string($devKey) || !is_string($devSecret)) {
15+
throw new InvalidArgumentException("Invalid devKey or devSecret");
16+
}
17+
$this->devKey = $devKey;
18+
$this->devSecret = $devSecret;
19+
$this->retryTimes = 1;
20+
$this->logFile = null;
21+
}
22+
23+
public function getAuthStr() { return $this->devKey . ":" . $this->devSecret; }
24+
public function getRetryTimes() { return $this->retryTimes; }
25+
public function getLogFile() { return $this->logFile; }
26+
27+
public function createApp($appName, $androidPackage, $groupName=null) {
28+
$url = AdminClient::ADMIN_URL;
29+
$body = [
30+
'app_name' => $appName,
31+
'android_package'=> $androidPackage,
32+
'group_name' => $groupName
33+
34+
];
35+
return Http::post($this, $url, $body);
36+
}
37+
38+
public function deleteApp($appKey) {
39+
$url = AdminClient::ADMIN_URL . $appKey . '/delete';
40+
return Http::post($this, $url, []);
41+
}
42+
}

src/JPush/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
22
namespace JPush;
33

4-
const VERSION = '3.5.23';
4+
const VERSION = '3.5.24';

0 commit comments

Comments
 (0)