瀏覽代碼

ios push test

tiams@foxmail.com 9 年之前
父節點
當前提交
c933e5077f
共有 2 個文件被更改,包括 64 次插入58 次删除
  1. 0 4
      crontab/index.php
  2. 64 54
      helper/push_app.php

+ 0 - 4
crontab/index.php

@@ -6,10 +6,6 @@
  * 计划任务触发 by abc.com
  */
 
-
-$_SERVER['argv'][1] = $_GET['act'];
-@$_SERVER['argv'][2] = $_GET['op'];
-
 if (empty($_SERVER['argv'][1])) exit('Access Invalid!');
 
 define('APP_ID','crontab');

+ 64 - 54
helper/push_app.php

@@ -2,67 +2,77 @@
 require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/android/AndroidCustomizedcast.php');
 require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/ios/IOSCustomizedcast.php');
 
-class push_app {
-	protected $appkey           = NULL; 
-	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';
+class push_app
+{
+    protected $appkey = NULL;
+    protected $appMasterSecret = NULL;
+    protected $timestamp = NULL;
+    protected $validation_token = NULL;
+    protected $alias_type = 'LRLZ';
+    protected $ios_alias_type = 'kPandaMakeUpAlias';
+    protected $androd_appkey = '5631efd4e0f55a8770000027';
+    protected $androd_appmastersecret = 'r6w2a8z9x8zonh7qmk8ds2fvypu02wpj';
+    protected $ios_appkey = '568b6727e0f55a06580011e7';
+    protected $ios_appmastersecret = 'q9rmi5zjvfpvkwauenbgvhnmdsqdjeso';
 
-	function __construct() {
-		$this->timestamp = strval(time());
-	}
+    function __construct()
+    {
+        $this->timestamp = strval(time());
+    }
 
-	public function setAliasType($value){
-		if(!empty($value)){
-			$this->alias_type = $value;
-		}
-	}
+    public function setAliasType($value)
+    {
+        if (!empty($value)) {
+            $this->alias_type = $value;
+        }
+    }
 
-	function sendAndroidCustomizedcast(array $pushinfo) {
-			$customizedcast = new AndroidCustomizedcast();
-			$customizedcast->setAppMasterSecret($this->appMasterSecret);
-			$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",            $pushinfo['member_id']);
-			// Set your alias_type here
-			$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");
-		    return $customizedcast->send();
-	}
+    function sendAndroidCustomizedcast(array $pushinfo)
+    {
+        $customizedcast = new AndroidCustomizedcast();
+        $customizedcast->setAppMasterSecret($this->androd_appmastersecret);
+        $customizedcast->setPredefinedKeyValue("appkey", $this->androd_appkey);
+        $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
+        // 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", $pushinfo['member_id']);
+        // Set your alias_type here
+        $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");
+        return $customizedcast->send();
+    }
 
 
-	function sendIOSCustomizedcast(array $pushinfo) {
-			$customizedcast = new IOSCustomizedcast();
-			$customizedcast->setAppMasterSecret($this->appMasterSecret);
-			$customizedcast->setPredefinedKeyValue("appkey",           $this->ios_appkey);
-			$customizedcast->setPredefinedKeyValue("timestamp",        $this->ios_appmastersecret);
+    function sendIOSCustomizedcast(array $pushinfo)
+    {
+        try {
+            $customizedcast = new IOSCustomizedcast();
+            $customizedcast->setAppMasterSecret($this->ios_appmastersecret);
+            $customizedcast->setPredefinedKeyValue("appkey", $this->ios_appkey);
+            $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
 
-			// 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", $pushinfo['member_id']);
-			// Set your alias_type here
-			$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");
-			return $customizedcast->send();
-	}
+            // 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", $pushinfo['member_id']);
+            // Set your alias_type here
+            $customizedcast->setPredefinedKeyValue("alias_type", $this->ios_alias_type);
+            $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");
+            return $customizedcast->send();
+        } catch (Exception $e) {
+            print("Caught exception: " . $e->getMessage());
+        }
+    }
 }
 
 // Set your appkey and master secret here
 $demo = new push_app();
-$demo->sendIOSCustomizedcast(array('member_id'=>'36485','text'=>'ddddddddd'));
+$demo->sendIOSCustomizedcast(array('member_id' => '36485', 'text' => 'ddddddddd'));