Skip to content

Commit 813dff3

Browse files
author
Dario Trbovic
committed
User composer.json and autoload
1 parent 9e732e6 commit 813dff3

45 files changed

Lines changed: 1080 additions & 1204 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea/
2+
.php_cs.cache
3+
vendor
4+
php-cs-fixer-v2

composer.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "HMS-Core/hms-push-php",
3+
"type": "library",
4+
"license": "MIT",
5+
"homepage": "https://github.com/HMS-Core/hms-push-serverdemo-php",
6+
"description": "PHP support for HMS push notifications",
7+
"keywords": [
8+
"push notifications",
9+
"huawei push notifications",
10+
"hms"
11+
],
12+
"authors": [
13+
{
14+
"name": "codecov.io",
15+
"email": "hello@codecov.io"
16+
}
17+
],
18+
"require": {
19+
"php": ">=7.0"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Huawei\\": "src/"
24+
}
25+
}
26+
}

composer.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

php-cs-fixer-v2.phar

1.77 MB
Binary file not shown.

src/example/push_common/test_sample_push_msg_common.php renamed to src/Example/PushCommon/TestPushMsgCommon.php

Lines changed: 182 additions & 405 deletions
Large diffs are not rendered by default.
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Huawei\Example\PushCommon;
6+
7+
use Huawei\PushNotifications\PushAdmin\Application;
8+
use Huawei\PushNotifications\PushAdmin\Constants;
9+
use Huawei\PushNotifications\PushAdmin\PushConfig;
10+
use Huawei\PushNotifications\PushAdmin\PushLogConfig;
11+
use Huawei\PushNotifications\TopicMsg;
12+
13+
class TestTopicCommonSample
14+
{
15+
private $topic = "defaultTopic";
16+
17+
private $topic_msg_create_type = 1;
18+
19+
private $appsecret;
20+
21+
private $appid;
22+
23+
private $hw_token_server;
24+
25+
private $hw_topic_subscriber_server;
26+
27+
private $hw_topic_unsubscriber_server;
28+
29+
private $hw_topic_query_subscriber_server;
30+
31+
private $tokenServerKey;
32+
33+
private $log_suffix_show = ".............................";
34+
35+
public function __construct($topic_value = "", $default_msg_create_type = "")
36+
{
37+
if (! empty($topic_value)) {
38+
$this->topic = $topic_value;
39+
}
40+
if (! empty($default_msg_create_type)) {
41+
$this->topic_msg_create_type = $default_msg_create_type;
42+
}
43+
44+
$pushConfig = PushConfig::getSingleInstance();
45+
46+
$this->appsecret = $pushConfig->HW_APPSECRET;
47+
$this->appid = $pushConfig->HW_APPID;
48+
$this->hw_token_server = $pushConfig->HW_TOKEN_SERVER;
49+
$this->tokenServerKey = $pushConfig->HW_PUSH_TOKEN_ARR;
50+
51+
$this->hw_topic_subscriber_server = $pushConfig->HW_TOPIC_SUBSCRIBE_SERVER;
52+
$this->hw_topic_unsubscriber_server = $pushConfig->HW_TOPIC_UNSUBSCRIBE_SERVER;
53+
$this->hw_topic_query_subscriber_server = $pushConfig->HW_TOPIC_QUERY_SUBSCRIBER_SERVER;
54+
}
55+
56+
private function createTopicData()
57+
{
58+
$topicMsg = new TopicMsg();
59+
$topicMsg->setTopic($this->topic);
60+
$topicMsg->setTokenArray(array(
61+
$this->tokenServerKey
62+
));
63+
$topicMsg->buildFields();
64+
65+
return $topicMsg;
66+
}
67+
68+
private function createApplication($application_server)
69+
{
70+
$application = new Application($this->appid, $this->appsecret, $this->hw_token_server, $application_server);
71+
return $application;
72+
}
73+
74+
private function printLogMethodOperate($msg_type, $dataFlow, $functionName = "", $logLevel = "")
75+
{
76+
$dataFlow = 'subscribe topic ' . $dataFlow;
77+
$logModule = Constants::HW_PUSH_LOG_TOPIC_SUBSCRIBE_MODULE;
78+
switch ($msg_type) {
79+
case Constants::TOPIC_UNSUBSCRIBE_MSG_TYPE:
80+
{
81+
$dataFlow = 'unsubscribe topic' . $dataFlow;
82+
$logModule = Constants::HW_PUSH_LOG_TOPIC_UNSUBSCRIBE_MODULE;
83+
}
84+
break;
85+
}
86+
if (empty($logLevel)) {
87+
$logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL;
88+
}
89+
90+
if (empty($functionName)) {
91+
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule);
92+
} else {
93+
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[' . $functionName . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule);
94+
}
95+
}
96+
97+
private function printLogMsgOperate($msg_type, $dataFlow, $functionName = "", $logLevel = "")
98+
{
99+
$logModule = Constants::HW_PUSH_LOG_TOPIC_SUBSCRIBE_MODULE;
100+
switch ($msg_type) {
101+
case Constants::TOPIC_UNSUBSCRIBE_MSG_TYPE:
102+
{
103+
$logModule = Constants::HW_PUSH_LOG_TOPIC_UNSUBSCRIBE_MODULE;
104+
}
105+
break;
106+
}
107+
if (empty($logLevel)) {
108+
$logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL;
109+
}
110+
111+
if (empty($functionName)) {
112+
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule);
113+
} else {
114+
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[' . $functionName . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule);
115+
}
116+
}
117+
118+
/**
119+
* topic subscribe/unsubscribe
120+
*/
121+
public function sendTopicMessage($msg_type)
122+
{
123+
$this->printLogMethodOperate($msg_type, "start", __FUNCTION__ . ':' . __LINE__);
124+
$topicMsg = $this->createTopicData();
125+
if ($this->topic_msg_create_type == 1) {
126+
$this->printLogMsgOperate($msg_type, "topicMsg:" . json_encode($topicMsg->getFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL);
127+
}
128+
129+
$application_server = $this->hw_topic_subscriber_server;
130+
if ($msg_type == Constants::TOPIC_UNSUBSCRIBE_MSG_TYPE) {
131+
$application_server = $this->hw_topic_unsubscriber_server;
132+
} elseif ($msg_type == Constants::TOPIC_SUBSCRIBE_QUERY_MSG_TYPE) {
133+
$application_server = $this->hw_topic_query_subscriber_server;
134+
$topicMsg = array(
135+
'token' => $this->tokenServerKey
136+
);
137+
}
138+
$application = $this->createApplication($application_server);
139+
$this->printLogMsgOperate($msg_type, "application server:" . json_encode($application->getApplicationFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL);
140+
141+
$topicResult = "";
142+
if ($msg_type == Constants::TOPIC_SUBSCRIBE_QUERY_MSG_TYPE) {
143+
$topicResult = $application->commonSendMsg($topicMsg);
144+
} else {
145+
$topicResult = $application->commonSendMsg($topicMsg->getFields());
146+
}
147+
148+
$this->printLogMethodOperate($msg_type, "end", __FUNCTION__ . ':' . __LINE__);
149+
return $topicResult;
150+
}
151+
}
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
*/
1717

1818
/**
19-
* function: two kinds of method to send apn msg:
19+
* function: two kinds of method to send apn msg:
2020
* 1) sendPushMsgMessageByMsgType(code class object);
2121
* 2) sendPushMsgRealMessage(text msg)
2222
* 3) ios format may change,sometimes push msg depends of ios msg format
2323
*/
24-
include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php');
25-
include_once (dirname(__FILE__) . '/../push_admin/Constants.php');
26-
use push_admin\Constants;
24+
use Huawei\PushNotifications\PushAdmin\Constants;
25+
use Huawei\Example\PushCommon\TestPushMsgCommon;
2726

2827
$testPushMsgSample = new TestPushMsgCommon();
2928
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::APN_MSG_TYPE);
@@ -96,10 +95,6 @@
9695
);
9796

