|
@@ -1,13 +1,5 @@
|
|
|
<?php
|
|
|
-require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/android/AndroidBroadcast.php');
|
|
|
-require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/android/AndroidFilecast.php');
|
|
|
-require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/android/AndroidGroupcast.php');
|
|
|
-require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/android/AndroidUnicast.php');
|
|
|
require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/android/AndroidCustomizedcast.php');
|
|
|
-require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/ios/IOSBroadcast.php');
|
|
|
-require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/ios/IOSFilecast.php');
|
|
|
-require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/ios/IOSGroupcast.php');
|
|
|
-require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/ios/IOSUnicast.php');
|
|
|
require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/ios/IOSCustomizedcast.php');
|
|
|
|
|
|
class push_app {
|
|
@@ -15,129 +7,62 @@ class push_app {
|
|
|
protected $appMasterSecret = NULL;
|
|
|
protected $timestamp = NULL;
|
|
|
protected $validation_token = NULL;
|
|
|
+ protected $alias_type = 'LRLZ';
|
|
|
+ protected $androd_appkey = '5631efd4e0f55a8770000027';
|
|
|
+ protected $androd_appmastersecret = 'r6w2a8z9x8zonh7qmk8ds2fvypu02wpj';
|
|
|
+ protected $ios_appkey = '568b6727e0f55a06580011e7';
|
|
|
+ protected $ios_appmastersecret = 'q9rmi5zjvfpvkwauenbgvhnmdsqdjeso';
|
|
|
|
|
|
- function __construct($key, $secret) {
|
|
|
- $this->appkey = $key;
|
|
|
- $this->appMasterSecret = $secret;
|
|
|
+ function __construct() {
|
|
|
$this->timestamp = strval(time());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- function sendAndroidUnicast() {
|
|
|
- try {
|
|
|
- $unicast = new AndroidUnicast();
|
|
|
- $unicast->setAppMasterSecret($this->appMasterSecret);
|
|
|
- $unicast->setPredefinedKeyValue("appkey", $this->appkey);
|
|
|
- $unicast->setPredefinedKeyValue("timestamp", $this->timestamp);
|
|
|
- // Set your device tokens here
|
|
|
- $unicast->setPredefinedKeyValue("device_tokens", "Aj9AympPsCha5zmPhrV0DbnOZJYF0pqKY5jdKvFy_Hbu");
|
|
|
- $unicast->setPredefinedKeyValue("ticker", "Android unicast ticker");
|
|
|
- $unicast->setPredefinedKeyValue("title", "Android unicast title");
|
|
|
- $unicast->setPredefinedKeyValue("text", "Android unicast text");
|
|
|
- $unicast->setPredefinedKeyValue("after_open", "go_app");
|
|
|
- // Set 'production_mode' to 'false' if it's a test device.
|
|
|
- // For how to register a test device, please see the developer doc.
|
|
|
- $unicast->setPredefinedKeyValue("production_mode", "true");
|
|
|
- // Set extra fields
|
|
|
- $unicast->setExtraField("test", "helloworld");
|
|
|
- print("Sending unicast notification, please wait...\r\n");
|
|
|
- $unicast->send();
|
|
|
- print("Sent SUCCESS\r\n");
|
|
|
- } catch (Exception $e) {
|
|
|
- print("Caught exception: " . $e->getMessage());
|
|
|
+ public function setAliasType($value){
|
|
|
+ if(!empty($value)){
|
|
|
+ $this->alias_type = $value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- function sendAndroidCustomizedcast() {
|
|
|
- try {
|
|
|
+ function sendAndroidCustomizedcast(array $pushinfo) {
|
|
|
$customizedcast = new AndroidCustomizedcast();
|
|
|
$customizedcast->setAppMasterSecret($this->appMasterSecret);
|
|
|
- $customizedcast->setPredefinedKeyValue("appkey", $this->appkey);
|
|
|
- $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
|
|
|
+ $customizedcast->setPredefinedKeyValue("appkey", $this->androd_appkey);
|
|
|
+ $customizedcast->setPredefinedKeyValue("timestamp", $this->androd_appmastersecret);
|
|
|
// Set your alias here, and use comma to split them if there are multiple alias.
|
|
|
// And if you have many alias, you can also upload a file containing these alias, then
|
|
|
// use file_id to send customized notification.
|
|
|
- $customizedcast->setPredefinedKeyValue("alias", "36489");
|
|
|
+ $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
|
|
|
// Set your alias_type here
|
|
|
- $customizedcast->setPredefinedKeyValue("alias_type", "LRLZ");
|
|
|
- $customizedcast->setPredefinedKeyValue("ticker", "Android te ticker");
|
|
|
- $customizedcast->setPredefinedKeyValue("title", "Android te title");
|
|
|
- $customizedcast->setPredefinedKeyValue("text", "Android te text");
|
|
|
+ $customizedcast->setPredefinedKeyValue("alias_type", $this->alias_type);
|
|
|
+ $customizedcast->setPredefinedKeyValue("ticker", $pushinfo['text']);
|
|
|
+ $customizedcast->setPredefinedKeyValue("title", $pushinfo['text']);
|
|
|
+ $customizedcast->setPredefinedKeyValue("text", $pushinfo['text']);
|
|
|
$customizedcast->setPredefinedKeyValue("after_open", "go_app");
|
|
|
- print("Sending customizedcast notification, please wait...\r\n");
|
|
|
- $customizedcast->send();
|
|
|
- print("Sent SUCCESS\r\n");
|
|
|
- } catch (Exception $e) {
|
|
|
- print("Caught exception: " . $e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- function sendIOSUnicast() {
|
|
|
- try {
|
|
|
- $unicast = new IOSUnicast();
|
|
|
- $unicast->setAppMasterSecret($this->appMasterSecret);
|
|
|
- $unicast->setPredefinedKeyValue("appkey", $this->appkey);
|
|
|
- $unicast->setPredefinedKeyValue("timestamp", $this->timestamp);
|
|
|
- // Set your device tokens here
|
|
|
- $unicast->setPredefinedKeyValue("device_tokens", "xx");
|
|
|
- $unicast->setPredefinedKeyValue("alert", "IOS 单播测试");
|
|
|
- $unicast->setPredefinedKeyValue("badge", 0);
|
|
|
- $unicast->setPredefinedKeyValue("sound", "chime");
|
|
|
- // Set 'production_mode' to 'true' if your app is under production mode
|
|
|
- $unicast->setPredefinedKeyValue("production_mode", "false");
|
|
|
- // Set customized fields
|
|
|
- $unicast->setCustomizedField("test", "helloworld");
|
|
|
- print("Sending unicast notification, please wait...\r\n");
|
|
|
- $unicast->send();
|
|
|
- print("Sent SUCCESS\r\n");
|
|
|
- } catch (Exception $e) {
|
|
|
- print("Caught exception: " . $e->getMessage());
|
|
|
- }
|
|
|
+ return $customizedcast->send();
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- function sendIOSCustomizedcast() {
|
|
|
- try {
|
|
|
+ function sendIOSCustomizedcast(array $pushinfo) {
|
|
|
$customizedcast = new IOSCustomizedcast();
|
|
|
$customizedcast->setAppMasterSecret($this->appMasterSecret);
|
|
|
- $customizedcast->setPredefinedKeyValue("appkey", $this->appkey);
|
|
|
- $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
|
|
|
+ $customizedcast->setPredefinedKeyValue("appkey", $this->ios_appkey);
|
|
|
+ $customizedcast->setPredefinedKeyValue("timestamp", $this->ios_appmastersecret);
|
|
|
|
|
|
// Set your alias here, and use comma to split them if there are multiple alias.
|
|
|
// And if you have many alias, you can also upload a file containing these alias, then
|
|
|
// use file_id to send customized notification.
|
|
|
- $customizedcast->setPredefinedKeyValue("alias", "xx");
|
|
|
+ $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
|
|
|
// Set your alias_type here
|
|
|
- $customizedcast->setPredefinedKeyValue("alias_type", "xx");
|
|
|
- $customizedcast->setPredefinedKeyValue("alert", "IOS 个性化测试");
|
|
|
+ $customizedcast->setPredefinedKeyValue("alias_type", 'kPandaMakeUpAlias');
|
|
|
+ $customizedcast->setPredefinedKeyValue("alert", $pushinfo['text']);
|
|
|
$customizedcast->setPredefinedKeyValue("badge", 0);
|
|
|
$customizedcast->setPredefinedKeyValue("sound", "chime");
|
|
|
// Set 'production_mode' to 'true' if your app is under production mode
|
|
|
$customizedcast->setPredefinedKeyValue("production_mode", "false");
|
|
|
- print("Sending customizedcast notification, please wait...\r\n");
|
|
|
- $customizedcast->send();
|
|
|
- print("Sent SUCCESS\r\n");
|
|
|
- } catch (Exception $e) {
|
|
|
- print("Caught exception: " . $e->getMessage());
|
|
|
- }
|
|
|
+ return $customizedcast->send();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Set your appkey and master secret here
|
|
|
-$demo = new push_app("5631efd4e0f55a8770000027", "r6w2a8z9x8zonh7qmk8ds2fvypu02wpj");
|
|
|
-$demo->sendAndroidCustomizedcast();
|
|
|
-/* these methods are all available, just fill in some fields and do the test
|
|
|
- * $demo->sendAndroidBroadcast();
|
|
|
- * $demo->sendAndroidFilecast();
|
|
|
- * $demo->sendAndroidGroupcast();
|
|
|
- * $demo->sendAndroidCustomizedcast();
|
|
|
- *
|
|
|
- * $demo->sendIOSBroadcast();
|
|
|
- * $demo->sendIOSUnicast();
|
|
|
- * $demo->sendIOSFilecast();
|
|
|
- * $demo->sendIOSGroupcast();
|
|
|
- * $demo->sendIOSCustomizedcast();
|
|
|
- */
|
|
|
+$demo = new push_app();
|
|
|
+$demo->sendIOSCustomizedcast(array('member_id'=>'36485','text'=>'ddddddddd'));
|