From 865c71b5d2854dbc6db281df767f13f885720303 Mon Sep 17 00:00:00 2001 From: YangLong <168119405@qq.com> Date: Mon, 11 May 2020 16:13:10 +0800 Subject: [PATCH] iOS --- README.md | 25 ++++++++++++++++++++++++- src/UmengPush.php | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 50fa204..38f63a9 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,15 @@ composer require sn01615/umeng-php ``` customizedcast,通过alias进行推送, 对单个或者多个alias进行推送 + 2020年4月14日:测试有效 + +2020年5月11日:iOS Customizedcast支持 ```php +# Android $cc = (new UmengPush('***', '***')) ->setProductionMode(false) -// ->setGetUrlAndBody(true) // 直接返回url和body + // ->setGetUrlAndBody(true) // 直接返回url和body ->sendAndroidCustomizedcast([ 'ticker' => '1', // 必填 通知栏提示文字 'title' => '2', // 必填 通知标题 @@ -25,6 +29,25 @@ $cc = (new UmengPush('***', '***')) ], $alias = '12345', // 开发者填写自己的alias, 要求不超过500个alias, 多个alias以英文逗号间隔 $aliasType = 'XXX'); + +# iOS +$cc = (new UmengPush('***', '***')) + ->setProductionMode(false) + // ->setGetUrlAndBody(true) // 直接返回url和body + ->sendIOSCustomizedcast([ + // 'alert' => '', // 可为JSON类型和字符串类型 + 'alert' => [ + 'title' => '1', + 'subtitle' => '2', + 'body' => '3', + ], + ], [ + 'aaa' => 1111, // 可选,用户自定义内容, "d","p"为友盟保留字段, + // key不可以是"d","p" + ], $alias = '12345', // 开发者填写自己的alias, 要求不超过500个alias, 多个alias以英文逗号间隔 + $aliasType = 'XXX'); + +var_dump($cc); ``` ##### README diff --git a/src/UmengPush.php b/src/UmengPush.php index 4726223..65f88b6 100644 --- a/src/UmengPush.php +++ b/src/UmengPush.php @@ -449,30 +449,45 @@ function sendIOSGroupcast() } } - function sendIOSCustomizedcast() + function sendIOSCustomizedcast(array $values, array $extra, $alias, $aliasType) { + $values = array_merge([ + 'alert' => '', // 必填 + // // 当content-available=1时(静默推送),可选; 否则必填。 + // 可为JSON类型和字符串类型 + // { + // "title":"title", + // "subtitle":"subtitle", + // "body":"body" + // }, + 'badge' => 0, + 'sound' => 'chime', + 'production_mode' => $this->getProductionMode(),// Set 'production_mode' to 'true' if your app is under production mode + 'content-available' => 1, + ], $values); + $extra = array_merge([], $extra); try { $customizedcast = new IOSCustomizedcast(); $customizedcast->setAppMasterSecret($this->appMasterSecret); $customizedcast->setPredefinedKeyValue("appkey", $this->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", "xx"); + $customizedcast->setPredefinedKeyValue("alias", $alias); // Set your alias_type here - $customizedcast->setPredefinedKeyValue("alias_type", "xx"); - $customizedcast->setPredefinedKeyValue("alert", "IOS 涓�у寲娴嬭瘯"); - $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"); + $customizedcast->setPredefinedKeyValue("alias_type", $aliasType); + foreach ($values as $key => $value) { + $customizedcast->setPredefinedKeyValue($key, $value); + } + foreach ($extra as $key => $value) { + $customizedcast->setCustomizedField($key, $value); + } + // print("Sending customizedcast notification, please wait...\r\n"); + return $customizedcast->send($this->getGetUrlAndBody()); + // print("Sent SUCCESS\r\n"); } catch (Exception $e) { - print("Caught exception: " . $e->getMessage()); + return "Caught exception: " . $e->getMessage(); } } }