9897
foreach ($message_arr as $message) {
99-
$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->apn_push_token_key.'"',$message);
98+
$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->apn_push_token_key.'"', $message);
10099
$testPushMsgSample->sendPushMsgRealMessage(json_decode($message));
101100
}
102-
103-
104-
105-

src/example/test_sample_push_condition_msg.php renamed to src/Example/test_sample_push_condition_msg.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
* 2) sendPushMsgRealMessage(text msg)
2222
* 3) topic and condition not real time, maybe delay
2323
*/
24-
include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php');
25-
include_once (dirname(__FILE__) . '/../push_admin/Constants.php');
26-
use push_admin\Constants;
24+
use Huawei\PushNotifications\PushAdmin\Constants;
25+
use Huawei\Example\PushCommon\TestPushMsgCommon;
2726

2827
$testPushMsgSample = new TestPushMsgCommon();
2928

@@ -92,7 +91,6 @@
9291
}';
9392

9493
$topic = '111';
95-
$message=str_ireplace("*condition*", '"\''.$topic.'\' in topics"',$message);
94+
$message=str_ireplace("*condition*", '"\''.$topic.'\' in topics"', $message);
9695

9796
$testPushMsgSample->sendPushMsgRealMessage(json_decode($message));
98-

src/example/test_sample_push_instantce_app_msg.php renamed to src/Example/test_sample_push_instantce_app_msg.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
*/
1717

