Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea/
.php_cs.cache
vendor
php-cs-fixer-v2
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used this php architecture since 3rd attribute

"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/"
}
}
}
19 changes: 19 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added php-cs-fixer-v2.phar
Binary file not shown.

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions src/Example/PushCommon/TestTopicCommonSample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example/test_sample_push_topic_msg.php has it,not need it


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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is "Huawei" Directory? the same

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include using has verify in linux and windows,not necessary to 'use'

use Huawei\Example\PushCommon\TestPushMsgCommon;

$testPushMsgSample = new TestPushMsgCommon();
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::APN_MSG_TYPE);
Expand Down Expand Up @@ -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));
}




Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include using has verify in linux and windows,not necessary to 'use'

use Huawei\Example\PushCommon\TestPushMsgCommon;

$testPushMsgSample = new TestPushMsgCommon();

Expand Down Expand Up @@ -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));

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include using has verify in linux and windows,not necessary to 'use'

use Huawei\Example\PushCommon\TestPushMsgCommon;

$testPushMsgSample = new TestPushMsgCommon();
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_FASTAPP_MSG_TYPE);
Expand All @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include using has verify in linux and windows,not necessary to 'use'

use Huawei\Example\PushCommon\TestPushMsgCommon;

$testPushMsgSample = new TestPushMsgCommon();
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_NOTIFICATION_MSG_TYPE);
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include using has verify in linux and windows,not necessary to 'use'

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);
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,23 @@
/**
* 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');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include using has verify in linux and windows,not necessary to 'use'

use push_admin\Constants;
use Huawei\PushNotifications\PushAdmin\Constants;
use Huawei\Example\PushCommon\TestPushMsgCommon;

$testPushMsgSample = new TestPushMsgCommon();

$topicSubscribeFlag = true;
$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",
Expand Down Expand Up @@ -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));
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include using has verify in linux and windows,not necessary to 'use'

use Huawei\PushNotifications\PushAdmin\Constants;
use Huawei\Example\PushCommon\TestPushMsgCommon;

$testPushMsgSample = new TestPushMsgCommon();
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::WEB_PUSH_MSG_TYPE);
Expand Down Expand Up @@ -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));
}
Loading