-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dario Trbovic
committed
Oct 22, 2020
1 parent
9e732e6
commit 4f9e49c
Showing
45 changed files
with
1,080 additions
and
1,204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea/ | ||
.php_cs.cache | ||
vendor | ||
php-cs-fixer-v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Huawei\\": "src/" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
587 changes: 182 additions & 405 deletions
587
...sh_common/test_sample_push_msg_common.php → src/Example/PushCommon/TestPushMsgCommon.php
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Huawei\Example\PushCommon; | ||
|
||
use Huawei\PushNotifications\PushAdmin\Application; | ||
use Huawei\PushNotifications\PushAdmin\Constants; | ||
use Huawei\PushNotifications\PushAdmin\PushConfig; | ||
use Huawei\PushNotifications\PushAdmin\PushLogConfig; | ||
use Huawei\PushNotifications\TopicMsg; | ||
|
||
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->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.