1818
/**
19-
* function: fast app,two kinds of method to send instance app msg:
19+
* function: fast app,two kinds of method to send instance app msg:
2020
* 1) sendPushMsgMessageByMsgType(code class object);
2121
* 2) sendPushMsgRealMessage(text msg)
2222
*/
23-
include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php');
24-
include_once (dirname(__FILE__) . '/../push_admin/Constants.php');
25-
use push_admin\Constants;
23+
use Huawei\PushNotifications\PushAdmin\Constants;
24+
use Huawei\Example\PushCommon\TestPushMsgCommon;
2625

2726
$testPushMsgSample = new TestPushMsgCommon();
2827
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_FASTAPP_MSG_TYPE);
@@ -44,6 +43,5 @@
4443
}';
4544

4645

47-
$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->fast_push_token.'"',$message);
48-
$testPushMsgSample->sendPushMsgRealMessage(json_decode($message),Constants::PUSHMSG_FASTAPP_MSG_TYPE);
49-
46+
$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->fast_push_token.'"', $message);
47+
$testPushMsgSample->sendPushMsgRealMessage(json_decode($message), Constants::PUSHMSG_FASTAPP_MSG_TYPE);

src/example/test_sample_push_notification_msg.php renamed to src/Example/test_sample_push_notification_msg.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
*/
1717

1818
/**
19-
* function: two kinds of method to send notification msg:
19+
* function: two kinds of method to send notification msg:
2020
* 1) sendPushMsgMessageByMsgType(code class object);
2121
* 2) sendPushMsgRealMessage(text msg)
2222
*/
23-
include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php');
24-
include_once (dirname(__FILE__) . '/../push_admin/Constants.php');
25-
use push_admin\Constants;
23+
use Huawei\PushNotifications\PushAdmin\Constants;
24+
use Huawei\Example\PushCommon\TestPushMsgCommon;
2625

2726
$testPushMsgSample = new TestPushMsgCommon();
2827
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_NOTIFICATION_MSG_TYPE);
@@ -69,6 +68,6 @@
6968
);
7069

7170
foreach ($message_arr as $message) {
72-
$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->hw_push_token_key.'"',$message);
71+
$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->hw_push_token_key.'"', $message);
7372
$testPushMsgSample->sendPushMsgRealMessage(json_decode($message));
74-
}
73+
}

0 commit comments

Comments
 (0)