diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd4f35e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/ +.php_cs.cache +vendor +php-cs-fixer-v2 \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..53875dd --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "HMS-Core/hms-push-php", + "type": "library", + "license": "MIT", + "homepage": "https://github.com/HMS-Core/hms-push-serverdemo-php", + "description": "PHP support for HMS push notifications", + "keywords": [ + "push notifications", + "huawei push notifications", + "hms" + ], + "authors": [ + { + "name": "Huawei", + "email": "hello@huawei.com" + } + ], + "require": { + "php": ">=7.0" + }, + "autoload": { + "psr-4": { + "Huawei\\": "src/" + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..8c08231 --- /dev/null +++ b/composer.lock @@ -0,0 +1,19 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "bf3e3ac697fe04376807b479e35ecaa5", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=7.0" + }, + "platform-dev": [] +} diff --git a/php-cs-fixer-v2.phar b/php-cs-fixer-v2.phar new file mode 100644 index 0000000..859a4c3 Binary files /dev/null and b/php-cs-fixer-v2.phar differ diff --git a/src/example/push_common/test_sample_push_msg_common.php b/src/Example/PushCommon/TestPushMsgCommon.php similarity index 50% rename from src/example/push_common/test_sample_push_msg_common.php rename to src/Example/PushCommon/TestPushMsgCommon.php index 92b7b3b..2c9cebf 100644 --- a/src/example/push_common/test_sample_push_msg_common.php +++ b/src/Example/PushCommon/TestPushMsgCommon.php @@ -1,83 +1,50 @@ fast_appsecret = $pushConfig->HW_FAST_APPSECRET; $this->fast_appid = $pushConfig->HW_FAST_APPID; $this->fast_push_token = $pushConfig->HW_FAST_PUSH_TOKEN; - } - function sendPushMsgMessageByMsgType($msg_type, $topic = "") + public function sendPushMsgMessageByMsgType($msg_type, $topic = "") { $application_server = $this->hw_push_server; $this->printLogMethodOperate("push msg start" . $this->log_suffix_show_start, __FUNCTION__ . ':' . __LINE__); @@ -150,11 +116,11 @@ function sendPushMsgMessageByMsgType($msg_type, $topic = "") $application = $this->createApplication($application_server); $this->printLogMethodOperate("application server:" . json_encode($application->getApplicationFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); - $application->push_send_msg($message->getFields()); + $application->pushSendMsg($message->getFields()); $this->printLogMethodOperate("push msg end" . $this->log_suffix_show_end, __FUNCTION__ . ':' . __LINE__); } - function sendPushMsgRealMessage($message,$push_msg_type="") + public function sendPushMsgRealMessage($message, $push_msg_type="") { $this->printLogMethodOperate("sendPushMsgRealMessage start push_msg_type:" .$push_msg_type, __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); if (!empty($push_msg_type)) { @@ -165,11 +131,11 @@ function sendPushMsgRealMessage($message,$push_msg_type="") $application = $this->createApplication($application_server); $this->printLogMethodOperate("application server:" . json_encode($application->getApplicationFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); - $application->push_send_msg($message); + $application->pushSendMsg($message); $this->printLogMethodOperate("push msg end" . $this->log_suffix_show_end, __FUNCTION__ . ':' . __LINE__); } - function sendPushTopicMsgMessage($topic = "") + public function sendPushTopicMsgMessage($topic = "") { if (empty($topic)) { $topic = $this->default_topic; @@ -194,14 +160,14 @@ private function isTopicInTopicList($result, $topic) { $this->printLogMethodOperate("isTopicInTopicList topic[" . $topic . "],result:" . json_encode($result) . "", __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_INFO_LEVEL); if (empty($result)) { - return FALSE; + return false; } $arrResult = json_decode(json_encode($result), true); $this->printLogMethodOperate("isTopicInTopicList arrResult:" . json_encode($arrResult) . "][code:" . $arrResult["code"], __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); if (empty($arrResult["code"])) { - return FALSE; + return false; } $this->printLogMethodOperate("isTopicInTopicList code:" . $arrResult["code"], __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); @@ -209,25 +175,25 @@ private function isTopicInTopicList($result, $topic) "80000000", 80000000 ))) { - return FALSE; + return false; } if (empty($arrResult["topics"])) { - return FALSE; + return false; } $topicArr = $arrResult["topics"]; $this->printLogMethodOperate("isTopicInTopicList topicArr:" . json_encode($topicArr), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); if (empty($topicArr)) { - return FALSE; + return false; } foreach ($topicArr as $topicObject) { if ($topicObject["name"] == $topic) { - return TRUE; + return true; } } $this->printLogMethodOperate("isTopicInTopicList False,topic is not subscribe", __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); - return FALSE; + return false; } private function getDefaultAndroidNotificationContent($titel) @@ -280,76 +246,76 @@ private function createAndroidNotification() { // generate click_action msg body for android notification-3-click_action $click_action = new ClickAction(); - $click_action->type(2); - $click_action->type(1); + $click_action->setType(2); + $click_action->setType(1); - $click_action->intent("#Intent;compo=com.rvr/.Activity;S.W=U;end"); - $click_action->action("test add"); - $click_action->url("https://www.baidu.com"); - $click_action->rich_resource("test rich resource"); + $click_action->setIntent("#Intent;compo=com.rvr/.Activity;S.W=U;end"); + $click_action->setAction("test add"); + $click_action->setUrl("https://www.baidu.com"); + $click_action->setRichResource("test rich resource"); $click_action->buildFields(); // generate Badge for android notification-3-badge $badge = new Badge(); - $badge->add_num(99); - $badge->setclass("Classic"); - $badge->set_num(99); + $badge->addNum(99); + $badge->setClass("Classic"); + $badge->setNum(99); $badge->buildFields(); // generate Light Settings for android notification-3-badge $lightSetting = new LightSetting(); - $lightSetting->light_on_duration("3.5"); - $lightSetting->light_off_duration("5S"); + $lightSetting->setLightOnDuration("3.5"); + $lightSetting->setLightOffDuration("5S"); // set light setting color $LightSettingColor = new LightSettingColor(); - $LightSettingColor->setgenFullcolor(0, 0, 1, 1); + $LightSettingColor->setGenFullcolor(0, 0, 1, 1); $LightSettingColor->buildFields(); - $lightSetting->color($LightSettingColor->getFields()); + $lightSetting->setColor($LightSettingColor->getFields()); $lightSetting->buildFields(); // 构建android notification消息体-2 for android config $android_notification = new AndroidNotification(); - $android_notification->title($this->getDefaultAndroidNotificationContent("default hw title ")); - $android_notification->body($this->getDefaultAndroidNotificationContent("default hw body")); - $android_notification->icon("https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png"); - $android_notification->color("#AACCDD"); - $android_notification->sound("https://att.chinauui.com/day_120606/20120606_7fcf2235b44f1eab0b4dadtAkAGMTBHK.mp3"); - $android_notification->tag("tagBoom"); - $android_notification->body_loc_key("M.String.body"); - $android_notification->body_loc_args(array( + $android_notification->setTitle($this->getDefaultAndroidNotificationContent("default hw title ")); + $android_notification->setBody($this->getDefaultAndroidNotificationContent("default hw body")); + $android_notification->setIcon("https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png"); + $android_notification->setColor("#AACCDD"); + $android_notification->setSound("https://att.chinauui.com/day_120606/20120606_7fcf2235b44f1eab0b4dadtAkAGMTBHK.mp3"); + $android_notification->setTag("tagBoom"); + $android_notification->setBodyLocKey("M.String.body"); + $android_notification->setBodyLocArgs(array( "Boy", "Dog" )); - $android_notification->title_loc_key("M.String.title"); - $android_notification->title_loc_args(array( + $android_notification->setTitleLocKey("M.String.title"); + $android_notification->setTitleLocArgs(array( "Girl", "Cat" )); - $android_notification->channel_id("RingRing"); - $android_notification->notify_summary("Some Summary"); - $android_notification->image("https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"); - $android_notification->style(0); - $android_notification->big_title("Big Boom Title"); - $android_notification->big_body("Big Boom Body"); - $android_notification->auto_clear(86400000); - $android_notification->notify_id(486); - $android_notification->group("Espace"); - $android_notification->importance(NotificationPriority::NOTIFICATION_PRIORITY_NORMAL); - $android_notification->ticker("i am a ticker"); - $android_notification->auto_cancel(false); - $android_notification->when("2019-11-05"); - $android_notification->use_default_vibrate(true); - $android_notification->use_default_light(false); - $android_notification->visibility("PUBLIC"); - $android_notification->foreground_show(true); - $android_notification->vibrate_config(array( + $android_notification->setChannelId("RingRing"); + $android_notification->setNotifySummary("Some Summary"); + $android_notification->setImage("https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"); + $android_notification->setStyle(0); + $android_notification->setBigTitle("Big Boom Title"); + $android_notification->setBigBody("Big Boom Body"); + $android_notification->setAutoClear(86400000); + $android_notification->setNotifyId(486); + $android_notification->setGroup("Espace"); + $android_notification->setImportance(NotificationPriority::NOTIFICATION_PRIORITY_NORMAL); + $android_notification->setTicker("i am a ticker"); + $android_notification->setAutoCancel(false); + $android_notification->setWhen("2019-11-05"); + $android_notification->setUseDefaultVibrate(true); + $android_notification->setUseDefaultLight(false); + $android_notification->setVisibility("PUBLIC"); + $android_notification->setForegroundShow(true); + $android_notification->setVibrateConfig(array( "1.5", "2.000000001", "3" )); - $android_notification->click_action($click_action->getFields()); - $android_notification->badge($badge->getFields()); - $android_notification->light_settings($lightSetting->getFields()); + $android_notification->setClickAction($click_action->getFields()); + $android_notification->setBadge($badge->getFields()); + $android_notification->setLightSettings($lightSetting->getFields()); $android_notification->buildFields(); @@ -361,15 +327,14 @@ private function createAndroidConfig() $android_notification = $this->createAndroidNotification(); $android_config = new AndroidConfig(); - $android_config->collapse_key(- 1); - $android_config->urgency(AndroidConfigDeliveryPriority::PRIORITY_HIGH); - $android_config->ttl("1448s"); - $android_config->bi_tag("Trump"); + $android_config->setCollapseKey(- 1); + $android_config->setUrgency(AndroidConfigDeliveryPriority::PRIORITY_HIGH); + $android_config->setTtl("1448s"); + $android_config->setBiTag("Trump"); if ($this->push_msg_type == Constants::PUSHMSG_FASTAPP_MSG_TYPE) { - $android_config->fast_app_target(1); - } - else{ - $android_config->notification($android_notification->getFields()); + $android_config->setFastAppTarget(1); + } else { + $android_config->setNotification($android_notification->getFields()); } $android_config->buildFields(); return $android_config; @@ -386,31 +351,31 @@ private function createApnsConfig() { // ApnsHeaders $apnsHeaders = new ApnsHeaders(); - $apnsHeaders->apns_topic("hmspush"); - $apnsHeaders->apns_priority(ApnConstant::ANP_PRIORITY_SEND_IMMEDIATELY); + $apnsHeaders->setApnsTopic("hmspush"); + $apnsHeaders->setApnsPriority(ApnConstant::ANP_PRIORITY_SEND_IMMEDIATELY); $apnsHeaders->buildFields(); // ApnHmsOptions $apnsHmsOptions = new ApnsHmsOptions(); - $apnsHmsOptions->target_user_type(ApnConstant::APN_TARGET_USER_TEST_USER); + $apnsHmsOptions->setTargetUserType(ApnConstant::APN_TARGET_USER_TEST_USER); $apnsHmsOptions->buildFields(); // Aps // Alert $alert = new Alert(); - $alert->title("hw default ios message title"); - $alert->body("hw default ios message body"); - $alert->action_loc_key("PLAY"); + $alert->setTitle("hw default ios message title"); + $alert->setBody("hw default ios message body"); + $alert->setActionLocKey("PLAY"); $alert->buildFields(); $aps = new Aps(); - $aps->alert($alert->getFields()); - $aps->badge(5); + $aps->setAlert($alert->getFields()); + $aps->setBadge(5); $aps->buildFields(); $apnsConfig = new ApnsConfig(); - $apnsConfig->headers($apnsHeaders->getFields()); - $apnsConfig->hms_options($apnsHmsOptions->getFields()); + $apnsConfig->setHeaders($apnsHeaders->getFields()); + $apnsConfig->setHmsOptions($apnsHmsOptions->getFields()); $apn_payload["aps"] = $aps->getFields(); $apn_payload["acme1"] = "bar"; @@ -418,7 +383,7 @@ private function createApnsConfig() "bang", "whiz" ); - $apnsConfig->payload($apn_payload); + $apnsConfig->setPayload($apn_payload); $apnsConfig->buildFields(); @@ -428,48 +393,48 @@ private function createApnsConfig() private function createWebPush() { $webPushConfig = new WebPushConfig(); - $webPushConfig->data("test webpush data"); + $webPushConfig->setData("test webpush data"); $webPushHeaders = new WebPushHeaders(); - $webPushHeaders->topic("12313ceshi"); - $webPushHeaders->ttl("990"); - $webPushHeaders->urgency(Constants::WEBPUSH_URGENCY_VERY_LOW); + $webPushHeaders->setTopic("12313ceshi"); + $webPushHeaders->setTtl("990"); + $webPushHeaders->setUrgency(Constants::WEBPUSH_URGENCY_VERY_LOW); $webPushHeaders->buildFields(); - $webPushConfig->headers($webPushHeaders->getFields()); + $webPushConfig->setHeaders($webPushHeaders->getFields()); $webPushHmsOptions = new WebPushHmsOptions(); - $webPushHmsOptions->link("https://www.huawei.com/"); + $webPushHmsOptions->setLink("https://www.huawei.com/"); $webPushHmsOptions->buildFields(); - $webPushConfig->hmsOptions($webPushHmsOptions->getFields()); + $webPushConfig->setHmsOptions($webPushHmsOptions->getFields()); $webPUshNotionfication = new WebPushNotification(); - $webPUshNotionfication->title("notication string"); - $webPUshNotionfication->body("web push body"); - $webPUshNotionfication->icon("https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"); - $webPUshNotionfication->image("https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"); - $webPUshNotionfication->lang("string"); - $webPUshNotionfication->tag("string"); - $webPUshNotionfication->badge("string"); - $webPUshNotionfication->dir("auto"); - $webPUshNotionfication->vibrate(array( + $webPUshNotionfication->setTitle("notication string"); + $webPUshNotionfication->setBody("web push body"); + $webPUshNotionfication->setIcon("https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"); + $webPUshNotionfication->setImage("https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"); + $webPUshNotionfication->setLang("string"); + $webPUshNotionfication->setTag("string"); + $webPUshNotionfication->setBadge("string"); + $webPUshNotionfication->setDir("auto"); + $webPUshNotionfication->setVibrate(array( 1, 2, 3 )); - $webPUshNotionfication->renotify(false); - $webPUshNotionfication->require_interaction(false); - $webPUshNotionfication->silent(false); - $webPUshNotionfication->timestamp(1545201266); + $webPUshNotionfication->setRenotify(false); + $webPUshNotionfication->setRequireInteraction(false); + $webPUshNotionfication->setSilent(false); + $webPUshNotionfication->setTimestamp(1545201266); $webPushNotificationAction = new WebPushNotificationAction(); - $webPushNotificationAction->title("string"); - $webPushNotificationAction->action("123"); - $webPushNotificationAction->icon("https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"); + $webPushNotificationAction->setTitle("string"); + $webPushNotificationAction->setAction("123"); + $webPushNotificationAction->setIcon("https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"); $webPushNotificationAction->buildFields(); - $webPUshNotionfication->actions(array( + $webPUshNotionfication->setActions(array( $webPushNotificationAction->getFields() )); $webPUshNotionfication->buildFields(); - $webPushConfig->notification($webPUshNotionfication->getFields()); + $webPushConfig->setNotification($webPUshNotionfication->getFields()); $webPushConfig->buildFields(); return $webPushConfig; @@ -492,9 +457,9 @@ private function printLogMethodOperate($dataFlow, $functionName = "", $logLevel private function createApplication($application_server) { - $this->printLogMethodOperate("createApplication push_msg_type:".$this->push_msg_type, __FUNCTION__ . ':' . __LINE__,Constants::HW_PUSH_LOG_DEBUG_LEVEL); - if ($this->push_msg_type == Constants::PUSHMSG_FASTAPP_MSG_TYPE){ - $this->printLogMethodOperate("createApplication PUSHMSG_FASTAPP_MSG_TYPE", __FUNCTION__ . ':' . __LINE__,Constants::HW_PUSH_LOG_DEBUG_LEVEL); + $this->printLogMethodOperate("createApplication push_msg_type:".$this->push_msg_type, __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); + if ($this->push_msg_type == Constants::PUSHMSG_FASTAPP_MSG_TYPE) { + $this->printLogMethodOperate("createApplication PUSHMSG_FASTAPP_MSG_TYPE", __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); $application = new Application($this->fast_appid, $this->fast_appsecret, $this->hw_token_server, $application_server); return $application; } @@ -538,48 +503,48 @@ private function getMessageByMsgType($msg_type) } } - private function createFastAppConfigNotificationData(){ + private function createFastAppConfigNotificationData() + { $instanceAppConfig = new InstanceAppConfig(); - $instanceAppConfig->pushtype(0); + $instanceAppConfig->setPushType(0); $instanceAppPushbody = new InstanceAppPushbody(); - $instanceAppPushbody->title("test fast app"); - $instanceAppPushbody->description("test fast app description"); - $instanceAppPushbody->page("/"); - $instanceAppPushbody->params(array( + $instanceAppPushbody->setTitle("test fast app"); + $instanceAppPushbody->setDescription("test fast app description"); + $instanceAppPushbody->setPage("/"); + $instanceAppPushbody->setParams(array( "key1"=>"test1", "key2"=>"test2" )); $instanceAppRingtone = new InstanceAppRingtone(); - $instanceAppRingtone->breathLight(true); - $instanceAppRingtone->vibration(true); + $instanceAppRingtone->setBreathLight(true); + $instanceAppRingtone->setVibration(true); $instanceAppRingtone->buildFields(); - $instanceAppPushbody->ringtone($instanceAppRingtone->getFields()); + $instanceAppPushbody->setRingtone($instanceAppRingtone->getFields()); $instanceAppPushbody->buildFields(); - $instanceAppConfig->pushbody($instanceAppPushbody->getFields()); + $instanceAppConfig->setPushBody($instanceAppPushbody->getFields()); $instanceAppConfig->buildFields(); return $instanceAppConfig; - } - private function createFastAppConfigPassThroughData(){ + private function createFastAppConfigPassThroughData() + { $instanceAppConfig = new InstanceAppConfig(); - $instanceAppConfig->pushtype(1); + $instanceAppConfig->setPushType(1); $instanceAppPushbody = new InstanceAppPushbody(); - $instanceAppPushbody->messageId("111110001"); - $instanceAppPushbody->data("hw default passthroug test"); + $instanceAppPushbody->setMessageId("111110001"); + $instanceAppPushbody->setData("hw default passthroug test"); $instanceAppPushbody->buildFields(); - $instanceAppConfig->pushbody($instanceAppPushbody->getFields()); + $instanceAppConfig->setPushBody($instanceAppPushbody->getFields()); $instanceAppConfig->buildFields(); return $instanceAppConfig; - } private function createFastAppMsg() @@ -587,12 +552,12 @@ private function createFastAppMsg() $this->printLogMethodOperate("push msg notification start", __FUNCTION__ . ':' . __LINE__); $message = new PushMessage(); - $message->data($this->createFastAppConfigNotificationData()->getFields()); + $message->setData($this->createFastAppConfigNotificationData()->getFields()); - $message->android($this->createAndroidConfig() + $message->setAndroid($this->createAndroidConfig() ->getFields()); - $message->token(array( + $message->setToken(array( $this->fast_push_token )); @@ -606,12 +571,12 @@ private function createNotificationMsg() $this->printLogMethodOperate("push msg notification start", __FUNCTION__ . ':' . __LINE__); $message = new PushMessage(); - $message->android($this->createAndroidConfig() + $message->setAndroid($this->createAndroidConfig() ->getFields()); - $message->notification($this->createNotification() + $message->setNotification($this->createNotification() ->getFields()); - $message->token(array( + $message->setToken(array( $this->hw_push_token_key )); @@ -625,11 +590,11 @@ private function createTopicMsg() $this->printLogMethodOperate("push msg createTopicMsg start", __FUNCTION__ . ':' . __LINE__); $message = new PushMessage(); - $message->android($this->createAndroidConfig() + $message->setAndroid($this->createAndroidConfig() ->getFields()); // $message->notification($this->createNotification()->buildFields()); - $message->topic($this->default_topic); + $message->setTopic($this->default_topic); $message->buildFields(); $this->printLogMethodOperate("push msg createTopicMsg end", __FUNCTION__ . ':' . __LINE__); @@ -641,10 +606,10 @@ private function createConditionMsg() $this->printLogMethodOperate("push msg createTopicMsg start", __FUNCTION__ . ':' . __LINE__); $message = new PushMessage(); - $message->android($this->createAndroidConfig() + $message->setAndroid($this->createAndroidConfig() ->getFields()); // $message->notification($this->createNotification()->buildFields()); - $message->condition("'defaultTopic' in topics"); + $message->setCondition("'defaultTopic' in topics"); // $message->condition("'weather' in topics || ('TopicB' in topics && 'TopicC' in topics)"); $message->buildFields(); @@ -657,8 +622,8 @@ private function createPassThroughMsg() $this->printLogMethodOperate("push msg passthrough start", __FUNCTION__ . ':' . __LINE__); $message = new PushMessage(); - $message->data("1111"); - $message->token(array( + $message->setData("1111"); + $message->setToken(array( $this->hw_push_token_key )); @@ -672,9 +637,9 @@ private function createApnsMsg() $this->printLogMethodOperate("push msg apns start", __FUNCTION__ . ':' . __LINE__); $message = new PushMessage(); $apnsConfig = $this->createApnsConfig(); - $message->apns($apnsConfig->getFields()); + $message->setApns($apnsConfig->getFields()); - $message->token(array( + $message->setToken(array( $this->apn_push_token_key )); $message->buildFields(); @@ -688,13 +653,13 @@ private function createWebPushMsg() $this->printLogMethodOperate("push msg webpush start", __FUNCTION__ . ':' . __LINE__); $message = new PushMessage(); - $message->webpush($this->createWebPush() + $message->setWebpush($this->createWebPush() ->getFields()); - $message->token(array( + $message->setToken(array( $this->webpush_push_token_key )); - PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[web-token:' . json_encode($message->get_token()) . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); + PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[web-token:' . json_encode($message->getToken()) . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); $message->buildFields(); @@ -702,191 +667,3 @@ private function createWebPushMsg() return $message; } } - -class TestTopicCommonSample -{ - - private $topic = "defaultTopic"; - - private $topic_msg_create_type = 1; - - private $appsecret; - - private $appid; - - private $hw_token_server; - - private $hw_topic_subscriber_server; - - private $hw_topic_unsubscriber_server; - - private $hw_topic_query_subscriber_server; - - private $tokenServerKey; - - private $log_suffix_show = "............................."; - - public function __construct($topic_value = "", $default_msg_create_type = "") - { - if (! empty($topic_value)) { - $this->topic = $topic_value; - } - if (! empty($default_msg_create_type)) { - $this->topic_msg_create_type = $default_msg_create_type; - } - - $pushConfig = PushConfig::getSingleInstance(); - - $this->appsecret = $pushConfig->HW_APPSECRET; - $this->appid = $pushConfig->HW_APPID; - $this->hw_token_server = $pushConfig->HW_TOKEN_SERVER; - $this->tokenServerKey = $pushConfig->HW_PUSH_TOKEN_ARR; - - $this->hw_topic_subscriber_server = $pushConfig->HW_TOPIC_SUBSCRIBE_SERVER; - $this->hw_topic_unsubscriber_server = $pushConfig->HW_TOPIC_UNSUBSCRIBE_SERVER; - $this->hw_topic_query_subscriber_server = $pushConfig->HW_TOPIC_QUERY_SUBSCRIBER_SERVER; - } - - private function createTopicData() - { - $topicMsg = new TopicMsg(); - $topicMsg->topic($this->topic); - $topicMsg->tokenArray(array( - $this->tokenServerKey - )); - $topicMsg->buildFields(); - - return $topicMsg; - } - - private function createApplication($application_server) - { - $application = new Application($this->appid, $this->appsecret, $this->hw_token_server, $application_server); - return $application; - } - - private function printLogMethodOperate($msg_type, $dataFlow, $functionName = "", $logLevel = "") - { - $dataFlow = 'subscribe topic ' . $dataFlow; - $logModule = Constants::HW_PUSH_LOG_TOPIC_SUBSCRIBE_MODULE; - switch ($msg_type) { - case Constants::TOPIC_UNSUBSCRIBE_MSG_TYPE: - { - $dataFlow = 'unsubscribe topic' . $dataFlow; - $logModule = Constants::HW_PUSH_LOG_TOPIC_UNSUBSCRIBE_MODULE; - } - break; - } - if (empty($logLevel)) { - $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL; - } - - if (empty($functionName)) { - PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule); - } else { - PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[' . $functionName . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule); - } - } - - private function printLogMsgOperate($msg_type, $dataFlow, $functionName = "", $logLevel = "") - { - $logModule = Constants::HW_PUSH_LOG_TOPIC_SUBSCRIBE_MODULE; - switch ($msg_type) { - case Constants::TOPIC_UNSUBSCRIBE_MSG_TYPE: - { - $logModule = Constants::HW_PUSH_LOG_TOPIC_UNSUBSCRIBE_MODULE; - } - break; - } - if (empty($logLevel)) { - $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL; - } - - if (empty($functionName)) { - PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule); - } else { - PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[' . $functionName . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule); - } - } - - /** - * topic subscribe/unsubscribe - */ - function sendTopicMessage($msg_type) - { - $this->printLogMethodOperate($msg_type, "start", __FUNCTION__ . ':' . __LINE__); - $topicMsg = $this->createTopicData(); - if ($this->topic_msg_create_type == 1) { - $this->printLogMsgOperate($msg_type, "topicMsg:" . json_encode($topicMsg->getFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); - } - - $application_server = $this->hw_topic_subscriber_server; - if ($msg_type == Constants::TOPIC_UNSUBSCRIBE_MSG_TYPE) { - $application_server = $this->hw_topic_unsubscriber_server; - } else if ($msg_type == Constants::TOPIC_SUBSCRIBE_QUERY_MSG_TYPE) { - $application_server = $this->hw_topic_query_subscriber_server; - $topicMsg = array( - 'token' => $this->tokenServerKey - ); - } - $application = $this->createApplication($application_server); - $this->printLogMsgOperate($msg_type, "application server:" . json_encode($application->getApplicationFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); - - $topicResult = ""; - if ($msg_type == Constants::TOPIC_SUBSCRIBE_QUERY_MSG_TYPE) { - $topicResult = $application->common_send_msg($topicMsg); - } else { - $topicResult = $application->common_send_msg($topicMsg->getFields()); - } - - $this->printLogMethodOperate($msg_type, "end", __FUNCTION__ . ':' . __LINE__); - return $topicResult; - } -} - -class TopicMsg -{ - - // madatory - private $topic; - - // madatory - private $tokenArray; - - private $fields; - - public function __construct() - { - $this->fields = array(); - } - - public function topic($value) - { - $this->topic = $value; - } - - public function tokenArray($value) - { - $this->tokenArray = $value; - } - - public function getFields() - { - return $this->fields; - } - - public function buildFields() - { - $keys = array( - 'topic', - 'tokenArray' - ); - foreach ($keys as $key) { - if (isset($this->$key)) { - $this->fields[$key] = $this->$key; - } - } - } -} - - diff --git a/src/Example/PushCommon/TestTopicCommonSample.php b/src/Example/PushCommon/TestTopicCommonSample.php new file mode 100644 index 0000000..d908d0c --- /dev/null +++ b/src/Example/PushCommon/TestTopicCommonSample.php @@ -0,0 +1,151 @@ +topic = $topic_value; + } + if (! empty($default_msg_create_type)) { + $this->topic_msg_create_type = $default_msg_create_type; + } + + $pushConfig = PushConfig::getSingleInstance(); + + $this->appsecret = $pushConfig->HW_APPSECRET; + $this->appid = $pushConfig->HW_APPID; + $this->hw_token_server = $pushConfig->HW_TOKEN_SERVER; + $this->tokenServerKey = $pushConfig->HW_PUSH_TOKEN_ARR; + + $this->hw_topic_subscriber_server = $pushConfig->HW_TOPIC_SUBSCRIBE_SERVER; + $this->hw_topic_unsubscriber_server = $pushConfig->HW_TOPIC_UNSUBSCRIBE_SERVER; + $this->hw_topic_query_subscriber_server = $pushConfig->HW_TOPIC_QUERY_SUBSCRIBER_SERVER; + } + + private function createTopicData() + { + $topicMsg = new TopicMsg(); + $topicMsg->setTopic($this->topic); + $topicMsg->setTokenArray(array( + $this->tokenServerKey + )); + $topicMsg->buildFields(); + + return $topicMsg; + } + + private function createApplication($application_server) + { + $application = new Application($this->appid, $this->appsecret, $this->hw_token_server, $application_server); + return $application; + } + + private function printLogMethodOperate($msg_type, $dataFlow, $functionName = "", $logLevel = "") + { + $dataFlow = 'subscribe topic ' . $dataFlow; + $logModule = Constants::HW_PUSH_LOG_TOPIC_SUBSCRIBE_MODULE; + switch ($msg_type) { + case Constants::TOPIC_UNSUBSCRIBE_MSG_TYPE: + { + $dataFlow = 'unsubscribe topic' . $dataFlow; + $logModule = Constants::HW_PUSH_LOG_TOPIC_UNSUBSCRIBE_MODULE; + } + break; + } + if (empty($logLevel)) { + $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL; + } + + if (empty($functionName)) { + PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule); + } else { + PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[' . $functionName . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule); + } + } + + private function printLogMsgOperate($msg_type, $dataFlow, $functionName = "", $logLevel = "") + { + $logModule = Constants::HW_PUSH_LOG_TOPIC_SUBSCRIBE_MODULE; + switch ($msg_type) { + case Constants::TOPIC_UNSUBSCRIBE_MSG_TYPE: + { + $logModule = Constants::HW_PUSH_LOG_TOPIC_UNSUBSCRIBE_MODULE; + } + break; + } + if (empty($logLevel)) { + $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL; + } + + if (empty($functionName)) { + PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule); + } else { + PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[' . $functionName . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule); + } + } + + /** + * topic subscribe/unsubscribe + */ + public function sendTopicMessage($msg_type) + { + $this->printLogMethodOperate($msg_type, "start", __FUNCTION__ . ':' . __LINE__); + $topicMsg = $this->createTopicData(); + if ($this->topic_msg_create_type == 1) { + $this->printLogMsgOperate($msg_type, "topicMsg:" . json_encode($topicMsg->getFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); + } + + $application_server = $this->hw_topic_subscriber_server; + if ($msg_type == Constants::TOPIC_UNSUBSCRIBE_MSG_TYPE) { + $application_server = $this->hw_topic_unsubscriber_server; + } elseif ($msg_type == Constants::TOPIC_SUBSCRIBE_QUERY_MSG_TYPE) { + $application_server = $this->hw_topic_query_subscriber_server; + $topicMsg = array( + 'token' => $this->tokenServerKey + ); + } + $application = $this->createApplication($application_server); + $this->printLogMsgOperate($msg_type, "application server:" . json_encode($application->getApplicationFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); + + $topicResult = ""; + if ($msg_type == Constants::TOPIC_SUBSCRIBE_QUERY_MSG_TYPE) { + $topicResult = $application->commonSendMsg($topicMsg); + } else { + $topicResult = $application->commonSendMsg($topicMsg->getFields()); + } + + $this->printLogMethodOperate($msg_type, "end", __FUNCTION__ . ':' . __LINE__); + return $topicResult; + } +} diff --git a/src/example/test_sample_apns_msg.php b/src/Example/test_sample_apns_msg.php similarity index 90% rename from src/example/test_sample_apns_msg.php rename to src/Example/test_sample_apns_msg.php index c1cee0a..1567cb2 100644 --- a/src/example/test_sample_apns_msg.php +++ b/src/Example/test_sample_apns_msg.php @@ -16,14 +16,13 @@ */ /** - * function: two kinds of method to send apn msg: + * function: two kinds of method to send apn msg: * 1) sendPushMsgMessageByMsgType(code class object); * 2) sendPushMsgRealMessage(text msg) * 3) ios format may change,sometimes push msg depends of ios msg format */ -include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php'); -include_once (dirname(__FILE__) . '/../push_admin/Constants.php'); -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\Example\PushCommon\TestPushMsgCommon; $testPushMsgSample = new TestPushMsgCommon(); $testPushMsgSample->sendPushMsgMessageByMsgType(Constants::APN_MSG_TYPE); @@ -96,10 +95,6 @@ ); foreach ($message_arr as $message) { - $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->apn_push_token_key.'"',$message); + $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->apn_push_token_key.'"', $message); $testPushMsgSample->sendPushMsgRealMessage(json_decode($message)); } - - - - diff --git a/src/example/test_sample_push_condition_msg.php b/src/Example/test_sample_push_condition_msg.php similarity index 93% rename from src/example/test_sample_push_condition_msg.php rename to src/Example/test_sample_push_condition_msg.php index 3a17dc7..07979a4 100644 --- a/src/example/test_sample_push_condition_msg.php +++ b/src/Example/test_sample_push_condition_msg.php @@ -21,9 +21,8 @@ * 2) sendPushMsgRealMessage(text msg) * 3) topic and condition not real time, maybe delay */ -include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php'); -include_once (dirname(__FILE__) . '/../push_admin/Constants.php'); -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\Example\PushCommon\TestPushMsgCommon; $testPushMsgSample = new TestPushMsgCommon(); @@ -92,7 +91,6 @@ }'; $topic = '111'; -$message=str_ireplace("*condition*", '"\''.$topic.'\' in topics"',$message); +$message=str_ireplace("*condition*", '"\''.$topic.'\' in topics"', $message); $testPushMsgSample->sendPushMsgRealMessage(json_decode($message)); - diff --git a/src/example/test_sample_push_instantce_app_msg.php b/src/Example/test_sample_push_instantce_app_msg.php similarity index 84% rename from src/example/test_sample_push_instantce_app_msg.php rename to src/Example/test_sample_push_instantce_app_msg.php index 113f970..c41c71d 100644 --- a/src/example/test_sample_push_instantce_app_msg.php +++ b/src/Example/test_sample_push_instantce_app_msg.php @@ -16,13 +16,12 @@ */ /** - * function: fast app,two kinds of method to send instance app msg: + * function: fast app,two kinds of method to send instance app msg: * 1) sendPushMsgMessageByMsgType(code class object); * 2) sendPushMsgRealMessage(text msg) */ -include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php'); -include_once (dirname(__FILE__) . '/../push_admin/Constants.php'); -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\Example\PushCommon\TestPushMsgCommon; $testPushMsgSample = new TestPushMsgCommon(); $testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_FASTAPP_MSG_TYPE); @@ -44,6 +43,5 @@ }'; -$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->fast_push_token.'"',$message); -$testPushMsgSample->sendPushMsgRealMessage(json_decode($message),Constants::PUSHMSG_FASTAPP_MSG_TYPE); - +$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->fast_push_token.'"', $message); +$testPushMsgSample->sendPushMsgRealMessage(json_decode($message), Constants::PUSHMSG_FASTAPP_MSG_TYPE); diff --git a/src/example/test_sample_push_notification_msg.php b/src/Example/test_sample_push_notification_msg.php similarity index 87% rename from src/example/test_sample_push_notification_msg.php rename to src/Example/test_sample_push_notification_msg.php index dfa9b21..fbf7c27 100644 --- a/src/example/test_sample_push_notification_msg.php +++ b/src/Example/test_sample_push_notification_msg.php @@ -16,13 +16,12 @@ */ /** - * function: two kinds of method to send notification msg: + * function: two kinds of method to send notification msg: * 1) sendPushMsgMessageByMsgType(code class object); * 2) sendPushMsgRealMessage(text msg) */ -include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php'); -include_once (dirname(__FILE__) . '/../push_admin/Constants.php'); -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\Example\PushCommon\TestPushMsgCommon; $testPushMsgSample = new TestPushMsgCommon(); $testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_NOTIFICATION_MSG_TYPE); @@ -69,6 +68,6 @@ ); foreach ($message_arr as $message) { - $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->hw_push_token_key.'"',$message); + $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->hw_push_token_key.'"', $message); $testPushMsgSample->sendPushMsgRealMessage(json_decode($message)); -} \ No newline at end of file +} diff --git a/src/example/test_sample_push_passthrouth_msg.php b/src/Example/test_sample_push_passthrouth_msg.php similarity index 85% rename from src/example/test_sample_push_passthrouth_msg.php rename to src/Example/test_sample_push_passthrouth_msg.php index 8a7d9a2..83496fc 100644 --- a/src/example/test_sample_push_passthrouth_msg.php +++ b/src/Example/test_sample_push_passthrouth_msg.php @@ -16,13 +16,12 @@ */ /** - * function: two kinds of method to send passthrough msg: + * function: two kinds of method to send passthrough msg: * 1) sendPushMsgMessageByMsgType(code class object); * 2) sendPushMsgRealMessage(text msg) */ -include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php'); -include_once (dirname(__FILE__) . '/../push_admin/Constants.php'); -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\Example\PushCommon\TestPushMsgCommon; $testPushMsgSample = new TestPushMsgCommon(); $testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_PASS_THROUGHT_MSG_TYPE); @@ -56,6 +55,6 @@ foreach ($message_arr as $message) { - $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->hw_push_token_key.'"',$message); + $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->hw_push_token_key.'"', $message); $testPushMsgSample->sendPushMsgRealMessage(json_decode($message)); -} \ No newline at end of file +} diff --git a/src/example/test_sample_push_topic_msg.php b/src/Example/test_sample_push_topic_msg.php similarity index 84% rename from src/example/test_sample_push_topic_msg.php rename to src/Example/test_sample_push_topic_msg.php index fdeeb3e..648a28c 100644 --- a/src/example/test_sample_push_topic_msg.php +++ b/src/Example/test_sample_push_topic_msg.php @@ -18,12 +18,11 @@ /** * function: two kinds of method to send topic msg: sendPushTopicMsgMessage for subscribe topic * 1) sendPushMsgMessageByMsgType(code class object); - * 2) sendPushMsgRealMessage(text msg) + * 2) sendPushMsgRealMessage(text msg) * 3) topic and condition not real time, maybe delay */ -include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php'); -include_once (dirname(__FILE__) . '/../push_admin/Constants.php'); -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\Example\PushCommon\TestPushMsgCommon; $testPushMsgSample = new TestPushMsgCommon(); @@ -31,11 +30,11 @@ $topic = '111'; //first time,must subscribe then could receive push msg; -if ($topicSubscribeFlag == false){ +if ($topicSubscribeFlag == false) { $testPushMsgSample->sendPushTopicMsgMessage($topic); } -$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_TOPIC_MSG_TYPE,$topic); +$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_TOPIC_MSG_TYPE, $topic); $message_arr = array('{ "data": "1111", @@ -70,6 +69,6 @@ }'); foreach ($message_arr as $message) { - $message=str_ireplace("*topic*", '"'.$topic.'"',$message); + $message=str_ireplace("*topic*", '"'.$topic.'"', $message); $testPushMsgSample->sendPushMsgRealMessage(json_decode($message)); } diff --git a/src/example/test_sample_push_webpush_msg.php b/src/Example/test_sample_push_webpush_msg.php similarity index 90% rename from src/example/test_sample_push_webpush_msg.php rename to src/Example/test_sample_push_webpush_msg.php index 30859b8..1a3f68e 100644 --- a/src/example/test_sample_push_webpush_msg.php +++ b/src/Example/test_sample_push_webpush_msg.php @@ -16,13 +16,12 @@ */ /** - * function: two kinds of method to send webpush msg: + * function: two kinds of method to send webpush msg: * 1) sendPushMsgMessageByMsgType(code class object); * 2) sendPushMsgRealMessage(text msg) */ -include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php'); -include_once (dirname(__FILE__) . '/../push_admin/Constants.php'); -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\Example\PushCommon\TestPushMsgCommon; $testPushMsgSample = new TestPushMsgCommon(); $testPushMsgSample->sendPushMsgMessageByMsgType(Constants::WEB_PUSH_MSG_TYPE); @@ -92,6 +91,6 @@ ); foreach ($message_arr as $message) { - $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->webpush_push_token_key.'"',$message); + $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->webpush_push_token_key.'"', $message); $testPushMsgSample->sendPushMsgRealMessage(json_decode($message)); } diff --git a/src/example/test_sample_test_push_msg.php b/src/Example/test_sample_test_push_msg.php similarity index 80% rename from src/example/test_sample_test_push_msg.php rename to src/Example/test_sample_test_push_msg.php index bb43457..7df2e10 100644 --- a/src/example/test_sample_test_push_msg.php +++ b/src/Example/test_sample_test_push_msg.php @@ -15,9 +15,8 @@ limitations under the License. */ -include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php'); -include_once (dirname(__FILE__) . '/../push_admin/Constants.php'); -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\Example\PushCommon\TestPushMsgCommon; $testPushMsgSample = new TestPushMsgCommon(); $testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_NOTIFICATION_MSG_TYPE); diff --git a/src/PushNotifications/PushAdmin/AndroidConfigDeliveryPriority.php b/src/PushNotifications/PushAdmin/AndroidConfigDeliveryPriority.php new file mode 100644 index 0000000..19a46aa --- /dev/null +++ b/src/PushNotifications/PushAdmin/AndroidConfigDeliveryPriority.php @@ -0,0 +1,9 @@ + push msg * common_send_msg => topic msg */ -namespace push_admin; - -include_once (dirname(__FILE__) . '/Constants.php'); -include_once (dirname(__FILE__) . '/PushLogConfig.php'); +namespace Huawei\PushNotifications\PushAdmin; class Application { - - private $appid; - - private $appsecret; - - private $token_expiredtime; - - private $access_token; - - private $validate_only; - - private $hw_token_server; - - private $hw_push_server; - + private $appId; + private $appSecret; + private $tokenExpiredTime; + private $accessToken; + private $validateOnly; + private $hwTokenServer; + private $hwPushServer; private $fields; - - public function __construct($appid, $appsecret, $hw_token_server, $hw_push_server) + public function __construct($appId, $appSecret, $hwTokenServer, $hwPushServer) { - $this->appid = $appid; - $this->appsecret = $appsecret; - $this->hw_token_server = $hw_token_server; - $this->hw_push_server = $hw_push_server; - $this->token_expiredtime = null; + $this->appId = $appId; + $this->appSecret = $appSecret; + $this->hwTokenServer = $hwTokenServer; + $this->hwPushServer = $hwPushServer; + $this->tokenExpiredTime = null; $this->accesstoken = null; - $this->validate_only = false; + $this->validateOnly = false; } - public function appid($value) + public function appId($value) { - $this->appid = $value; + $this->appId = $value; } - public function appsecret($value) + public function appSecret($value) { - $this->appsecret = $value; + $this->appSecret = $value; } - public function validate_only($value) + public function validateOnly($value) { - $this->validate_only = $value; + $this->validateOnly = $value; } public function getApplicationFields() @@ -100,23 +88,23 @@ private function printLogMethodOperate($dataFlow, $functionName = "", $logLevel } } - private function is_token_expired() + private function isTokenExpired() { if (empty($this->accesstoken)) { return true; } - if (time() > $this->token_expiredtime) { + if (time() > $this->tokenExpiredTime) { return true; } return false; } - private function refresh_token() + private function refreshToken() { - $result = json_decode($this->curl_https_post($this->hw_token_server, http_build_query(array( + $result = json_decode($this->curlHttpsPost($this->hwTokenServer, http_build_query(array( "grant_type" => "client_credentials", - "client_secret" => $this->appsecret, - "client_id" => $this->appid + "client_secret" => $this->appSecret, + "client_id" => $this->appId )), array( "Content-Type: application/x-www-form-urlencoded;charset=utf-8" ))); @@ -127,11 +115,11 @@ private function refresh_token() } $this->printLogMethodOperate('refresh_token result:' . json_encode($result), __FUNCTION__ . ':' . __LINE__); $this->accesstoken = $result->access_token; - $this->token_expiredtime = time() + $result->expires_in; - return $this->access_token; + $this->tokenExpiredTime = time() + $result->expires_in; + return $this->accessToken; } - private function curl_https_post($url, $data = array(), $header = array()) + private function curlHttpsPost($url, $data = array(), $header = array()) { $this->printLogMethodOperate('curl_https_post enter url:' . $url, __FUNCTION__ . ':' . __LINE__); $ch = curl_init($url); @@ -169,27 +157,33 @@ private function curl_https_post($url, $data = array(), $header = array()) /** * push_send_msg for push msg */ - public function push_send_msg($msg) + public function pushSendMsg($msg) { $this->printLogMethodOperate('push_send_msg enter msg:' . json_encode($msg), __FUNCTION__ . ':' . __LINE__); $body = array( - "validate_only" => $this->validate_only, + "validate_only" => $this->validateOnly, "message" => $msg ); $this->printLogMethodOperate('push_send_msg new body:' . json_encode($body), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); - if ($this->is_token_expired()) { - $this->refresh_token(); + if ($this->isTokenExpired()) { + $this->refreshToken(); } - if (empty($this->accesstoken)){ - $this->printLogMethodOperate("accesstoken is empty!", - __FUNCTION__ . ':' . __LINE__,Constants::HW_PUSH_LOG_ERROR_LEVEL); + if (empty($this->accesstoken)) { + $this->printLogMethodOperate( + "accesstoken is empty!", + __FUNCTION__ . ':' . __LINE__, + Constants::HW_PUSH_LOG_ERROR_LEVEL + ); return null; } - $result = json_decode($this->curl_https_post(str_replace('{appid}', $this->appid, $this->hw_push_server), json_encode($body), array( + $result = json_decode($this->curlHttpsPost( + str_replace('{appid}', $this->appId, $this->hwPushServer), + json_encode($body), + array( "Content-Type: application/json", "Authorization: Bearer {$this->accesstoken}" ) // Use bearer auth @@ -211,20 +205,26 @@ public function push_send_msg($msg) /** * common_send_msg for topic msg/other */ - public function common_send_msg($msg) + public function commonSendMsg($msg) { $this->printLogMethodOperate('common_send_msg enter msg:' . json_encode($msg), __FUNCTION__ . ':' . __LINE__); - if ($this->is_token_expired()) { - $this->refresh_token(); + if ($this->isTokenExpired()) { + $this->refreshToken(); } - if (empty($this->accesstoken)){ - $this->printLogMethodOperate("accesstoken is empty!", - __FUNCTION__ . ':' . __LINE__,Constants::HW_PUSH_LOG_ERROR_LEVEL); + if (empty($this->accesstoken)) { + $this->printLogMethodOperate( + "accesstoken is empty!", + __FUNCTION__ . ':' . __LINE__, + Constants::HW_PUSH_LOG_ERROR_LEVEL + ); return null; } - $result = json_decode($this->curl_https_post(str_replace('{appid}', $this->appid, $this->hw_push_server), json_encode($msg), array( + $result = json_decode($this->curlHttpsPost( + str_replace('{appid}', $this->appId, $this->hwPushServer), + json_encode($msg), + array( "Content-Type: application/json", "Authorization: Bearer {$this->accesstoken}" ) // Use bearer auth diff --git a/src/push_admin/Constants.php b/src/PushNotifications/PushAdmin/Constants.php similarity index 71% rename from src/push_admin/Constants.php rename to src/PushNotifications/PushAdmin/Constants.php index cb250e7..ed68899 100644 --- a/src/push_admin/Constants.php +++ b/src/PushNotifications/PushAdmin/Constants.php @@ -18,41 +18,28 @@ /** * function: const variables */ -namespace push_admin; - +namespace Huawei\PushNotifications\PushAdmin; class Constants { - /** * push_msg */ - const WEBPUSH_URGENCY_VERY_LOW = "very-low"; - const WEBPUSH_URGENCY_LOW = "low"; - const WEBPUSH_URGENCY_NORMAL = "normal"; - const WEBPUSH_URGENCY_HIGH = "high"; /* * Notification Type */ const PUSHMSG_NOTIFICATION_MSG_TYPE = 1; - const PUSHMSG_PASS_THROUGHT_MSG_TYPE = 2; - const PUSHMSG_TOPIC_MSG_TYPE = 3; - const PUSHMSG_CONDITION_MSG_TYPE = 4; - const PUSHMSG_FASTAPP_MSG_TYPE = 5; - const APN_MSG_TYPE = 6; - const WEB_PUSH_MSG_TYPE = 7; - const TOPIC_SUBSCRIBE_MSG_TYPE = 8; const TOPIC_UNSUBSCRIBE_MSG_TYPE = 9; const TOPIC_SUBSCRIBE_QUERY_MSG_TYPE = 10; @@ -61,63 +48,17 @@ class Constants * log */ const HW_PUSH_LOG_PUSH_MSG_MODULE = "PushMsg"; - const HW_PUSH_LOG_TOPIC_SUBSCRIBE_MODULE = "TopicSubsScribe"; - const HW_PUSH_LOG_TOPIC_UNSUBSCRIBE_MODULE = "TopicUnSubsScribe"; - const HW_PUSH_LOG_DEBUG_LEVEL = 4; - const HW_PUSH_LOG_INFO_LEVEL = 3; - const HW_PUSH_LOG_WARN_LEVEL = 2; - const HW_PUSH_LOG_ERROR_LEVEL = 1; - const HW_PUSH_LOG_FILE_NAME = 'push.log'; - const URL_PATTERN = "/^https.*/"; const VIBRATE_PATTERN = "/[0-9]+|[0-9]+[sS]|[0-9]+[.][0-9]{1,9}|[0-9]+[.][0-9]{1,9}[sS]/"; const COLOR_PATTERN = "/^#[0-9a-fA-F]{6}$/"; const TTL_PATTERN = "/\\d+|\\d+[sS]|\\d+.\\d{1,9}|\\d+.\\d{1,9}[sS]/"; - const APN_AUTHORIZATION_PATTERN = "/^bearer*/"; const APN_ID_PATTERN = "/[0-9a-z]{8}(-[0-9a-z]{4}){3}-[0-9a-z]{12}/"; } - -class Visibility { - const VISIBILITY_UNSPECIFIED= "VISIBILITY_UNSPECIFIED"; - const PRIVATE_STR="PRIVATE"; - const PUBLIC_STR="PUBLIC"; - const SECRET_STR="SECRET"; -} - -class NotificationPriority { - const NOTIFICATION_PRIORITY_LOW = 'LOW'; - - const NOTIFICATION_PRIORITY_NORMAL = 'NORMAL'; - - const NOTIFICATION_PRIORITY_HIGH = 'HIGH'; -} - -class AndroidConfigDeliveryPriority{ - const PRIORITY_HIGH = 'HIGH'; - - const PRIORITY_NORMAL = 'NORMAL'; -} - -class ApnConstant{ - - //APN PRIORITY - const ANP_PRIORITY_SEND_IMMEDIATELY = "10"; - const ANP_PRIORITY_SEND_BY_GROUP = "5"; - - //APN TARGET USER - const APN_TARGET_USER_TEST_USER = 1; - const APN_TARGET_USER_FORMAL_USER = 2; - const APN_TARGET_USER_VOIP_USER = 3; - -} - - - diff --git a/src/PushNotifications/PushAdmin/NotificationPriority.php b/src/PushNotifications/PushAdmin/NotificationPriority.php new file mode 100644 index 0000000..dfd6157 --- /dev/null +++ b/src/PushNotifications/PushAdmin/NotificationPriority.php @@ -0,0 +1,10 @@ +log_read_flag == false) { + if ($this->logReadFlag === false) { $file_path = "../config.ini"; if (file_exists($file_path)) { $file_contents = file($file_path); @@ -57,7 +54,7 @@ private function __construct() for ($i = 0; $i < count($file_contents); $i ++) { $this->processConfigData($file_contents[$i]); } - $this->log_read_flag = true; + $this->logReadFlag = true; } else { echo $file_path . " not exist,please config first!!!
"; } @@ -87,15 +84,15 @@ private function processConfigData($lineData) $lineData = str_replace(";", "", $lineData); $order=array("\r\n","\n","\r"); - $lineData=str_replace($order,"",$lineData); + $lineData=str_replace($order, "", $lineData); $lineData = str_replace(PHP_EOL, '', $lineData); $resultPos = stripos($lineData, "="); - if (FALSE == $resultPos) { + if (false == $resultPos) { return; } $key = substr($lineData, 0, $resultPos); - if (FALSE == $key) { + if (false == $key) { return; } @@ -157,7 +154,7 @@ private function processConfigData($lineData) case "HW_DEFAULT_LOG_LEVEL": { $this->HW_DEFAULT_LOG_LEVEL = $value; - } + } break; case "HW_FAST_APPID": @@ -182,7 +179,7 @@ private function processConfigData($lineData) private function processConfigValueData($lineDataMapValue) { $key = stripos($lineDataMapValue, "\""); - if (FALSE == $key) { + if (false == $key) { return $lineDataMapValue; } if ($key > 0) { @@ -191,4 +188,3 @@ private function processConfigValueData($lineDataMapValue) return $lineDataMapValue; } } - diff --git a/src/push_admin/PushLogConfig.php b/src/PushNotifications/PushAdmin/PushLogConfig.php similarity index 88% rename from src/push_admin/PushLogConfig.php rename to src/PushNotifications/PushAdmin/PushLogConfig.php index 32d2db4..99f932c 100644 --- a/src/push_admin/PushLogConfig.php +++ b/src/PushNotifications/PushAdmin/PushLogConfig.php @@ -15,16 +15,12 @@ limitations under the License. */ -namespace push_admin; - -include_once (dirname(__FILE__) . '/Constants.php'); -include_once (dirname(__FILE__) . '/PushConfig.php'); +namespace Huawei\PushNotifications\PushAdmin; use Exception; class PushLogConfig { - private $LogFile; private $logBanner = " @@ -38,10 +34,10 @@ class PushLogConfig private $LOG_MODULE_FIXED_LEN = 20; - private $default_log_level = Constants::HW_PUSH_LOG_INFO_LEVEL; + private $defaultLogLevel = Constants::HW_PUSH_LOG_INFO_LEVEL; private function __construct() - { + { $this->LogFile = @fopen(Constants::HW_PUSH_LOG_FILE_NAME, 'a+'); if (! is_resource($this->LogFile)) { throw new Exception(Constants::HW_PUSH_LOG_FILE_NAME . 'invalid file Stream'); @@ -51,9 +47,9 @@ private function __construct() $pushConfig = PushConfig::getSingleInstance(); - $this->default_log_level = $pushConfig->HW_DEFAULT_LOG_LEVEL; - if (empty($this->default_log_level)){ - $this->default_log_level = Constants::HW_PUSH_LOG_INFO_LEVEL; + $this->defaultLogLevel = $pushConfig->HW_DEFAULT_LOG_LEVEL; + if (empty($this->defaultLogLevel)) { + $this->defaultLogLevel = Constants::HW_PUSH_LOG_INFO_LEVEL; } } @@ -78,7 +74,7 @@ public function LogMessage($msg, $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL, $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL; } - if ($logLevel > $this->default_log_level) { + if ($logLevel > $this->defaultLogLevel) { return; } date_default_timezone_set($timeZone); @@ -123,4 +119,3 @@ private function levelToString($logLevel) return $ret; } } - diff --git a/src/push_admin/push_msg/android/AndroidConfig.php b/src/PushNotifications/PushAdmin/PushMessage/Android/AndroidConfig.php similarity index 63% rename from src/push_admin/push_msg/android/AndroidConfig.php rename to src/PushNotifications/PushAdmin/PushMessage/Android/AndroidConfig.php index 28345ee..f8db0f7 100644 --- a/src/push_admin/push_msg/android/AndroidConfig.php +++ b/src/PushNotifications/PushAdmin/PushMessage/Android/AndroidConfig.php @@ -14,36 +14,25 @@ See the License for the specific language governing permissions and limitations under the License. */ -namespace push_admin\push_msg\android; -include_once (dirname(__FILE__) . '/../../Constants.php'); -include_once (dirname(__FILE__) . '/../ValidatorUtil.php'); +namespace Huawei\PushNotifications\PushAdmin\PushMessage\Android; -use push_admin\ValidatorUtil; -use push_admin\Constants; -use push_admin\AndroidConfigDeliveryPriority; use Exception; -use push_admin\PushLogConfig; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\PushNotifications\PushAdmin\PushLogConfig; +use Huawei\PushNotifications\PushAdmin\PushMessage\ValidatorUtil; +use Huawei\PushNotifications\PushAdmin\AndroidConfigDeliveryPriority; class AndroidConfig { - - private $collapse_key; - + private $collapseKey; private $category; - private $urgency; - private $ttl; - - private $bi_tag; - - private $fast_app_target; - + private $biTag; + private $fastAppTarget; private $notification; - private $fields; - private $data; public function __construct() @@ -58,42 +47,42 @@ public function getFields() return $this->fields; } - public function collapse_key($value) + public function setCollapseKey($value) { - $this->collapse_key = $value; + $this->collapseKey = $value; } - public function category($value) + public function setCategory($value) { $this->category = $value; } - public function urgency($value) + public function setUrgency($value) { $this->urgency = $value; } - public function ttl($value) + public function setTtl($value) { $this->ttl = $value; } - public function bi_tag($value) + public function setBiTag($value) { - $this->bi_tag = $value; + $this->biTag = $value; } - public function fast_app_target($value) + public function setFastAppTarget($value) { - $this->fast_app_target = $value; + $this->fastAppTarget = $value; } - public function notification($value) + public function setNotification($value) { $this->notification = $value; } - public function data($value) + public function setData($value) { $this->data = $value; } @@ -101,19 +90,18 @@ public function data($value) public function buildFields() { try { - $this->check_parameter(); + $this->checkParameter(); } catch (Exception $e) { -// echo $e; - PushLogConfig::getSingleInstance()->LogMessage($e,Constants::HW_PUSH_LOG_ERROR_LEVEL); + PushLogConfig::getSingleInstance()->LogMessage($e, Constants::HW_PUSH_LOG_ERROR_LEVEL); return; } $keys = array( - 'collapse_key', + 'collapseKey', 'category', 'urgency', 'ttl', - 'bi_tag', - 'fast_app_target', + 'biTag', + 'fastAppTarget', 'notification', 'data' ); @@ -124,12 +112,17 @@ public function buildFields() } } - private function check_parameter() + public function getAllVars() { - if (! empty($this->collapse_key) && ($this->collapse_key < - 1 || $this->collapse_key > 100)) { + var_dump(get_object_vars($this)); + } + + private function checkParameter() + { + if (! empty($this->collapseKey) && ($this->collapseKey < - 1 || $this->collapseKey > 100)) { throw new Exception("Collapse Key should be [-1, 100]"); } - if (! empty($this->fast_app_target) && ! in_array($this->fast_app_target, array( + if (! empty($this->fastAppTarget) && ! in_array($this->fastAppTarget, array( 1, 2 ))) { @@ -144,14 +137,9 @@ private function check_parameter() } if (! empty($this->ttl)) { - if (FALSE == ValidatorUtil::validatePattern(Constants::TTL_PATTERN, $this->ttl)) { + if (false == ValidatorUtil::validatePattern(Constants::TTL_PATTERN, $this->ttl)) { throw new Exception("The TTL's format is wrong"); } } } - - public function get_all_vars() - { - var_dump(get_object_vars($this)); - } -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/android/AndroidNotification.php b/src/PushNotifications/PushAdmin/PushMessage/Android/AndroidNotification.php similarity index 53% rename from src/push_admin/push_msg/android/AndroidNotification.php rename to src/PushNotifications/PushAdmin/PushMessage/Android/AndroidNotification.php index f257bed..eead0ea 100644 --- a/src/push_admin/push_msg/android/AndroidNotification.php +++ b/src/PushNotifications/PushAdmin/PushMessage/Android/AndroidNotification.php @@ -15,53 +15,35 @@ limitations under the License. */ -namespace push_admin\push_msg\android; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\Android; -include_once (dirname(__FILE__) . '/../../Constants.php'); -include_once (dirname(__FILE__) . '/../ValidatorUtil.php'); - -use push_admin\ValidatorUtil; -use push_admin\Constants; -use push_admin\NotificationPriority; -use push_admin\Visibility; use Exception; -use push_admin\PushLogConfig; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\PushNotifications\PushAdmin\PushLogConfig; +use Huawei\PushNotifications\PushAdmin\PushMessage\ValidatorUtil; +use Huawei\PushNotifications\PushAdmin\NotificationPriority; +use Huawei\PushNotifications\PushAdmin\Visibility; /** * optional for android config */ class AndroidNotification { - private $title; - private $body; - private $icon; - private $color; - private $sound; - private $tag; - - private $click_action; - - private $body_loc_key; - - private $body_loc_args; - - private $title_loc_key; - - private $title_loc_args; - - private $channel_id; - - private $notify_summary; - + private $clickAction; + private $bodyLocKey; + private $bodyLocArgs; + private $titleLocKey; + private $titleLocArgs; + private $channelId; + private $notifySummary; private $image; - - private $notify_icon; + private $notifyIcon; /** * notification style: @@ -70,211 +52,194 @@ class AndroidNotification * 2:big photo */ private $style; - - private $big_title; - - private $big_body; - - private $auto_clear; - - private $notify_id; - + private $bigTitle; + private $bigBody; + private $autoClear; + private $notifyId; private $group; - private $badge; - private $ticker; - - private $auto_cancel; - + private $autoCancel; private $when; - private $importance; - - private $use_default_vibrate; - - private $use_default_light; - - private $vibrate_config; - + private $useDefaultVibrate; + private $useDefaultLight; + private $vibrateConfig; private $visibility; - - private $light_settings; - - private $foreground_show; - + private $lightSettings; + private $foregroundShow; private $fields; public function __construct() { - $this->click_action = array(); - $this->body_loc_args = array(); - $this->title_loc_args = array(); + $this->clickAction = array(); + $this->bodyLocArgs = array(); + $this->titleLocArgs = array(); $this->badge = array(); - $this->light_settings = array(); - $this->foreground_show = true; + $this->lightSettings = array(); + $this->foregroundShow = true; $this->fields = array(); } - public function title($value) + public function setTitle($value) { $this->title = $value; } - public function body($value) + public function setBody($value) { $this->body = $value; } - public function icon($value) + public function setIcon($value) { $this->icon = $value; } - public function color($value) + public function setColor($value) { $this->color = $value; } - public function sound($value) + public function setSound($value) { $this->sound = $value; } - public function tag($value) + public function setTag($value) { $this->tag = $value; } - public function click_action($value) + public function setClickAction($value) { - $this->click_action = $value; + $this->clickAction = $value; } - public function body_loc_key($value) + public function setBodyLocKey($value) { - $this->body_loc_key = $value; + $this->bodyLocKey = $value; } - public function body_loc_args($value) + public function setBodyLocArgs($value) { - $this->body_loc_args = $value; + $this->bodyLocArgs = $value; } - public function title_loc_key($value) + public function setTitleLocKey($value) { - $this->title_loc_key = $value; + $this->titleLocKey = $value; } - public function title_loc_args($value) + public function setTitleLocArgs($value) { - $this->title_loc_args = $value; + $this->titleLocArgs = $value; } - public function channel_id($value) + public function setChannelId($value) { - $this->channel_id = $value; + $this->channelId = $value; } - public function notify_summary($value) + public function setNotifySummary($value) { - $this->notify_summary = $value; + $this->notifySummary = $value; } // added - public function image($value) + public function setImage($value) { $this->image = $value; } - public function notify_icon($value) + public function setNotifyIcon($value) { - $this->notify_icon = $value; + $this->notifyIcon = $value; } - public function style($value) + public function setStyle($value) { $this->style = $value; } - public function big_title($value) + public function setBigTitle($value) { - $this->big_title = $value; + $this->bigTitle = $value; } - public function big_body($value) + public function setBigBody($value) { - $this->big_body = $value; + $this->bigBody = $value; } - public function auto_clear($value) + public function setAutoClear($value) { - $this->auto_clear = $value; + $this->autoClear = $value; } - public function notify_id($value) + public function setNotifyId($value) { - $this->notify_id = $value; + $this->notifyId = $value; } - public function group($value) + public function setGroup($value) { $this->group = $value; } - public function badge($value) + public function setBadge($value) { $this->badge = $value; } - public function ticker($value) + public function setTicker($value) { $this->ticker = $value; } - public function auto_cancel($value) + public function setAutoCancel($value) { - $this->auto_cancel = $value; + $this->autoCancel = $value; } - public function when($value) + public function setWhen($value) { $this->when = $value; } - public function importance($value) + public function setImportance($value) { $this->importance = $value; } - public function use_default_vibrate($value) + public function setUseDefaultVibrate($value) { - $this->use_default_vibrate = $value; + $this->useDefaultVibrate = $value; } - public function use_default_light($value) + public function setUseDefaultLight($value) { - $this->use_default_light = $value; + $this->useDefaultLight = $value; } - public function vibrate_config($value) + public function setVibrateConfig($value) { - $this->vibrate_config = $value; + $this->vibrateConfig = $value; } - public function visibility($value) + public function setVisibility($value) { $this->visibility = $value; } - public function light_settings($value) + public function setLightSettings($value) { - $this->light_settings = $value; + $this->lightSettings = $value; } - public function foreground_show($value) + public function setForegroundShow($value) { - $this->foreground_show = $value; + $this->foregroundShow = $value; } public function getFields() @@ -285,9 +250,9 @@ public function getFields() public function buildFields() { try { - $this->check_parameter(); + $this->checkParameter(); } catch (Exception $e) { - PushLogConfig::getSingleInstance()->LogMessage($e,Constants::HW_PUSH_LOG_ERROR_LEVEL); + PushLogConfig::getSingleInstance()->LogMessage($e, Constants::HW_PUSH_LOG_ERROR_LEVEL); return; } @@ -299,31 +264,31 @@ public function buildFields() 'color', 'sound', 'tag', - 'click_action', - 'body_loc_key', - 'body_loc_args', - 'title_loc_key', - 'title_loc_args', - 'channel_id', - 'notify_summary', - 'notify_icon', + 'clickAction', + 'bodyLocKey', + 'bodyLocArgs', + 'titleLocKey', + 'titleLocArgs', + 'channelId', + 'notifySummary', + 'notifyIcon', 'style', - 'big_title', - 'big_body', - 'auto_clear', - 'notify_id', + 'bigTitle', + 'bigBody', + 'autoClear', + 'notifyId', 'group', 'badge', 'ticker', - 'auto_cancel', + 'autoCancel', 'when', 'importance', - 'use_default_vibrate', - 'use_default_light', - 'vibrate_config', + 'useDefaultVibrate', + 'useDefaultLight', + 'vibrateConfig', 'visibility', - 'light_settings', - 'foreground_show' + 'lightSettings', + 'foregroundShow' ); foreach ($keys as $key) { if (isset($this->$key)) { @@ -332,33 +297,31 @@ public function buildFields() } } - private function check_parameter() + private function checkParameter() { - if (empty($this->title)) - { + if (empty($this->title)) { throw new Exception("title should be set"); } - if (empty($this->body)) - { + if (empty($this->body)) { throw new Exception("body should be set"); } if (! empty($this->color)) { - if (FALSE == ValidatorUtil::validatePattern(Constants::COLOR_PATTERN, $this->color)) { + if (false == ValidatorUtil::validatePattern(Constants::COLOR_PATTERN, $this->color)) { throw new Exception("Wrong color format, color must be in the form #RRGGBB"); } } - if (! empty($this->body_loc_args) && empty($this->body_loc_key)) { + if (! empty($this->bodyLocArgs) && empty($this->bodyLocKey)) { throw new Exception("bodyLocKey is required when specifying bodyLocArgs"); } - if (! empty($this->title_loc_args) && empty($this->title_loc_key)) { + if (! empty($this->titleLocArgs) && empty($this->titleLocKey)) { throw new Exception("titleLocKey is required when specifying titleLocArgs"); } if (! empty($this->image)) { - if (FALSE == ValidatorUtil::validatePattern(Constants::URL_PATTERN, $this->image)) { + if (false == ValidatorUtil::validatePattern(Constants::URL_PATTERN, $this->image)) { throw new Exception("notifyIcon must start with https"); } } @@ -384,9 +347,9 @@ private function check_parameter() } // vibrate_config - if (! empty($this->vibrate_config)) { - foreach ($this->vibrate_config as $key) { - if (FALSE == ValidatorUtil::validatePattern(Constants::VIBRATE_PATTERN, $key)) { + if (! empty($this->vibrateConfig)) { + foreach ($this->vibrateConfig as $key) { + if (false == ValidatorUtil::validatePattern(Constants::VIBRATE_PATTERN, $key)) { throw new Exception("Wrong vibrate timing format"); } } @@ -403,14 +366,12 @@ private function check_parameter() } // auto_clear - if (($this->auto_clear) && (gettype($this->auto_clear) != "integer")) { + if (($this->autoClear) && (gettype($this->autoClear) != "integer")) { throw new Exception("type of auto_clear is wrong."); } // notify_id - if (($this->notify_id) && (gettype($this->notify_id) != "integer")) { + if (($this->notifyId) && (gettype($this->notifyId) != "integer")) { throw new Exception("type of notify_id is wrong."); } - - } -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/android/Badge.php b/src/PushNotifications/PushAdmin/PushMessage/Android/Badge.php similarity index 70% rename from src/push_admin/push_msg/android/Badge.php rename to src/PushNotifications/PushAdmin/PushMessage/Android/Badge.php index e6ad113..dbd7a9b 100644 --- a/src/push_admin/push_msg/android/Badge.php +++ b/src/PushNotifications/PushAdmin/PushMessage/Android/Badge.php @@ -20,19 +20,15 @@ * =>AndroidConfig(notification) * =>PushMessage(android) */ -namespace push_admin\push_msg\android; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\Android; use Exception; class Badge { - - private $add_num; - + private $addNum; private $class; - - private $set_num; - + private $setNum; private $fields; public function __construct() @@ -40,19 +36,19 @@ public function __construct() $this->fields = array(); } - public function add_num($value) + public function addNum($value) { - $this->add_num = $value; + $this->addNum = $value; } - public function setclass($value) + public function setClass($value) { $this->class = $value; } - public function set_num($value) + public function setNum($value) { - $this->set_num = $value; + $this->setNum = $value; } public function getFields() @@ -63,14 +59,14 @@ public function getFields() public function buildFields() { try { - $this->check_parameter(); + $this->checkParameter(); } catch (Exception $e) { echo $e; } $keys = array( - 'add_num', + 'addNum', 'class', - 'set_num' + 'setNum' ); foreach ($keys as $key) { if (isset($this->$key)) { @@ -79,20 +75,19 @@ public function buildFields() } } - private function check_parameter() + private function checkParameter() { - if (($this->add_num) && (gettype($this->add_num) != "integer")) { + if (($this->addNum) && (gettype($this->addNum) != "integer")) { throw new Exception("type of add_num is wrong."); } - if (is_int($this->add_num) && ($this->add_num < 1 || $this->add_num > 100)) { + if (is_int($this->addNum) && ($this->addNum < 1 || $this->addNum > 100)) { throw new Exception("add_num should locate between 0 and 100"); } - if (($this->set_num) && (gettype($this->set_num) != "integer")) { + if (($this->setNum) && (gettype($this->setNum) != "integer")) { throw new Exception("type of set_num is wrong."); } - if (is_int($this->set_num) && ($this->set_num < 1 || $this->set_num > 100)) { + if (is_int($this->setNum) && ($this->setNum < 1 || $this->setNum > 100)) { throw new Exception("set_num should locate between 0 and 100"); } - } -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/android/ClickAction.php b/src/PushNotifications/PushAdmin/PushMessage/Android/ClickAction.php similarity index 75% rename from src/push_admin/push_msg/android/ClickAction.php rename to src/PushNotifications/PushAdmin/PushMessage/Android/ClickAction.php index 33cbbf4..de95b5c 100644 --- a/src/push_admin/push_msg/android/ClickAction.php +++ b/src/PushNotifications/PushAdmin/PushMessage/Android/ClickAction.php @@ -20,58 +20,49 @@ * =>AndroidConfig(notification) * =>PushMessage(android) */ -namespace push_admin\push_msg\android; - -include_once (dirname(__FILE__) . '/../ValidatorUtil.php'); - -use push_admin\ValidatorUtil; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\Android; use Exception; +use Huawei\PushNotifications\PushAdmin\PushMessage\ValidatorUtil; class ClickAction { - private $type; - private $intent; - private $url; - - private $rich_resource; - // added private $action; - private $fields; + private $richResource; public function __construct() { - $this->rich_resource = null; + $this->richResource = null; $this->url = null; } - public function type($value) + public function setType($value) { $this->type = $value; } - public function intent($value) + public function setIntent($value) { $this->intent = $value; } - public function url($value) + public function setUrl($value) { $this->url = $value; } - public function rich_resource($value) + public function setRichResource($value) { - $this->rich_resource = $value; + $this->richResource = $value; } // added - public function action($value) + public function setAction($value) { $this->action = $value; } @@ -84,7 +75,7 @@ public function getFields() public function buildFields() { try { - $this->check_parameter(); + $this->checkParameter(); } catch (Exception $e) { echo $e; } @@ -92,7 +83,7 @@ public function buildFields() 'type', 'intent', 'url', - 'rich_resource', + 'richResource', // add 'action' ); @@ -103,16 +94,16 @@ public function buildFields() } } - private function check_parameter() + private function checkParameter() { if (($this->type) && (gettype($this->type) != "integer")) { throw new Exception("type of type is wrong."); } - if (!in_array($this->type, array(1,2,3,4))){ + if (!in_array($this->type, array(1,2,3,4))) { throw new Exception("click type should be one of 1: customize action, 2: open url, 3: open app, 4: open rich media"); } $PATTERN = "/^https.*/"; - switch($this->type){ + switch ($this->type) { case 1:{ if (is_null($this->intent) && is_null($this->action)) { throw new Exception("when type=1,intent/action at least one is valid"); @@ -120,27 +111,24 @@ private function check_parameter() } break; case 2:{ - if (is_null($this->url)){ + if (is_null($this->url)) { throw new Exception("url is required when click type=2"); } - if (FALSE == ValidatorUtil::validatePattern($PATTERN,$this->url)){ + if (false == ValidatorUtil::validatePattern($PATTERN, $this->url)) { throw new Exception("url must start with https"); } } break; case 4:{ - if (is_null($this->richResource)){ + if (is_null($this->richResource)) { throw new Exception("richResource is required when click type=4"); } - if (FALSE == ValidatorUtil::validatePattern($PATTERN,$this->richResource)){ + if (false == ValidatorUtil::validatePattern($PATTERN, $this->richResource)) { throw new Exception("richResource must start with https"); } } break; } - - - } -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/android/LightSetting.php b/src/PushNotifications/PushAdmin/PushMessage/Android/LightSetting.php similarity index 69% rename from src/push_admin/push_msg/android/LightSetting.php rename to src/PushNotifications/PushAdmin/PushMessage/Android/LightSetting.php index be161b0..8f3a4e5 100644 --- a/src/push_admin/push_msg/android/LightSetting.php +++ b/src/PushNotifications/PushAdmin/PushMessage/Android/LightSetting.php @@ -20,21 +20,16 @@ * =>AndroidConfig(notification) * =>PushMessage(android) */ -namespace push_admin\push_msg\android; -include_once (dirname(__FILE__) . '/../ValidatorUtil.php'); +namespace Huawei\PushNotifications\PushAdmin\PushMessage\Android; -use push_admin\ValidatorUtil; use Exception; +use Huawei\PushNotifications\PushAdmin\PushMessage\ValidatorUtil; class LightSetting { - private $color; - - private $light_on_duration; - - private $light_off_duration; - + private $lightOnDuration; + private $lightOffDuration; private $fields; public function __construct() @@ -43,19 +38,19 @@ public function __construct() $this->fields = array(); } - public function color($value) + public function setColor($value) { $this->color = $value; } - public function light_on_duration($value) + public function setLightOnDuration($value) { - $this->light_on_duration = $value; + $this->lightOnDuration = $value; } - public function light_off_duration($value) + public function setLightOffDuration($value) { - $this->light_off_duration = $value; + $this->lightOffDuration = $value; } public function getFields() @@ -66,14 +61,14 @@ public function getFields() public function buildFields() { try { - $this->check_parameter(); + $this->checkParameter(); } catch (Exception $e) { echo $e; } $keys = array( 'color', - 'light_on_duration', - 'light_off_duration' + 'lightOnDuration', + 'lightOffDuration' ); foreach ($keys as $key) { if (isset($this->$key)) { @@ -82,25 +77,23 @@ public function buildFields() } } - private function check_parameter() + private function checkParameter() { - if (empty($this->color)){ + if (empty($this->color)) { throw new Exception("color must be selected when light_settings is set"); } - if (empty($this->light_on_duration)){ + if (empty($this->lightOnDuration)) { throw new Exception("light_on_duration must be selected when light_settings is set"); } - if (empty($this->light_off_duration)){ + if (empty($this->lightOffDuration)) { throw new Exception("light_off_duration must be selected when light_settings is set"); } $LIGTH_DURATION_PATTERN = "/\\d+|\\d+[sS]|\\d+.\\d{1,9}|\\d+.\\d{1,9}[sS]/"; - if ( FALSE == ValidatorUtil::validatePattern($LIGTH_DURATION_PATTERN,$this->light_on_duration)) { + if (false == ValidatorUtil::validatePattern($LIGTH_DURATION_PATTERN, $this->lightOnDuration)) { throw new Exception("light_on_duration format is wrong"); } - if (FALSE == ValidatorUtil::validatePattern($LIGTH_DURATION_PATTERN,$this->light_off_duration) ) { + if (false == ValidatorUtil::validatePattern($LIGTH_DURATION_PATTERN, $this->lightOffDuration)) { throw new Exception("light_off_duration format is wrong"); } - - } -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/android/LightSettingColor.php b/src/PushNotifications/PushAdmin/PushMessage/Android/LightSettingColor.php similarity index 90% rename from src/push_admin/push_msg/android/LightSettingColor.php rename to src/PushNotifications/PushAdmin/PushMessage/Android/LightSettingColor.php index 92af139..54bd251 100644 --- a/src/push_admin/push_msg/android/LightSettingColor.php +++ b/src/PushNotifications/PushAdmin/PushMessage/Android/LightSettingColor.php @@ -21,21 +21,16 @@ * =>AndroidConfig(notification) * =>PushMessage(android) */ -namespace push_admin\push_msg\android; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\Android; use Exception; class LightSettingColor { - private $alpha; - private $red; - private $green; - private $blue; - private $fields; public function __construct() @@ -47,7 +42,7 @@ public function __construct() $this->fields = array(); } - public function setgenFullcolor($alpha, $red, $green, $blue) + public function setGenFullcolor($alpha, $red, $green, $blue) { $this->alpha = $alpha; $this->red = $red; @@ -55,22 +50,22 @@ public function setgenFullcolor($alpha, $red, $green, $blue) $this->blue = $blue; } - public function alpha($value) + public function setAlpha($value) { $this->alpha = $value; } - public function red($value) + public function setRed($value) { $this->red = $value; } - public function green($value) + public function setGreen($value) { $this->green = $value; } - public function blue($value) + public function setBlue($value) { $this->blue = $value; } @@ -115,4 +110,4 @@ private function check_parameter() throw new Exception("type of blue is wrong."); } } -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/apns/Alert.php b/src/PushNotifications/PushAdmin/PushMessage/Apns/Alert.php similarity index 59% rename from src/push_admin/push_msg/apns/Alert.php rename to src/PushNotifications/PushAdmin/PushMessage/Apns/Alert.php index 38588f6..c3ec8d5 100644 --- a/src/push_admin/push_msg/apns/Alert.php +++ b/src/PushNotifications/PushAdmin/PushMessage/Apns/Alert.php @@ -18,50 +18,64 @@ /** * function: Alert => =>PushMessage(apns) for ios channel */ -namespace push_admin\push_msg\apns; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\Apns; -include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php'); -use push_admin\PushLogConfig; -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\PushNotifications\PushAdmin\PushLogConfig; - -class Alert { - +class Alert +{ private $title; private $body; - private $title_loc_key; - private $title_loc_args; - private $action_loc_key; - private $loc_key; - private $loc_args; - private $launch_image; + private $titleLocKey; + private $titleLocArgs; + private $actionLocKey; + private $locKey; + private $locArgs; + private $launchImage; private $fields; - public function title($value) { + public function setTitle($value) + { $this->title = $value; } - public function body($value) { + + public function setBody($value) + { $this->body = $value; } - public function title_loc_key($value) { - $this->title_loc_key = $value; + + public function setTitleLocKey($value) + { + $this->titleLocKey = $value; } - public function title_loc_args($value) { - $this->title_loc_args = $value; + + public function setTitleLocArgs($value) + { + $this->titleLocArgs = $value; } - public function action_loc_key($value) { - $this->action_loc_key = $value; + + public function setActionLocKey($value) + { + $this->actionLocKey = $value; } - public function loc_key($value) { - $this->loc_key = $value; + + public function setLocKey($value) + { + $this->locKey = $value; } - public function loc_args($value) { - $this->loc_args = $value; + + public function setLocArgs($value) + { + $this->locArgs = $value; } - public function launch_image($value) { - $this->launch_image = $value; + + public function setLaunchImage($value) + { + $this->launchImage = $value; } + public function getFields() { return $this->fields; @@ -72,15 +86,14 @@ public function buildFields() $keys = array( 'title', 'body', - 'title-loc-key', - 'title-loc-args', - 'action-loc-key', - 'loc-key', - 'loc-args', - 'launch-image' + 'titleLocKey', + 'titleLocArgs', + 'actionLocKey', + 'locKey', + 'locArgs', + 'launchImage' ); foreach ($keys as $key) { - $value = str_replace('-', '_', $key); PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][before key:' . $key . '][after key:' . $value . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); @@ -89,7 +102,5 @@ public function buildFields() } } PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); - } - -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/apns/ApnsConfig.php b/src/PushNotifications/PushAdmin/PushMessage/Apns/ApnsConfig.php similarity index 80% rename from src/push_admin/push_msg/apns/ApnsConfig.php rename to src/PushNotifications/PushAdmin/PushMessage/Apns/ApnsConfig.php index b811d33..e6ccdda 100644 --- a/src/push_admin/push_msg/apns/ApnsConfig.php +++ b/src/PushNotifications/PushAdmin/PushMessage/Apns/ApnsConfig.php @@ -18,19 +18,16 @@ /** * function: ApnsConfig => =>PushMessage(apns) for ios channel */ -namespace push_admin\push_msg\apns; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\Apns; - -include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php'); -use push_admin\PushLogConfig; -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\PushNotifications\PushAdmin\PushLogConfig; class ApnsConfig { private $payload; private $headers; - private $hms_options; - + private $hmsOptions; private $fields; public function __construct() @@ -38,18 +35,21 @@ public function __construct() $this->fields = array(); } - public function payload($value) + public function setPayload($value) { $this->payload = $value; } - public function headers($value) + + public function setHeaders($value) { $this->headers = $value; } - public function hms_options($value) + + public function setHmsOptions($value) { - $this->hms_options = $value; + $this->hmsOptions = $value; } + public function getFields() { return $this->fields; @@ -57,10 +57,9 @@ public function getFields() public function buildFields() { - $keys = array( 'headers', - 'hms_options', + 'hmsOptions', 'payload' ); foreach ($keys as $key) { @@ -70,8 +69,5 @@ public function buildFields() } } PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); - } - } - diff --git a/src/push_admin/push_msg/apns/ApnsHeaders.php b/src/PushNotifications/PushAdmin/PushMessage/Apns/ApnsHeaders.php similarity index 60% rename from src/push_admin/push_msg/apns/ApnsHeaders.php rename to src/PushNotifications/PushAdmin/PushMessage/Apns/ApnsHeaders.php index cae52fa..4b1812d 100644 --- a/src/push_admin/push_msg/apns/ApnsHeaders.php +++ b/src/PushNotifications/PushAdmin/PushMessage/Apns/ApnsHeaders.php @@ -15,63 +15,52 @@ limitations under the License. */ -namespace push_admin\push_msg\apns; - -include_once (dirname(__FILE__) . '/../ValidatorUtil.php'); - -include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php'); +namespace Huawei\PushNotifications\PushAdmin\PushMessage\Apns; use Exception; -use push_admin\ValidatorUtil; -use push_admin\Constants; -use push_admin\ApnConstant; -use push_admin\PushLogConfig; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\PushNotifications\PushAdmin\PushLogConfig; +use Huawei\PushNotifications\PushAdmin\PushMessage\ValidatorUtil; +use Huawei\PushNotifications\PushAdmin\ApnConstant; class ApnsHeaders { - private $authorization; - - private $apns_id; - - private $apns_expiration; - - private $apns_priority; - - private $apns_topic; - - private $apns_collapse_id; - + private $apnsId; + private $apnsExpiration; + private $apnsPriority; + private $apnsTopic; + private $apnsCollapseId; private $fields; - public function authorization($value) + public function setAuthorization($value) { $this->authorization = $value; } - public function apns_id($value) + public function setApnsId($value) { - $this->apns_id = $value; + $this->apnsId = $value; } - public function apns_expiration($value) + public function setApnsExpiration($value) { - $this->apns_expiration = $value; + $this->apnsExpiration = $value; } - public function apns_priority($value) + public function setApnsPriority($value) { - $this->apns_priority = $value; + $this->apnsPriority = $value; } - public function apns_topic($value) + public function setApnsTopic($value) { - $this->apns_topic = $value; + $this->apnsTopic = $value; } - public function apns_collapse_id($value) + public function setApnsCollapseId($value) { - $this->apns_collapse_id = $value; + $this->apnsCollapseId = $value; } public function getFields() @@ -82,20 +71,19 @@ public function getFields() public function buildFields() { try { - $this->check_parameter(); + $this->checkParameter(); } catch (Exception $e) { echo $e; } $keys = array( 'authorization', - 'apns-id', - 'apns-expiration', - 'apns-priority', - 'apns-topic', - 'apns-collapse-id' + 'apnsId', + 'apnsExpiration', + 'apnsPriority', + 'apnsTopic', + 'apnsCollapseId' ); foreach ($keys as $key) { - $value = str_replace('-', '_', $key); PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][before key:' . $key . '][after key:' . $value . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); @@ -106,30 +94,30 @@ public function buildFields() PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); } - private function check_parameter() + private function checkParameter() { if (! empty($this->authorization)) { - if (FALSE == ValidatorUtil::validatePattern(Constants::APN_AUTHORIZATION_PATTERN, $this->authorization)) { + if (false == ValidatorUtil::validatePattern(Constants::APN_AUTHORIZATION_PATTERN, $this->authorization)) { throw new Exception("authorization must start with bearer"); } } - if (! empty($this->apns_id)) { - if (FALSE == ValidatorUtil::validatePattern(Constants::APN_ID_PATTERN, $this->apns_id)) { + if (! empty($this->apnsId)) { + if (false == ValidatorUtil::validatePattern(Constants::APN_ID_PATTERN, $this->apnsId)) { throw new Exception("apns-id format error"); } } - if (! empty($this->apns_priority)) { - if (! in_array($this->apns_priority, array( + if (! empty($this->apnsPriority)) { + if (! in_array($this->apnsPriority, array( ApnConstant::ANP_PRIORITY_SEND_BY_GROUP, ApnConstant::ANP_PRIORITY_SEND_IMMEDIATELY ))) { throw new Exception("apns-priority should be SEND_BY_GROUP:5 or SEND_IMMEDIATELY:10"); } } - if (! empty($this->apns_collapse_id)) { - if (strlen($this->apns_priority) >= 64) { + if (! empty($this->apnsCollapseId)) { + if (strlen($this->apnsPriority) >= 64) { throw new Exception("Number of apnsCollapseId bytes should be less than 64"); } } } -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/apns/ApnsHmsOptions.php b/src/PushNotifications/PushAdmin/PushMessage/Apns/ApnsHmsOptions.php similarity index 71% rename from src/push_admin/push_msg/apns/ApnsHmsOptions.php rename to src/PushNotifications/PushAdmin/PushMessage/Apns/ApnsHmsOptions.php index 086c13f..2a9a267 100644 --- a/src/push_admin/push_msg/apns/ApnsHmsOptions.php +++ b/src/PushNotifications/PushAdmin/PushMessage/Apns/ApnsHmsOptions.php @@ -15,32 +15,34 @@ limitations under the License. */ -namespace push_admin\push_msg\apns; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\Apns; use Exception; -class ApnsHmsOptions { - - - private $target_user_type; +class ApnsHmsOptions +{ + private $targetUserType; + private $fields; public function getFields() { return $this->fields; } - public function target_user_type($value) + + public function setTargetUserType($value) { - $this->target_user_type = $value; + $this->targetUserType = $value; } + public function buildFields() { try { - $this->check_parameter(); + $this->checkParameter(); } catch (Exception $e) { echo $e; } - $keys = array( - 'target_user_type' + $keys = array( + 'targetUserType' ); foreach ($keys as $key) { if (isset($this->$key)) { @@ -49,13 +51,11 @@ public function buildFields() } } - private function check_parameter() + private function checkParameter() { - if (!empty($this->target_user_type) - && !in_array($this->target_user_type,array(1,2,3))) { + if (!empty($this->targetUserType) + && !in_array($this->targetUserType, array(1,2,3))) { throw new Exception("target_user_type range TEST_USER:1,FORMAL_USER:2,VOIP_USER:3"); } } } - - \ No newline at end of file diff --git a/src/push_admin/push_msg/apns/Aps.php b/src/PushNotifications/PushAdmin/PushMessage/Apns/Aps.php similarity index 72% rename from src/push_admin/push_msg/apns/Aps.php rename to src/PushNotifications/PushAdmin/PushMessage/Apns/Aps.php index 755e765..834f841 100644 --- a/src/push_admin/push_msg/apns/Aps.php +++ b/src/PushNotifications/PushAdmin/PushMessage/Apns/Aps.php @@ -15,40 +15,45 @@ limitations under the License. */ -namespace push_admin\push_msg\apns; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\Apns; -include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php'); -use push_admin\PushLogConfig; -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\PushNotifications\PushAdmin\PushLogConfig; -class Aps { - +class Aps +{ private $alert; private $badge; private $sound; - private $content_available; + private $contentAvailable; private $category; - private $thread_id; + private $threadId; private $fields; - public function alert($value) { + public function setAlert($value) + { $this->alert = $value; } - public function badge($value) { + public function setBadge($value) + { $this->badge = $value; } - public function sound($value) { + public function setSound($value) + { $this->sound = $value; } - public function content_available($value) { - $this->content_available = $value; + public function setContentAvailable($value) + { + $this->contentAvailable = $value; } - public function category($value) { + public function setCategory($value) + { $this->category = $value; } - public function thread_id($value) { - $this->thread_id = $value; + public function setThreadId($value) + { + $this->threadId = $value; } public function getFields() @@ -62,12 +67,11 @@ public function buildFields() 'alert', 'badge', 'sound', - 'content-available', + 'contentAvailable', 'category', - 'thread-id' + 'threadId' ); foreach ($keys as $key) { - $value = str_replace('-', '_', $key); PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][before key:' . $key . '][after key:' . $value . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); @@ -76,7 +80,5 @@ public function buildFields() } } PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); - } - -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/instanceapp/InstanceAppConfig.php b/src/PushNotifications/PushAdmin/PushMessage/InstanceApp/InstanceAppConfig.php similarity index 80% rename from src/push_admin/push_msg/instanceapp/InstanceAppConfig.php rename to src/PushNotifications/PushAdmin/PushMessage/InstanceApp/InstanceAppConfig.php index 03981b3..3c957b0 100644 --- a/src/push_admin/push_msg/instanceapp/InstanceAppConfig.php +++ b/src/PushNotifications/PushAdmin/PushMessage/InstanceApp/InstanceAppConfig.php @@ -18,31 +18,29 @@ /** * function: ApnsConfig => =>PushMessage(apns) for ios channel */ -namespace push_admin\push_msg\instanceapp; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\InstanceApp; - -include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php'); -use push_admin\PushLogConfig; -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\PushNotifications\PushAdmin\PushLogConfig; class InstanceAppConfig { //push_type 0:notification;1,pass-through - private $pushtype; - private $pushbody; + private $pushType; + private $pushBody; private $fields; public function __construct() { } - public function pushtype($value) + public function setPushType($value) { - $this->pushtype = $value; + $this->pushType = $value; } - public function pushbody($value) + public function setPushBody($value) { - $this->pushbody = $value; + $this->pushBody = $value; } public function getFields() @@ -52,7 +50,7 @@ public function getFields() $result = $result .$key.":".json_encode($value).","; PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][result:' .$result, Constants::HW_PUSH_LOG_DEBUG_LEVEL); } - if (strlen($result) > 1){ + if (strlen($result) > 1) { $result = rtrim($result, ","); } $result = $result."}"; @@ -61,10 +59,9 @@ public function getFields() public function buildFields() { - $keys = array( - 'pushtype', - 'pushbody' + 'pushType', + 'pushBody' ); foreach ($keys as $key) { PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][key:' . $key . '][value:' . json_encode($this->$key) . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); @@ -73,8 +70,5 @@ public function buildFields() } } PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); - } - } - diff --git a/src/push_admin/push_msg/instanceapp/InstanceAppPushbody.php b/src/PushNotifications/PushAdmin/PushMessage/InstanceApp/InstanceAppPushbody.php similarity index 81% rename from src/push_admin/push_msg/instanceapp/InstanceAppPushbody.php rename to src/PushNotifications/PushAdmin/PushMessage/InstanceApp/InstanceAppPushbody.php index 497ad34..02c9fc0 100644 --- a/src/push_admin/push_msg/instanceapp/InstanceAppPushbody.php +++ b/src/PushNotifications/PushAdmin/PushMessage/InstanceApp/InstanceAppPushbody.php @@ -18,60 +18,55 @@ /** * function: ApnsConfig => =>PushMessage(apns) for ios channel */ -namespace push_admin\push_msg\instanceapp; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\InstanceApp; - -include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php'); -use push_admin\PushLogConfig; -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\PushNotifications\PushAdmin\PushLogConfig; class InstanceAppPushbody { // for pass-through private $messageId; private $data; - // for notification private $title; - private $description; + private $description; private $page; private $params; private $ringtone; - private $fields; - public function __construct() - { - } - - public function messageId($value) + public function setMessageId($value) { $this->messageId = $value; } - public function data($value) + + public function setData($value) { $this->data = $value; } - public function title($value) + public function setTitle($value) { $this->title = $value; } - public function description($value) + + public function setDescription($value) { $this->description = $value; } - public function page($value) + public function setPage($value) { $this->page = $value; } - public function params($value) + + public function setParams($value) { $this->params = $value; } - public function ringtone($value) + public function setRingtone($value) { $this->ringtone = $value; } @@ -83,7 +78,7 @@ public function getFields() $result = $result .$key.":".json_encode($value).","; PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][result:' .$result, Constants::HW_PUSH_LOG_DEBUG_LEVEL); } - if (strlen($result) > 1){ + if (strlen($result) > 1) { $result = rtrim($result, ","); } $result = $result."}"; @@ -92,7 +87,6 @@ public function getFields() public function buildFields() { - $keys = array( 'messageId', 'data', @@ -109,8 +103,5 @@ public function buildFields() } } PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); - } - } - diff --git a/src/push_admin/push_msg/instanceapp/InstanceAppRingtone.php b/src/PushNotifications/PushAdmin/PushMessage/InstanceApp/InstanceAppRingtone.php similarity index 87% rename from src/push_admin/push_msg/instanceapp/InstanceAppRingtone.php rename to src/PushNotifications/PushAdmin/PushMessage/InstanceApp/InstanceAppRingtone.php index 0025f6a..2e8e861 100644 --- a/src/push_admin/push_msg/instanceapp/InstanceAppRingtone.php +++ b/src/PushNotifications/PushAdmin/PushMessage/InstanceApp/InstanceAppRingtone.php @@ -18,15 +18,13 @@ /** * function: ApnsConfig => =>PushMessage(apns) for ios channel */ -namespace push_admin\push_msg\instanceapp; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\InstanceApp; -include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php'); -use push_admin\PushLogConfig; -use push_admin\Constants; +use Huawei\PushNotifications\PushAdmin\Constants; +use Huawei\PushNotifications\PushAdmin\PushLogConfig; class InstanceAppRingtone { - private $vibration; private $breathLight; @@ -37,12 +35,12 @@ public function __construct() $this->fields = array(); } - public function vibration($value) + public function setVibration($value) { $this->vibration = $value; } - public function breathLight($value) + public function setBreathLight($value) { $this->breathLight = $value; } @@ -54,7 +52,7 @@ public function getFields() $result = $result .$key.":".json_encode($value).","; PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][result:' .$result, Constants::HW_PUSH_LOG_DEBUG_LEVEL); } - if (strlen($result) > 1){ + if (strlen($result) > 1) { $result = rtrim($result, ","); } $result = $result."}"; @@ -76,4 +74,3 @@ public function buildFields() PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); } } - diff --git a/src/push_admin/push_msg/notification/Notification.php b/src/PushNotifications/PushAdmin/PushMessage/Notification/Notification.php similarity index 81% rename from src/push_admin/push_msg/notification/Notification.php rename to src/PushNotifications/PushAdmin/PushMessage/Notification/Notification.php index adf1d01..10d6b01 100644 --- a/src/push_admin/push_msg/notification/Notification.php +++ b/src/PushNotifications/PushAdmin/PushMessage/Notification/Notification.php @@ -18,12 +18,13 @@ /** * function: Notification message push control parameter =>PushMessage(notification) for ios channel */ -namespace push_admin\push_msg\notification; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\Notification; /** * optional for message */ use Exception; + class Notification { @@ -52,17 +53,17 @@ public function __construct($title, $body, $image) $this->fields = array(); } - public function title($value) + public function setTitle($value) { $this->title = $value; } - public function body($value) + public function setBody($value) { $this->body = $value; } - public function image($value) + public function setImage($value) { $this->image = $value; } @@ -73,11 +74,12 @@ public function getFields() } public function buildFields() - { try { - $this->check_parameter(); - } catch (Exception $e) { - echo $e; - } + { + try { + $this->checkParameter(); + } catch (Exception $e) { + echo $e; + } $keys = array( 'title', 'body', @@ -90,15 +92,13 @@ public function buildFields() } } - private function check_parameter() + private function checkParameter() { - if (empty($this->title)) - { + if (empty($this->title)) { throw new Exception("title should be set"); } - if (empty($this->body)) - { + if (empty($this->body)) { throw new Exception("body should be set"); } } -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/PushMessage.php b/src/PushNotifications/PushAdmin/PushMessage/PushMessage.php similarity index 83% rename from src/push_admin/push_msg/PushMessage.php rename to src/PushNotifications/PushAdmin/PushMessage/PushMessage.php index 5038122..58e78b2 100644 --- a/src/push_admin/push_msg/PushMessage.php +++ b/src/PushNotifications/PushAdmin/PushMessage/PushMessage.php @@ -20,27 +20,18 @@ * 5 kinds of msg payload:$data,$notification,$android,$apns,$webpush * 3 kinds of Message sending object:$token,$topic,$condition */ -namespace push_admin\push_msg; +namespace Huawei\PushNotifications\PushAdmin\PushMessage; class PushMessage { - private $data; - private $notification; - private $android; - private $apns; - private $webpush; - private $token; - private $topic; - private $condition; - private $fields; public function __construct() @@ -52,45 +43,46 @@ public function __construct() $this->notification = null; } - public function data($value) + public function setData($value) { $this->data = $value; } - public function notification($value) + public function setNotification($value) { $this->notification = $value; } - public function android($value) + public function setAndroid($value) { $this->android = $value; } - public function token($value) + public function setToken($value) { $this->token = $value; } - public function get_token(){ + public function getToken() + { return $this->token; } - public function topic($value) + public function setTopic($value) { $this->topic = $value; } - public function condition($value) + public function setCondition($value) { $this->condition = $value; } - public function apns($value) + public function setApns($value) { $this->apns = $value; } - public function webpush($value) + public function setWebpush($value) { $this->webpush = $value; } @@ -118,4 +110,4 @@ public function buildFields() } } } -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/ValidatorUtil.php b/src/PushNotifications/PushAdmin/PushMessage/ValidatorUtil.php similarity index 75% rename from src/push_admin/push_msg/ValidatorUtil.php rename to src/PushNotifications/PushAdmin/PushMessage/ValidatorUtil.php index 4520686..dd39060 100644 --- a/src/push_admin/push_msg/ValidatorUtil.php +++ b/src/PushNotifications/PushAdmin/PushMessage/ValidatorUtil.php @@ -15,16 +15,18 @@ limitations under the License. */ -namespace push_admin; +namespace Huawei\PushNotifications\PushAdmin\PushMessage; -class ValidatorUtil{ - - function validatePattern($pattern,$value){ +class ValidatorUtil +{ + public static function validatePattern($pattern, $value) + { $result = preg_match($pattern, $value); - if (1 == $result){ - return TRUE; + if (1 == $result) { + return true; } - return FALSE; + + return false; } -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/webpush/WebPushConfig.php b/src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushConfig.php similarity index 83% rename from src/push_admin/push_msg/webpush/WebPushConfig.php rename to src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushConfig.php index a5a2212..f4e29b5 100644 --- a/src/push_admin/push_msg/webpush/WebPushConfig.php +++ b/src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushConfig.php @@ -18,19 +18,14 @@ /** * function: webpush message push control parameter, which is required for webpush msg=>PushMessage(webpush) */ -namespace push_admin\push_msg\webpush; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\WebPush; class WebPushConfig { - private $headers; - private $data; - private $notification; - - private $hms_options; - + private $hmsOptions; private $fields; public function __construct() @@ -41,24 +36,24 @@ public function __construct() $this->fields = array(); } - public function headers($value) + public function setHeaders($value) { $this->headers = $value; } - public function data($value) + public function setData($value) { $this->data = $value; } - public function notification($value) + public function setNotification($value) { $this->notification = $value; } - public function hmsOptions($value) + public function setHmsOptions($value) { - $this->hms_options = $value; + $this->hmsOptions = $value; } public function getFields() @@ -72,7 +67,7 @@ public function buildFields() 'headers', 'data', 'notification', - 'hms_options' + 'hmsOptions' ); foreach ($keys as $key) { if (isset($this->$key)) { @@ -81,4 +76,3 @@ public function buildFields() } } } - diff --git a/src/push_admin/push_msg/webpush/WebPushHeaders.php b/src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushHeaders.php similarity index 88% rename from src/push_admin/push_msg/webpush/WebPushHeaders.php rename to src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushHeaders.php index a9330b6..2bc6501 100644 --- a/src/push_admin/push_msg/webpush/WebPushHeaders.php +++ b/src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushHeaders.php @@ -19,17 +19,13 @@ * function: WebPush Headers class =>WebPushConfig(headers) * =>PushMessage(webpush) */ -namespace push_admin\push_msg\webpush; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\WebPush; class WebPushHeaders { - private $ttl; - private $topic; - private $urgency; - private $fields; public function __construct() @@ -37,17 +33,17 @@ public function __construct() $this->fields = array(); } - public function ttl($value) + public function setTtl($value) { $this->ttl = $value; } - public function topic($value) + public function setTopic($value) { $this->topic = $value; } - public function urgency($value) + public function setUrgency($value) { $this->urgency = $value; } @@ -70,4 +66,4 @@ public function buildFields() } } } -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/webpush/WebPushHmsOptions.php b/src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushHmsOptions.php similarity index 83% rename from src/push_admin/push_msg/webpush/WebPushHmsOptions.php rename to src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushHmsOptions.php index 2161d39..cfa2ab1 100644 --- a/src/push_admin/push_msg/webpush/WebPushHmsOptions.php +++ b/src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushHmsOptions.php @@ -19,33 +19,30 @@ * function: WebPushHmsOptions class =>WebPushConfig(hms_options) * =>PushMessage(webpush) */ -namespace push_admin\push_msg\webpush; - +namespace Huawei\PushNotifications\PushAdmin\PushMessage\WebPush; class WebPushHmsOptions -{ +{ private $link; - private $fields; public function __construct() { - $this->fields = array(); + $this->fields = array(); } - public function link($value) { + public function setLink($value) + { $this->link = $value; } - - - public function getFields() { + public function getFields() + { return $this->fields; } - public function buildFields() { - - + public function buildFields() + { $keys = array( 'link' ); @@ -55,7 +52,4 @@ public function buildFields() { } } } - - - -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/webpush/WebPushNotification.php b/src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushNotification.php similarity index 67% rename from src/push_admin/push_msg/webpush/WebPushNotification.php rename to src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushNotification.php index 234c653..78fbdb8 100644 --- a/src/push_admin/push_msg/webpush/WebPushNotification.php +++ b/src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushNotification.php @@ -19,93 +19,114 @@ * function: WebPushNotification class =>WebPushConfig(notification) * =>PushMessage(webpush) */ -namespace push_admin\push_msg\webpush; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\WebPush; use Exception; + class WebPushNotification { - private $title; private $body; private $icon; - private $image; + private $image; private $lang; private $tag; private $badge; - private $dir; + private $dir; private $vibrate; private $renotify; - - private $require_interaction; + private $requireInteraction; private $silent; private $timestamp; - private $actions; - private $fields; public function __construct() { $this->actions = array(); - $this->fields = array(); + $this->fields = array(); } - public function title($value) { + public function setTitle($value) + { $this->title = $value; } - public function body($value) { + + public function setBody($value) + { $this->body = $value; } - public function icon($value) { + + public function setIcon($value) + { $this->icon = $value; } - public function image($value) { + + public function setImage($value) + { $this->image = $value; } - public function lang($value) { + + public function setLang($value) + { $this->lang = $value; } - public function tag($value) { + + public function setTag($value) + { $this->tag = $value; } - public function badge($value) { + public function setBadge($value) + { $this->badge = $value; } - public function dir($value) { + public function setDir($value) + { $this->dir = $value; } - public function vibrate($value) { + + public function setVibrate($value) + { $this->vibrate = $value; } - public function renotify($value) { + + public function setRenotify($value) + { $this->renotify = $value; } - public function require_interaction($value) { - $this->require_interaction = $value; + + public function setRequireInteraction($value) + { + $this->requireInteraction = $value; } - - public function silent($value) { + public function setSilent($value) + { $this->silent = $value; } - public function timestamp($value) { + + public function setTimestamp($value) + { $this->timestamp = $value; } - public function actions($value) { + + public function setActions($value) + { $this->actions = $value; } - - public function getFields() { + public function getFields() + { return $this->fields; } - public function buildFields() { - try{ - $this->check_parameter(); - }catch (Exception $e) { + public function buildFields() + { + try { + $this->checkParameter(); + } catch (Exception $e) { echo $e; } @@ -119,8 +140,8 @@ public function buildFields() { 'badge', 'dir', 'vibrate', - 'renotify', - 'require_interaction', + 'renotify', + 'requireInteraction', 'silent', 'timestamp', 'actions' @@ -132,18 +153,16 @@ public function buildFields() { } } - private function check_parameter() { + private function checkParameter() + { if (($this->renotify) && (gettype($this->renotify) != "boolean")) { throw new Exception("type of renotify is wrong."); } - if (($this->require_interaction) && (gettype($this->require_interaction) != "boolean")) { + if (($this->requireInteraction) && (gettype($this->requireInteraction) != "boolean")) { throw new Exception("type of requireInteraction is wrong."); } if (($this->silent) && (gettype($this->silent) != "boolean")) { throw new Exception("type of silent is wrong."); } - - } - -} \ No newline at end of file +} diff --git a/src/push_admin/push_msg/webpush/WebPushNotificationAction.php b/src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushNotificationAction.php similarity index 89% rename from src/push_admin/push_msg/webpush/WebPushNotificationAction.php rename to src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushNotificationAction.php index 566d8f7..8b116bf 100644 --- a/src/push_admin/push_msg/webpush/WebPushNotificationAction.php +++ b/src/PushNotifications/PushAdmin/PushMessage/WebPush/WebPushNotificationAction.php @@ -20,17 +20,13 @@ * =>WebPushConfig(notification) * =>PushMessage(webpush) */ -namespace push_admin\push_msg\webpush; +namespace Huawei\PushNotifications\PushAdmin\PushMessage\WebPush; class WebPushNotificationAction { - private $title; - private $icon; - private $action; - private $fields; public function __construct() @@ -38,17 +34,17 @@ public function __construct() $this->fields = array(); } - public function title($value) + public function setTitle($value) { $this->title = $value; } - public function action($value) + public function setAction($value) { $this->action = $value; } - public function icon($value) + public function setIcon($value) { $this->icon = $value; } @@ -71,4 +67,4 @@ public function buildFields() } } } -} \ No newline at end of file +} diff --git a/src/PushNotifications/PushAdmin/Visibility.php b/src/PushNotifications/PushAdmin/Visibility.php new file mode 100644 index 0000000..3c68097 --- /dev/null +++ b/src/PushNotifications/PushAdmin/Visibility.php @@ -0,0 +1,11 @@ +topic = $value; + } + + public function setTokenArray($value) + { + $this->tokenArray = $value; + } + + public function getFields() + { + return $this->fields; + } + + public function buildFields() + { + $keys = array( + 'topic', + 'tokenArray' + ); + foreach ($keys as $key) { + if (isset($this->$key)) { + $this->fields[$key] = $this->$key; + } + } + } +}