瀏覽代碼

yumeng push 修改逻辑

tiams@foxmail.com 9 年之前
父節點
當前提交
cd5d2818d6

+ 1 - 1
data/api/notification/UmengNotification.php

@@ -87,7 +87,7 @@ abstract class UmengNotification {
         $curlErrNo = curl_errno($ch);
         $curlErr = curl_error($ch);
         curl_close($ch);
-        print($result . "\r\n");
+     //   print($result . "\r\n");
         if ($httpCode == "0") {
           	 // Time out
            	throw new Exception("Curl error number:" . $curlErrNo . " , Curl error details:" . $curlErr . "\r\n");

+ 1 - 1
data/api/notification/android/AndroidCustomizedcast.php

@@ -44,7 +44,7 @@ class AndroidCustomizedcast extends AndroidNotification {
         $curlErrNo = curl_errno($ch);
         $curlErr = curl_error($ch); 
         curl_close($ch);
-        print($result."\r\n");
+        //print($result."\r\n");
         if ($httpCode == "0") //time out 
         	throw new Exception("Curl error number:" . $curlErrNo . " , Curl error details:" . $curlErr . "\r\n");
         else if ($httpCode != "200") //we did send the notifition out and got a non-200 response

+ 1 - 1
data/api/notification/android/AndroidFilecast.php

@@ -37,7 +37,7 @@ class AndroidFilecast extends AndroidNotification {
         $curlErrNo = curl_errno($ch);
         $curlErr = curl_error($ch);  
         curl_close($ch);
-        print($result . "\r\n");
+        //print($result . "\r\n");
         if ($httpCode == "0") //time out 
         	throw new Exception("Curl error number:" . $curlErrNo . " , Curl error details:" . $curlErr . "\r\n");
         else if ($httpCode != "200") //we did send the notifition out and got a non-200 response

+ 1 - 1
data/api/notification/ios/IOSCustomizedcast.php

@@ -44,7 +44,7 @@ class IOSCustomizedcast extends IOSNotification {
         $curlErrNo = curl_errno($ch);
         $curlErr = curl_error($ch); 
         curl_close($ch);
-        print($result . "\r\n");
+        //print($result . "\r\n");
         if ($httpCode == "0") //time out 
         	throw new Exception("Curl error number:" . $curlErrNo . " , Curl error details:" . $curlErr . "\r\n");
         else if ($httpCode != "200") //we did send the notifition out and got a non-200 response

+ 1 - 1
data/api/notification/ios/IOSFilecast.php

@@ -37,7 +37,7 @@ class IOSFilecast extends IOSNotification {
         $curlErrNo = curl_errno($ch);
         $curlErr = curl_error($ch);
         curl_close($ch);
-        print($result . "\r\n");
+        //print($result . "\r\n");
         if ($httpCode == "0") //time out 
         	throw new Exception("Curl error number:" . $curlErrNo . " , Curl error details:" . $curlErr . "\r\n");
         else if ($httpCode != "200") //we did send the notifition out and got a non-200 response

+ 15 - 8
data/logic/queue.logic.php

@@ -379,16 +379,23 @@ class queueLogic
      */
     public function upushSendMsg($param)
     {
+        if(!empty($param) || empty($param['member_id']) || empty($param['text'])){
+            Log::record("push info: 数据有误! data:".json_encode($param)."\t".json_encode($_SESSION));
+        }
 
-        $push = new upush();
-        $push->ticker = $param['ticker'];
-        $push->member_id = $param['member_id'];
-        $push->title = $param['title'];
-        $push->text = $param['text'];
+        try{
+            $push = new push_app();
+            //androd
+            $return = $push->sendAndroidCustomizedcast($param);
+            Log::record("push info: androd  return:".json_encode($return));
+            //ios
+            $return = $push->sendIOSCustomizedcast($push);
+            Log::record("push info: ios  return:".json_encode($return));
+        } catch (Exception $e) {
+            print("Caught exception: " . $e->getMessage());
+            Log::record("push info: fall error return:".$e->getMessage());
+        }
 
-        list($ret_code, $ret_content) = $push->android_push();
-        $return_info = json_decode($ret_content);
-        joutput_data($return_info);
         return;
     }
 }

+ 27 - 102
helper/push_app.php

@@ -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'));