Commit fc5b7e05 authored by 蔡闯's avatar 蔡闯

更新推送代码

parent 1844e0cc
...@@ -114,13 +114,14 @@ class Index extends Base ...@@ -114,13 +114,14 @@ class Index extends Base
public function getVacancyInfo() { public function getVacancyInfo() {
$vacancy_id = Request::param('vacancy_id'); $vacancy_id = Request::param('vacancy_id');
$data = Db::name('house_vacancy')->alias('hv') $data = Db::name('house_vacancy')->alias('hv')
->Join('house_village hvi','hvi.village_id = hv.village_id') ->leftJoin('house_village hvi','hvi.village_id = hv.village_id')
->Join('house_user_bind hub','hub.vacancy_id = hv.vacancy_id') ->leftJoin('house_user_bind hub','hub.vacancy_id = hv.vacancy_id')
->where(['hv.vacancy_id'=>$vacancy_id]) ->where(['hv.vacancy_id'=>$vacancy_id])
->field('hv.vacancy_code,hv.village_id,hv.parent_id,layout_id,hvi.village_name,hvi.village_address,hvi.province_name,hvi.city_name,hvi.area_name') ->field('hv.vacancy_code,hv.village_id,hv.parent_id,layout_id,hvi.village_name,hvi.village_address,hvi.province_name,hvi.city_name,hvi.area_name')
->find(); ->find();
$data['vacancy_address'] = Common::getVacancyAddress($data['vacancy_code'],$data['layout_id']); $data['vacancy_address'] = Common::getVacancyAddress($data['vacancy_code'],$data['layout_id']);
$data['vacancyOwnerInfo'] = Common::getOwnerInfo($vacancy_id); //物业信息 $data['vacancyOwnerInfo'] = Common::getOwnerInfo($vacancy_id); //业主信息
$data['isHasOwner'] = empty($data['vacancyOwnerInfo']) ? 0 : 1;
$data['getUserBindType'] = Common::getUserBindType(); $data['getUserBindType'] = Common::getUserBindType();
$data['getFamilyBindType'] = Common::getFamilyBindType(); $data['getFamilyBindType'] = Common::getFamilyBindType();
return $this->returnJson($data); return $this->returnJson($data);
......
...@@ -71,4 +71,6 @@ class News extends Base{ ...@@ -71,4 +71,6 @@ class News extends Base{
} }
\ No newline at end of file
...@@ -86,6 +86,7 @@ class User extends Base ...@@ -86,6 +86,7 @@ class User extends Base
//用户绑定房间 //用户绑定房间
public function userBindVacancy(){ public function userBindVacancy(){
//判断参数是否为空
$data['type'] = Request::param('type'); $data['type'] = Request::param('type');
$village_id = Request::param('village_id'); $village_id = Request::param('village_id');
$vacancy_id = Request::param('vacancy_id'); $vacancy_id = Request::param('vacancy_id');
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
namespace app\api\controller; namespace app\api\controller;
use app\common\controller\Common; use app\common\controller\Common;
use app\common\controller\Jpush;
use think\facade\Db; use think\facade\Db;
use think\facade\Request; use think\facade\Request;
...@@ -11,13 +12,10 @@ class Village extends Base ...@@ -11,13 +12,10 @@ class Village extends Base
{ {
//搜索小区 //搜索小区
public function test() { public function test() {
$phone = "135883180489";
$float_1 = 1.11111111111111111111111111111111111111111111111111111; $content = "新版本推送";
$float_2 = 1.11111111111111111111111111111111111111111111111111112; Jpush::push_oppo($phone,$content);
var_dump($float_1==$float_2);
} }
} }
\ No newline at end of file
...@@ -78,7 +78,6 @@ class Common extends BaseController ...@@ -78,7 +78,6 @@ class Common extends BaseController
return $data; return $data;
} }
//对数组中的图片字段进行日期转换 //对数组中的图片字段进行日期转换
public static function changeImg($data,$field="pic"){ public static function changeImg($data,$field="pic"){
if(empty($data)){ if(empty($data)){
...@@ -133,7 +132,6 @@ class Common extends BaseController ...@@ -133,7 +132,6 @@ class Common extends BaseController
} }
/** /**
* @param $url_ids string 1,2,3 * @param $url_ids string 1,2,3
* @param $navAl array * @param $navAl array
...@@ -873,6 +871,7 @@ class Common extends BaseController ...@@ -873,6 +871,7 @@ class Common extends BaseController
public static function getUserBindType() { public static function getUserBindType() {
return ['0'=>'业主','1'=>'家人','2'=>'租客','3'=>'替换业主']; return ['0'=>'业主','1'=>'家人','2'=>'租客','3'=>'替换业主'];
} }
//获取需要绑定人员设备 //获取需要绑定人员设备
public static function getFamilyBindType() { public static function getFamilyBindType() {
return ['1'=>'配偶','2'=>'父母','3'=>'子女','4'=>'亲戚','5'=>'好友']; return ['1'=>'配偶','2'=>'父母','3'=>'子女','4'=>'亲戚','5'=>'好友'];
...@@ -893,7 +892,7 @@ class Common extends BaseController ...@@ -893,7 +892,7 @@ class Common extends BaseController
//图片上传 //图片上传
public static function uploadImg($file,$path) { public static function uploadImg($file,$path) {
$ext = $file->getOriginalExtension(); $ext = $file->getOriginalExtension();
if(!in_array($ext,['pjpeg','jpeg','jpg','gif','bmp','png'])) { if(!in_array($ext,['jpeg','jpg','gif','bmp','png'])) {
return false; return false;
} }
......
<?php
namespace app\common\controller;
use \HwPush\push_admin\Application;
use \app\BaseController;
use think\facade\Db;
$file = dirname(dirname(dirname(__DIR__)))."/extend/jpush/autoload.php";
require_once $file;
class Jpush extends BaseController
{
public static $title = "微控云享智慧社区";
//推送所有的
public static function push($phone,$content){
self::push_mi($phone,$content);
self::push_huwei($phone,$content);
self::push_oppo($phone,$content);
self::push_meizu($phone,$content);
self::push_vivo($phone,$content);
self::push_jiguang($phone,$content);
}
/**
* mi推送代码测试,已通过
*/
public static function push_mi($phone,$content){
$alias = $phone;
$title = self::$title;
$desc = $content;
$sender = new \MiPush\xmpush\Sender();
$message1 = new \MiPush\xmpush\Builder();
$message1->title($title); // 通知栏的title
$message1->description($desc); // 通知栏的descption
$message1->passThrough(0); // 这是一条通知栏消息,如果需要透传,把这个参数设置成1,同时去掉title和descption两个参数
$message1->extra( \MiPush\xmpush\Builder::notifyForeground, 1); // 应用在前台是否展示通知,如果不希望应用在前台时候弹出通知,则设置这个参数为0
$message1->notifyId(2); // 通知类型。最多支持0-4 5个取值范围,同样的类型的通知会互相覆盖,不同类型可以在通知栏并存
$message1->build();
$sender->broadcast($message1, $alias)->getRaw();
}
/**
* huawei推送
*/
public static function push_huwei($phone,$content){
$application = Application::getInstance();
//设备token
$device = Db::name('push_device')->where(['phone'=>$phone,'type'=>1])->value('device_id',true);
$device_token = json_encode($device);
$title = self::$title;
$body = $content;
$res = $application->pushMsg($title,$body,$device_token);
}
/**
* oppo 推送
*/
public static function push_oppo($phone,$content){
$application = new \OPush\Application();
$title = self::$title;
$device = Db::name('push_device')->where(['phone'=>$phone,'type'=>2])->column('device_id');
foreach($device as $v){
$res = $application->pushTag($title,$content,$v);
}
}
/**
* meizu 推送
*/
public static function push_meizu($phone,$content){
$application = new \MzPush\Application();
$title = self::$title;
$res = $application->pushTag($title,$content,$phone);
}
/**
* 极光推送iso测试通过
*/
public static function push_jiguang($phone,$content){
$client = new \JPush\Client();
$alias = $phone;
//iso是通了的
$result = $client->push()
->setPlatform(array('all'))// 推送的all
->addAlias($alias)//
->setNotificationAlert($content)
->send();
}
/**
* vivo推送
*/
public static function push_vivo($phone,$content){
$application = new \ViPush\Application();
//别名推送
// $alias = $phone;
// $message = new \ViPush\Message();
// $message->setTitle(self::$title);
// $message->setContent($content);
// $message->setNotifyType(4);
// $message->setAlias($alias);
// $message->setSkipType();
// $message->setSkipType();
// $body = $message->build();
// $res = $application->pushAlias($body);
//tag推送,测试成功
$title = self::$title;
$tag[] = $phone;
return $res = $application->pushTag($title,$content,$tag);
}
}
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
"app\\": "app" "app\\": "app"
}, },
"psr-0": { "psr-0": {
"": "extend/" "": ["extend/","extend/jpush/"]
} }
}, },
"config": { "config": {
......
___ ___ __ __ __________ ____ ___ _________ ___ ___ __________ ___ _____________
/ | \/ \ / \ \______ \ | \/ _____// | \ \______ \/ | \______ \
/ ~ \ \/\/ / | ___/ | /\_____ \/ ~ \ | ___/ ~ \ ___/
\ Y /\ / | | | | / / \ Y / | | \ Y / |
\___|_ / \__/\ / |____| |______/ /_______ /\___|_ / |____| \___|_ /|____|
\/ \/ \/ \/ \/
********************************************************************************************
********** instruction: 1)two part:private personal data and public url **********
********** 2)don't change split character such as =/" **********
********** 3)don't new line for HW_PUSH_TOKEN_ARR **********
********** 4)Space will be removed, cannot be a variable **********
********************************************************************************************
********************************************************************************************
********** here is private variable personal data,you must change it! **********
********************************************************************************************
HW_APPID="102526607"
HW_APPSECRET="xxxxx"
### Business Push Token,For common push msg ####
HW_PUSH_TOKEN_ARR="xxxxx"
### Business Push Token,For IOS apn ####
APN_PUSH_TOKEN_ARR="xxxxx"
### Business Push Token,For webpush ####
WEBPUSH_PUSH_TOKEN_ARR="xxxxx"
### FAST APP INFO : different from ordinal app####
HW_FAST_APPID="xxxxx"
HW_FAST_APPSECRET="xxxxx"
HW_FAST_PUSH_TOKEN="xxxxx"
********************************************************************************************
********** below is public url entry,please don't modify if not necessary **********
********************************************************************************************
### Token Server for push msg and top subscribe/unsubscribe ####
HW_TOKEN_SERVER="https://oauth-login.cloud.huawei.com/oauth2/v2/token"
### Push Server address ####
HW_PUSH_SERVER="https://push-api.cloud.huawei.com/v1/{appid}/messages:send"
### Topic Server address ####
HW_TOPIC_SUBSCRIBE_SERVER="https://push-api.cloud.huawei.com/v1/{appid}/topic:subscribe"
HW_TOPIC_UNSUBSCRIBE_SERVER="https://push-api.cloud.huawei.com/v1/{appid}/topic:unsubscribe"
HW_TOPIC_QUERY_SUBSCRIBER_SERVER="https://push-api.cloud.huawei.com/v1/{appid}/topic:list"
### LogLevel:ERROR(1),WARN(2),INFO(3),DEBUG(4) ####
HW_DEFAULT_LOG_LEVEL=3
a:2:{s:12:"access_token";s:88:"CgB6e3x9DjmYP/VKIURJlMrbQYzgvbJ5jcQvQA4i6Ep3t6OcuafHoeuico454a///E3mnDQ5YITryXcTWvUz+ynR";s:11:"expire_time";i:1611370987;}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* 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;
$testPushMsgSample = new TestPushMsgCommon();
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::APN_MSG_TYPE);
$message_arr = array(
'{
"token": [*push_token*],
"apns": {
"hms_options": {
"target_user_type": 1
},
"payload": {
"aps": {
"alert": {
"title": "hw1 message title",
"body": "hw message body",
"action-loc-key": "PLAY"
},
"badge": 5
},
"acme1": "bar",
"acme2": ["bang",
"whiz"]
}
}
}',
'{
"token": [*push_token*],
"apns": {
"hms_options": {
"target_user_type": 1
},
"payload": {
"aps": {
"alert": {
"title": "hw2 message title",
"body": "hw3 message body",
"action-loc-key": "PLAY"
},
"badge": 5
},
"acme1": "bar",
"acme2": ["bang",
"whiz"],
"sound": "default",
"launch-image": "https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"
}
}
}',
'{
"token": [*push_token*],
"apns": {
"hms_options": {
"target_user_type": 1
},
"payload":{
"aps" : {
"alert" : {
"title" : "Game3 Request",
"body" : "Bob3 wants to play poker",
"action-loc-key" : "PLAY"
},
"badge" : 5
},
"acme1" : "bar",
"acme2" : [ "bang", "whiz" ]
}
}
}'
);
foreach ($message_arr as $message) {
$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->apn_push_token_key.'"',$message);
$testPushMsgSample->sendPushMsgRealMessage(json_decode($message));
}
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: two kinds of method to send condition msg: sendPushTopicMsgMessage fro subscribe topic
* 1) sendPushMsgMessageByMsgType(code class object);
* 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;
$testPushMsgSample = new TestPushMsgCommon();
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_CONDITION_MSG_TYPE);
$message = '{
"android": {
"collapse_key": -1,
"urgency": "HIGH",
"ttl": "1448s",
"bi_tag": "Trump",
"notification": {
"title": " condition1 default hw title condition ",
"body": " condition1 default hw body condition ",
"color": "#AACCDD",
"tag": "tagBoom",
"click_action": {
"type": 1,
"intent": "#Intent;compo=com.rvr\/.Activity;S.W=U;end",
"rich_resource": "test rich resource",
"action": "test add"
},
"body_loc_key": "M.String.body",
"body_loc_args": ["Boy",
"Dog"],
"title_loc_key": "M.String.title",
"title_loc_args": ["Girl",
"Cat"],
"channel_id": "RingRing",
"notify_summary": "Some Summary",
"style": 0,
"big_title": "Big Boom Title",
"big_body": "Big Boom Body",
"auto_clear": 86400000,
"notify_id": 486,
"group": "Espace",
"badge": {
"add_num": 99,
"class": "Classic",
"set_num": 99
},
"ticker": "i am a ticker",
"auto_cancel": false,
"when": "2019-11-05",
"importance": "NORMAL",
"use_default_vibrate": true,
"use_default_light": false,
"vibrate_config": ["1.5",
"2.000000001",
"3"],
"visibility": "PUBLIC",
"light_settings": {
"color": {
"alpha": 0,
"red": 0,
"green": 1,
"blue": 1
},
"light_on_duration": "3.5",
"light_off_duration": "5S"
},
"foreground_show": true
}
},
"condition": *condition*
}';
$topic = '111';
$message=str_ireplace("*condition*", '"\''.$topic.'\' in topics"',$message);
$testPushMsgSample->sendPushMsgRealMessage(json_decode($message));
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* 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;
$testPushMsgSample = new TestPushMsgCommon();
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_FASTAPP_MSG_TYPE);
$message = '{
"data": "{\"pushtype\":1,\"pushbody\":{\"messageId\":\"111110001\",\"data\":\"test pass-through msg\"}}",
"ssss":"{k1:v1}",
"android": {
"collapse_key": -1,
"urgency": "HIGH",
"ttl": "1448s",
"bi_tag": "Trump",
"fast_app_target": 1
},
"token": [
*push_token*
]
}';
$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->fast_push_token.'"',$message);
$testPushMsgSample->sendPushMsgRealMessage(json_decode($message),Constants::PUSHMSG_FASTAPP_MSG_TYPE);
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* 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;
$testPushMsgSample = new TestPushMsgCommon();
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_NOTIFICATION_MSG_TYPE);
$message_arr = array(
'{
"notification": {
"title": "Big News1",
"body": "This is a Big News!",
"image": "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2_0.png"
},
"android": {
"notification": {
"click_action": {
"type": 1,
"intent": "#Intent;compo=com.rvr/.Activity;S.W=U;end"
}
}
},
"token": [*push_token*]
}',
'{
"notification": {
"title": "Big News",
"body": "This is a Big News!",
"image": "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2_0.png"
},
"android": {
"notification": {
"title": " real notification default hw title notification2 ",
"body": " real notification default hw body notification ",
"color": "#AACCDD",
"click_action": {
"type": 1,
"intent": "#Intent;compo=com.rvr/.Activity;S.W=U;end"
}
}
},
"token": [*push_token*]
}'
);
foreach ($message_arr as $message) {
$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->hw_push_token_key.'"',$message);
$testPushMsgSample->sendPushMsgRealMessage(json_decode($message));
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* 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;
$testPushMsgSample = new TestPushMsgCommon();
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_PASS_THROUGHT_MSG_TYPE);
$message_arr = array(
'{
"data": "hw test default data1",
"token": [*push_token*]
}',
'{
"data": "k=v,k=v2",
"android": {
"collapse_key": -1,
"ttl": "10000s",
"bi_tag": "the_sample_bi_tag_for_receipt_service"
},
"token": [*push_token*]
}',
'{
"data": "k=v,k=v",
"android": {
"data": "pass through real data3",
"collapse_key": -1,
"ttl": "10000s",
"bi_tag": "the_sample_bi_tag_for_receipt_service"
},
"token": [*push_token*]
}'
);
foreach ($message_arr as $message) {
$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->hw_push_token_key.'"',$message);
$testPushMsgSample->sendPushMsgRealMessage(json_decode($message));
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: two kinds of method to send topic msg: sendPushTopicMsgMessage for subscribe topic
* 1) sendPushMsgMessageByMsgType(code class object);
* 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;
$testPushMsgSample = new TestPushMsgCommon();
$topicSubscribeFlag = true;
$topic = '111';
//first time,must subscribe then could receive push msg;
if ($topicSubscribeFlag == false){
$testPushMsgSample->sendPushTopicMsgMessage($topic);
}
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_TOPIC_MSG_TYPE,$topic);
$message_arr = array('{
"data": "1111",
"android": {
"notification": {
"title": " topic1 default hw title topic ",
"body": " topic1 default hw body topic ",
"color": "#AACCDD",
"tag": "tagBoom",
"click_action": {
"type": 1,
"intent": "#Intent;compo=com.rvr\/.Activity;S.W=U;end",
"rich_resource": "test rich resource",
"action": "test add"
}
}
},
"topic": *topic*
}','{
"data": "1111",
"android": {
"notification": {
"title": " topic2 default hw title topic ",
"body": " topic2 default hw body topic ",
"click_action": {
"type": 1,
"intent": "#Intent;compo=com.rvr\/.Activity;S.W=U;end"
}
}
},
"topic": *topic*
}');
foreach ($message_arr as $message) {
$message=str_ireplace("*topic*", '"'.$topic.'"',$message);
$testPushMsgSample->sendPushMsgRealMessage(json_decode($message));
}
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* 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;
$testPushMsgSample = new TestPushMsgCommon();
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::WEB_PUSH_MSG_TYPE);
$message_arr = array('{
"token": [*push_token*],
"webpush": {
"headers": {
"ttl": "990",
"topic": "12313ceshi",
"urgency": "very-low"
},
"data": "test webpush data",
"notification": {
"title": "web2 push title test",
"body": "web2 push body",
"icon": "https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png",
"image": "https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png",
"lang": "string",
"tag": "string",
"badge": "string",
"dir": "auto",
"vibrate": [1,
2,
3],
"renotify": false,
"require_interaction": false,
"silent": false,
"timestamp": 1545201266,
"actions": [{
"title": "string",
"icon": "https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png",
"action": "123"
}]
},
"hms_options": {
"link": "https://www.cctv.com/"
}
}
}',
'{
"token": [*push_token*],
"webpush": {
"headers": {
"ttl": "11990",
"topic": "test",
"urgency": "low"
},
"data": "test webpush data",
"notification": {
"title": "hw default web push title test",
"body": "hw default web push body",
"require_interaction": false,
"silent": false,
"timestamp": 1545201266,
"actions": [{
"title": "string",
"icon": "https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png",
"action": "123"
}]
},
"hms_options": {
"link": "https://www.huawei.com/"
}
}
}'
);
foreach ($message_arr as $message) {
$message=str_ireplace("*push_token*", '"'.$testPushMsgSample->webpush_push_token_key.'"',$message);
$testPushMsgSample->sendPushMsgRealMessage(json_decode($message));
}
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
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;
$testPushMsgSample = new TestPushMsgCommon();
$testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_NOTIFICATION_MSG_TYPE);
This diff is collapsed.
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: const variables
*/
namespace HwPush\push_admin;
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;
/**
* 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;
}
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: read config file and make it applicaitonable
*/
namespace HwPush\push_admin;
class PushConfig
{
// ORDINAL APP
public $HW_APPID;
public $HW_APPSECRET;
public $HW_PUSH_TOKEN_ARR;
public $APN_PUSH_TOKEN_ARR;
public $WEBPUSH_PUSH_TOKEN_ARR;
// FAST APP
public $HW_FAST_APPID;
public $HW_FAST_APPSECRET;
public $HW_FAST_PUSH_TOKEN;
public $HW_TOKEN_SERVER;
public $HW_PUSH_SERVER;
public $HW_TOPIC_SUBSCRIBE_SERVER;
public $HW_TOPIC_UNSUBSCRIBE_SERVER;
public $HW_TOPIC_QUERY_SUBSCRIBER_SERVER;
public $HW_DEFAULT_LOG_LEVEL = 3;
private $log_read_flag = true; //false,是否记入日志
private function __construct()
{
if ($this->log_read_flag == false) {
$file_path = "../config.ini";
if (file_exists($file_path)) {
$file_contents = file($file_path);
// read line
for ($i = 0; $i < count($file_contents); $i ++) {
$this->processConfigData($file_contents[$i]);
}
$this->log_read_flag = true;
} else {
echo $file_path . " not exist,please config first!!!<br>";
}
}
}
public static function getSingleInstance()
{
static $obj;
if (! isset($obj)) {
$obj = new PushConfig();
}
return $obj;
}
private function processConfigData($lineData)
{
if (empty($lineData)) {
return;
}
if (strncmp($lineData, "#", 1) == 0) {
return;
}
$lineData = str_replace("\"", "", $lineData);
$lineData = str_replace("\'", "", $lineData);
$lineData = str_replace(" ", "", $lineData);
$lineData = str_replace(";", "", $lineData);
$order=array("\r\n","\n","\r");
$lineData=str_replace($order,"",$lineData);
$lineData = str_replace(PHP_EOL, '', $lineData);
$resultPos = stripos($lineData, "=");
if (FALSE == $resultPos) {
return;
}
$key = substr($lineData, 0, $resultPos);
if (FALSE == $key) {
return;
}
$value = $this->processConfigValueData(substr($lineData, $resultPos + 1));
switch ($key) {
case "HW_APPID":
{
$this->HW_APPID = $value;
}
break;
case "HW_APPSECRET":
{
$this->HW_APPSECRET = $value;
}
break;
case "HW_TOKEN_SERVER":
{
$this->HW_TOKEN_SERVER = $value;
}
break;
case "HW_PUSH_SERVER":
{
$this->HW_PUSH_SERVER = $value;
}
break;
case "HW_TOPIC_SUBSCRIBE_SERVER":
{
$this->HW_TOPIC_SUBSCRIBE_SERVER = $value;
}
break;
case "HW_TOPIC_UNSUBSCRIBE_SERVER":
{
$this->HW_TOPIC_UNSUBSCRIBE_SERVER = $value;
}
break;
case "HW_TOPIC_QUERY_SUBSCRIBER_SERVER":
{
$this->HW_TOPIC_QUERY_SUBSCRIBER_SERVER = $value;
}
break;
case "HW_PUSH_TOKEN_ARR":
{
$this->HW_PUSH_TOKEN_ARR = $value;
}
break;
case "APN_PUSH_TOKEN_ARR":
{
$this->APN_PUSH_TOKEN_ARR = $value;
}
break;
case "WEBPUSH_PUSH_TOKEN_ARR":
{
$this->WEBPUSH_PUSH_TOKEN_ARR = $value;
}
break;
case "HW_DEFAULT_LOG_LEVEL":
{
$this->HW_DEFAULT_LOG_LEVEL = $value;
}
break;
case "HW_FAST_APPID":
{
$this->HW_FAST_APPID = $value;
}
break;
case "HW_FAST_APPSECRET":
{
$this->HW_FAST_APPSECRET = $value;
}
break;
case "HW_FAST_PUSH_TOKEN":
{
$this->HW_FAST_PUSH_TOKEN = $value;
}
break;
}
}
private function processConfigValueData($lineDataMapValue)
{
$key = stripos($lineDataMapValue, "\"");
if (FALSE == $key) {
return $lineDataMapValue;
}
if ($key > 0) {
return str_replace("\"", "", substr($lineDataMapValue, $key));
}
return $lineDataMapValue;
}
}
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
namespace HwPush\push_admin;
include_once (dirname(__FILE__) . '/Constants.php');
include_once (dirname(__FILE__) . '/PushConfig.php');
use Exception;
class PushLogConfig
{
private $LogFile;
private $logBanner = "
___ ___ __ __ __________ ____ ___ _________ ___ ___ __________ ___ _____________
/ | \/ \ / \ \______ \ | \/ _____// | \ \______ \/ | \______ \
/ ~ \ \/\/ / | ___/ | /\_____ \/ ~ \ | ___/ ~ \ ___/
\ Y /\ / | | | | / / \ Y / | | \ Y / |
\___|_ / \__/\ / |____| |______/ /_______ /\___|_ / |____| \___|_ /|____|
\/ \/ \/ \/ \/
";
private $LOG_MODULE_FIXED_LEN = 20;
private $default_log_level = 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');
}
fwrite($this->LogFile, $this->logBanner);
$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;
}
}
/**
* single instance
*/
public static function getSingleInstance()
{
static $obj;
if (! isset($obj)) {
$obj = new PushLogConfig();
}
return $obj;
}
/**
* core log process
*/
public function LogMessage($msg, $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL, $module = null, $timeZone = 'Asia/shanghai', $timeFormat = "%Y-%m-%d %H:%M:%S")
{
if (empty($logLevel)) {
$logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL;
}
if ($logLevel > $this->default_log_level) {
return;
}
date_default_timezone_set($timeZone);
$time = strftime($timeFormat, time());
$msg = str_replace("\t", '', $msg);
$msg = str_replace("\n", '', $msg);
$strLogLevel = $this->levelToString($logLevel);
if (isset($module)) {
$module = '[' . str_pad(str_replace(array(
"\n",
"\t"
), array(
"",
""
), $module), $this->LOG_MODULE_FIXED_LEN) . ']';
$logLine = "$time\t$strLogLevel\t$module\t$msg\r\n";
} else {
$logLine = "$time\t$strLogLevel\t$msg\r\n";
}
print_r($logLine . '<br>');
fwrite($this->LogFile, $logLine);
}
private function levelToString($logLevel)
{
$ret = 'LOG::UNKNOWN';
switch ($logLevel) {
case Constants::HW_PUSH_LOG_DEBUG_LEVEL:
$ret = 'LOG::DEBUG';
break;
case Constants::HW_PUSH_LOG_INFO_LEVEL:
$ret = 'LOG::INFO';
break;
case Constants::HW_PUSH_LOG_WARN_LEVEL:
$ret = 'LOG::WARNING';
break;
case Constants::HW_PUSH_LOG_ERROR_LEVEL:
$ret = 'LOG::ERROR';
break;
}
return $ret;
}
}
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: push message push control parameter:
* 5 kinds of msg payload:$data,$notification,$android,$apns,$webpush
* 3 kinds of Message sending object:$token,$topic,$condition
*/
namespace push_admin\push_msg;
class PushMessage
{
private $data;
private $notification;
private $android;
private $apns;
private $webpush;
private $token;
private $topic;
private $condition;
private $fields;
public function __construct()
{
$this->fields = array();
$this->token = null;
$this->condition = null;
$this->topic = null;
$this->notification = null;
}
public function data($value)
{
$this->data = $value;
}
public function notification($value)
{
$this->notification = $value;
}
public function android($value)
{
$this->android = $value;
}
public function token($value)
{
$this->token = $value;
}
public function get_token(){
return $this->token;
}
public function topic($value)
{
$this->topic = $value;
}
public function condition($value)
{
$this->condition = $value;
}
public function apns($value)
{
$this->apns = $value;
}
public function webpush($value)
{
$this->webpush = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{
$keys = array(
'data',
'notification',
'android',
'token',
'topic',
'condition',
'apns',
'webpush'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
namespace push_admin;
class ValidatorUtil{
function validatePattern($pattern,$value){
$result = preg_match($pattern, $value);
if (1 == $result){
return TRUE;
}
return FALSE;
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
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');
use push_admin\ValidatorUtil;
use push_admin\Constants;
use push_admin\AndroidConfigDeliveryPriority;
use Exception;
use push_admin\PushLogConfig;
class AndroidConfig
{
private $collapse_key;
private $category;
private $urgency;
private $ttl;
private $bi_tag;
private $fast_app_target;
private $notification;
private $fields;
private $data;
public function __construct()
{
$this->urgency = null;
$this->notification = null;
$this->fields = array();
}
public function getFields()
{
return $this->fields;
}
public function collapse_key($value)
{
$this->collapse_key = $value;
}
public function category($value)
{
$this->category = $value;
}
public function urgency($value)
{
$this->urgency = $value;
}
public function ttl($value)
{
$this->ttl = $value;
}
public function bi_tag($value)
{
$this->bi_tag = $value;
}
public function fast_app_target($value)
{
$this->fast_app_target = $value;
}
public function notification($value)
{
$this->notification = $value;
}
public function data($value)
{
$this->data = $value;
}
public function buildFields()
{
try {
$this->check_parameter();
} catch (Exception $e) {
// echo $e;
PushLogConfig::getSingleInstance()->LogMessage($e,Constants::HW_PUSH_LOG_ERROR_LEVEL);
return;
}
$keys = array(
'collapse_key',
'category',
'urgency',
'ttl',
'bi_tag',
'fast_app_target',
'notification',
'data'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
private function check_parameter()
{
if (! empty($this->collapse_key) && ($this->collapse_key < - 1 || $this->collapse_key > 100)) {
throw new Exception("Collapse Key should be [-1, 100]");
}
if (! empty($this->fast_app_target) && ! in_array($this->fast_app_target, array(
1,
2
))) {
throw new Exception("Invalid fast app target type[one of 1 or 2]");
}
if (! empty($this->urgency) && ! in_array($this->urgency, array(
AndroidConfigDeliveryPriority::PRIORITY_HIGH,
AndroidConfigDeliveryPriority::PRIORITY_NORMAL
))) {
throw new Exception("delivery priority shouid be [HIGH, NOMAL]");
}
if (! empty($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
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
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');
use push_admin\ValidatorUtil;
use push_admin\Constants;
use push_admin\NotificationPriority;
use push_admin\Visibility;
use Exception;
use push_admin\PushLogConfig;
/**
* 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 $image;
private $notify_icon;
/**
* notification style:
* 0:default
* 1:big text
* 2:big photo
*/
private $style;
private $big_title;
private $big_body;
private $auto_clear;
private $notify_id;
private $group;
private $badge;
private $ticker;
private $auto_cancel;
private $when;
private $importance;
private $use_default_vibrate;
private $use_default_light;
private $vibrate_config;
private $visibility;
private $light_settings;
private $foreground_show;
private $fields;
public function __construct()
{
$this->click_action = array();
$this->body_loc_args = array();
$this->title_loc_args = array();
$this->badge = array();
$this->light_settings = array();
$this->foreground_show = true;
$this->fields = array();
}
public function title($value)
{
$this->title = $value;
}
public function body($value)
{
$this->body = $value;
}
public function icon($value)
{
$this->icon = $value;
}
public function color($value)
{
$this->color = $value;
}
public function sound($value)
{
$this->sound = $value;
}
public function tag($value)
{
$this->tag = $value;
}
public function click_action($value)
{
$this->click_action = $value;
}
public function body_loc_key($value)
{
$this->body_loc_key = $value;
}
public function body_loc_args($value)
{
$this->body_loc_args = $value;
}
public function title_loc_key($value)
{
$this->title_loc_key = $value;
}
public function title_loc_args($value)
{
$this->title_loc_args = $value;
}
public function channel_id($value)
{
$this->channel_id = $value;
}
public function notify_summary($value)
{
$this->notify_summary = $value;
}
// added
public function image($value)
{
$this->image = $value;
}
public function notify_icon($value)
{
$this->notify_icon = $value;
}
public function style($value)
{
$this->style = $value;
}
public function big_title($value)
{
$this->big_title = $value;
}
public function big_body($value)
{
$this->big_body = $value;
}
public function auto_clear($value)
{
$this->auto_clear = $value;
}
public function notify_id($value)
{
$this->notify_id = $value;
}
public function group($value)
{
$this->group = $value;
}
public function badge($value)
{
$this->badge = $value;
}
public function ticker($value)
{
$this->ticker = $value;
}
public function auto_cancel($value)
{
$this->auto_cancel = $value;
}
public function when($value)
{
$this->when = $value;
}
public function importance($value)
{
$this->importance = $value;
}
public function use_default_vibrate($value)
{
$this->use_default_vibrate = $value;
}
public function use_default_light($value)
{
$this->use_default_light = $value;
}
public function vibrate_config($value)
{
$this->vibrate_config = $value;
}
public function visibility($value)
{
$this->visibility = $value;
}
public function light_settings($value)
{
$this->light_settings = $value;
}
public function foreground_show($value)
{
$this->foreground_show = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{
try {
$this->check_parameter();
} catch (Exception $e) {
PushLogConfig::getSingleInstance()->LogMessage($e,Constants::HW_PUSH_LOG_ERROR_LEVEL);
return;
}
$keys = array(
'title',
'body',
'image',
'icon',
'color',
'sound',
'tag',
'click_action',
'body_loc_key',
'body_loc_args',
'title_loc_key',
'title_loc_args',
'channel_id',
'notify_summary',
'notify_icon',
'style',
'big_title',
'big_body',
'auto_clear',
'notify_id',
'group',
'badge',
'ticker',
'auto_cancel',
'when',
'importance',
'use_default_vibrate',
'use_default_light',
'vibrate_config',
'visibility',
'light_settings',
'foreground_show'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
private function check_parameter()
{
if (empty($this->title))
{
throw new Exception("title should be set");
}
if (empty($this->body))
{
throw new Exception("body should be set");
}
if (! empty($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)) {
throw new Exception("bodyLocKey is required when specifying bodyLocArgs");
}
if (! empty($this->title_loc_args) && empty($this->title_loc_key)) {
throw new Exception("titleLocKey is required when specifying titleLocArgs");
}
if (! empty($this->image)) {
if (FALSE == ValidatorUtil::validatePattern(Constants::URL_PATTERN, $this->image)) {
throw new Exception("notifyIcon must start with https");
}
}
if (($this->style) && (gettype($this->style) != "integer")) {
throw new Exception("type of style is wrong.");
}
if (! in_array($this->style, array(
0,
1
))) {
throw new Exception("style should be one of 0:default, 1: big text");
}
// importance
if (! empty($this->importance) && ! in_array($this->importance, array(
NotificationPriority::NOTIFICATION_PRIORITY_LOW,
NotificationPriority::NOTIFICATION_PRIORITY_NORMAL,
NotificationPriority::NOTIFICATION_PRIORITY_HIGH,
))) {
throw new Exception("notification priority shouid be [LOW,NORMAL,HIGH]");
}
// vibrate_config
if (! empty($this->vibrate_config)) {
foreach ($this->vibrate_config as $key) {
if (FALSE == ValidatorUtil::validatePattern(Constants::VIBRATE_PATTERN, $key)) {
throw new Exception("Wrong vibrate timing format");
}
}
}
// visibility
if (! empty($this->visibility) && ! in_array($this->visibility, array(
Visibility::VISIBILITY_UNSPECIFIED,
Visibility::PRIVATE_STR,
Visibility::PUBLIC_STR,
Visibility::SECRET_STR
))) {
throw new Exception("visibility shouid be [VISIBILITY_UNSPECIFIED, PRIVATE, PUBLIC, SECRET]");
}
// auto_clear
if (($this->auto_clear) && (gettype($this->auto_clear) != "integer")) {
throw new Exception("type of auto_clear is wrong.");
}
// notify_id
if (($this->notify_id) && (gettype($this->notify_id) != "integer")) {
throw new Exception("type of notify_id is wrong.");
}
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: Badge class =>AndroidNotification(badge)
* =>AndroidConfig(notification)
* =>PushMessage(android)
*/
namespace push_admin\push_msg\android;
use Exception;
class Badge
{
private $add_num;
private $class;
private $set_num;
private $fields;
public function __construct()
{
$this->fields = array();
}
public function add_num($value)
{
$this->add_num = $value;
}
public function setclass($value)
{
$this->class = $value;
}
public function set_num($value)
{
$this->set_num = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{
try {
$this->check_parameter();
} catch (Exception $e) {
echo $e;
}
$keys = array(
'add_num',
'class',
'set_num'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
private function check_parameter()
{
if (($this->add_num) && (gettype($this->add_num) != "integer")) {
throw new Exception("type of add_num is wrong.");
}
if (is_int($this->add_num) && ($this->add_num < 1 || $this->add_num > 100)) {
throw new Exception("add_num should locate between 0 and 100");
}
if (($this->set_num) && (gettype($this->set_num) != "integer")) {
throw new Exception("type of set_num is wrong.");
}
if (is_int($this->set_num) && ($this->set_num < 1 || $this->set_num > 100)) {
throw new Exception("set_num should locate between 0 and 100");
}
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: ClickAction class =>AndroidNotification(clickaction)
* =>AndroidConfig(notification)
* =>PushMessage(android)
*/
namespace push_admin\push_msg\android;
include_once (dirname(__FILE__) . '/../ValidatorUtil.php');
use push_admin\ValidatorUtil;
use Exception;
class ClickAction
{
private $type;
private $intent;
private $url;
private $rich_resource;
// added
private $action;
private $fields;
public function __construct()
{
$this->rich_resource = null;
$this->url = null;
}
public function type($value)
{
$this->type = $value;
}
public function intent($value)
{
$this->intent = $value;
}
public function url($value)
{
$this->url = $value;
}
public function rich_resource($value)
{
$this->rich_resource = $value;
}
// added
public function action($value)
{
$this->action = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{
try {
$this->check_parameter();
} catch (Exception $e) {
echo $e;
}
$keys = array(
'type',
'intent',
'url',
'rich_resource',
// add
'action'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
private function check_parameter()
{
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))){
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){
case 1:{
if (is_null($this->intent) && is_null($this->action)) {
throw new Exception("when type=1,intent/action at least one is valid");
}
}
break;
case 2:{
if (is_null($this->url)){
throw new Exception("url is required when click type=2");
}
if (FALSE == ValidatorUtil::validatePattern($PATTERN,$this->url)){
throw new Exception("url must start with https");
}
}
break;
case 4:{
if (is_null($this->richResource)){
throw new Exception("richResource is required when click type=4");
}
if (FALSE == ValidatorUtil::validatePattern($PATTERN,$this->richResource)){
throw new Exception("richResource must start with https");
}
}
break;
}
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: LightSetting class =>AndroidNotification(light_setting)
* =>AndroidConfig(notification)
* =>PushMessage(android)
*/
namespace push_admin\push_msg\android;
include_once (dirname(__FILE__) . '/../ValidatorUtil.php');
use push_admin\ValidatorUtil;
use Exception;
class LightSetting
{
private $color;
private $light_on_duration;
private $light_off_duration;
private $fields;
public function __construct()
{
$this->color = array();
$this->fields = array();
}
public function color($value)
{
$this->color = $value;
}
public function light_on_duration($value)
{
$this->light_on_duration = $value;
}
public function light_off_duration($value)
{
$this->light_off_duration = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{
try {
$this->check_parameter();
} catch (Exception $e) {
echo $e;
}
$keys = array(
'color',
'light_on_duration',
'light_off_duration'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
private function check_parameter()
{
if (empty($this->color)){
throw new Exception("color must be selected when light_settings is set");
}
if (empty($this->light_on_duration)){
throw new Exception("light_on_duration must be selected when light_settings is set");
}
if (empty($this->light_off_duration)){
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)) {
throw new Exception("light_on_duration format is wrong");
}
if (FALSE == ValidatorUtil::validatePattern($LIGTH_DURATION_PATTERN,$this->light_off_duration) ) {
throw new Exception("light_off_duration format is wrong");
}
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: LightSettingColor =>LightSetting(color)
* =>AndroidNotification(light_setting)
* =>AndroidConfig(notification)
* =>PushMessage(android)
*/
namespace push_admin\push_msg\android;
use Exception;
class LightSettingColor
{
private $alpha;
private $red;
private $green;
private $blue;
private $fields;
public function __construct()
{
$this->alpha = 1;
$this->red = 0;
$this->green = 0;
$this->blue = 0;
$this->fields = array();
}
public function setgenFullcolor($alpha, $red, $green, $blue)
{
$this->alpha = $alpha;
$this->red = $red;
$this->green = $green;
$this->blue = $blue;
}
public function alpha($value)
{
$this->alpha = $value;
}
public function red($value)
{
$this->red = $value;
}
public function green($value)
{
$this->green = $value;
}
public function blue($value)
{
$this->blue = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{
try {
$this->check_parameter();
} catch (Exception $e) {
echo $e;
}
$keys = array(
'alpha',
'red',
'green',
'blue'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
private function check_parameter()
{
if (empty($this->alpha) && (gettype($this->alpha) != "integer")) {
throw new Exception("type of alpha is wrong.");
}
if (empty($this->red) && (gettype($this->red) != "integer")) {
throw new Exception("type of red is wrong.");
}
if (empty($this->green) && (gettype($this->green) != "integer")) {
throw new Exception("type of green is wrong.");
}
if (empty($this->blue) && (gettype($this->blue) != "integer")) {
throw new Exception("type of blue is wrong.");
}
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: Alert => =>PushMessage(apns) for ios channel
*/
namespace push_admin\push_msg\apns;
include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php');
use push_admin\PushLogConfig;
use push_admin\Constants;
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 $fields;
public function title($value) {
$this->title = $value;
}
public function body($value) {
$this->body = $value;
}
public function title_loc_key($value) {
$this->title_loc_key = $value;
}
public function title_loc_args($value) {
$this->title_loc_args = $value;
}
public function action_loc_key($value) {
$this->action_loc_key = $value;
}
public function loc_key($value) {
$this->loc_key = $value;
}
public function loc_args($value) {
$this->loc_args = $value;
}
public function launch_image($value) {
$this->launch_image = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{
$keys = array(
'title',
'body',
'title-loc-key',
'title-loc-args',
'action-loc-key',
'loc-key',
'loc-args',
'launch-image'
);
foreach ($keys as $key) {
$value = str_replace('-', '_', $key);
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][before key:' . $key . '][after key:' . $value . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL);
if (isset($this->$value)) {
$this->fields[$key] = $this->$value;
}
}
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL);
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: ApnsConfig => =>PushMessage(apns) for ios channel
*/
namespace push_admin\push_msg\apns;
include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php');
use push_admin\PushLogConfig;
use push_admin\Constants;
class ApnsConfig
{
private $payload;
private $headers;
private $hms_options;
private $fields;
public function __construct()
{
$this->fields = array();
}
public function payload($value)
{
$this->payload = $value;
}
public function headers($value)
{
$this->headers = $value;
}
public function hms_options($value)
{
$this->hms_options = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{
$keys = array(
'headers',
'hms_options',
'payload'
);
foreach ($keys as $key) {
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][key:' . $key . '][value:' . json_encode($this->$key) . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL);
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL);
}
}
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
namespace push_admin\push_msg\apns;
include_once (dirname(__FILE__) . '/../ValidatorUtil.php');
include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php');
use Exception;
use push_admin\ValidatorUtil;
use push_admin\Constants;
use push_admin\ApnConstant;
use push_admin\PushLogConfig;
class ApnsHeaders
{
private $authorization;
private $apns_id;
private $apns_expiration;
private $apns_priority;
private $apns_topic;
private $apns_collapse_id;
private $fields;
public function authorization($value)
{
$this->authorization = $value;
}
public function apns_id($value)
{
$this->apns_id = $value;
}
public function apns_expiration($value)
{
$this->apns_expiration = $value;
}
public function apns_priority($value)
{
$this->apns_priority = $value;
}
public function apns_topic($value)
{
$this->apns_topic = $value;
}
public function apns_collapse_id($value)
{
$this->apns_collapse_id = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{
try {
$this->check_parameter();
} catch (Exception $e) {
echo $e;
}
$keys = array(
'authorization',
'apns-id',
'apns-expiration',
'apns-priority',
'apns-topic',
'apns-collapse-id'
);
foreach ($keys as $key) {
$value = str_replace('-', '_', $key);
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][before key:' . $key . '][after key:' . $value . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL);
if (isset($this->$value)) {
$this->fields[$key] = $this->$value;
}
}
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL);
}
private function check_parameter()
{
if (! empty($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)) {
throw new Exception("apns-id format error");
}
}
if (! empty($this->apns_priority)) {
if (! in_array($this->apns_priority, 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) {
throw new Exception("Number of apnsCollapseId bytes should be less than 64");
}
}
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
namespace push_admin\push_msg\apns;
use Exception;
class ApnsHmsOptions {
private $target_user_type;
public function getFields()
{
return $this->fields;
}
public function target_user_type($value)
{
$this->target_user_type = $value;
}
public function buildFields()
{
try {
$this->check_parameter();
} catch (Exception $e) {
echo $e;
}
$keys = array(
'target_user_type'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
private function check_parameter()
{
if (!empty($this->target_user_type)
&& !in_array($this->target_user_type,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
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
namespace push_admin\push_msg\apns;
include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php');
use push_admin\PushLogConfig;
use push_admin\Constants;
class Aps {
private $alert;
private $badge;
private $sound;
private $content_available;
private $category;
private $thread_id;
private $fields;
public function alert($value) {
$this->alert = $value;
}
public function badge($value) {
$this->badge = $value;
}
public function sound($value) {
$this->sound = $value;
}
public function content_available($value) {
$this->content_available = $value;
}
public function category($value) {
$this->category = $value;
}
public function thread_id($value) {
$this->thread_id = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{
$keys = array(
'alert',
'badge',
'sound',
'content-available',
'category',
'thread-id'
);
foreach ($keys as $key) {
$value = str_replace('-', '_', $key);
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][before key:' . $key . '][after key:' . $value . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL);
if (isset($this->$value)) {
$this->fields[$key] = $this->$value;
}
}
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL);
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: ApnsConfig => =>PushMessage(apns) for ios channel
*/
namespace push_admin\push_msg\instanceapp;
include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php');
use push_admin\PushLogConfig;
use push_admin\Constants;
class InstanceAppConfig
{
//push_type 0:notification;1,pass-through
private $pushtype;
private $pushbody;
private $fields;
public function __construct()
{
}
public function pushtype($value)
{
$this->pushtype = $value;
}
public function pushbody($value)
{
$this->pushbody = $value;
}
public function getFields()
{
$result = "{";
foreach ($this->fields as $key=>$value) {
$result = $result .$key.":".json_encode($value).",";
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][result:' .$result, Constants::HW_PUSH_LOG_DEBUG_LEVEL);
}
if (strlen($result) > 1){
$result = rtrim($result, ",");
}
$result = $result."}";
return $result;
}
public function buildFields()
{
$keys = array(
'pushtype',
'pushbody'
);
foreach ($keys as $key) {
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][key:' . $key . '][value:' . json_encode($this->$key) . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL);
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL);
}
}
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: ApnsConfig => =>PushMessage(apns) for ios channel
*/
namespace push_admin\push_msg\instanceapp;
include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php');
use push_admin\PushLogConfig;
use push_admin\Constants;
class InstanceAppPushbody
{
// for pass-through
private $messageId;
private $data;
// for notification
private $title;
private $description;
private $page;
private $params;
private $ringtone;
private $fields;
public function __construct()
{
}
public function messageId($value)
{
$this->messageId = $value;
}
public function data($value)
{
$this->data = $value;
}
public function title($value)
{
$this->title = $value;
}
public function description($value)
{
$this->description = $value;
}
public function page($value)
{
$this->page = $value;
}
public function params($value)
{
$this->params = $value;
}
public function ringtone($value)
{
$this->ringtone = $value;
}
public function getFields()
{
$result = "{";
foreach ($this->fields as $key=>$value) {
$result = $result .$key.":".json_encode($value).",";
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][result:' .$result, Constants::HW_PUSH_LOG_DEBUG_LEVEL);
}
if (strlen($result) > 1){
$result = rtrim($result, ",");
}
$result = $result."}";
return $result;
}
public function buildFields()
{
$keys = array(
'messageId',
'data',
'title',
'description',
'page',
'params',
'ringtone'
);
foreach ($keys as $key) {
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][key:' . $key . '][value:' . json_encode($this->$key) . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL);
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL);
}
}
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: ApnsConfig => =>PushMessage(apns) for ios channel
*/
namespace push_admin\push_msg\instanceapp;
include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php');
use push_admin\PushLogConfig;
use push_admin\Constants;
class InstanceAppRingtone
{
private $vibration;
private $breathLight;
private $fields;
public function __construct()
{
$this->fields = array();
}
public function vibration($value)
{
$this->vibration = $value;
}
public function breathLight($value)
{
$this->breathLight = $value;
}
public function getFields()
{
$result = "{";
foreach ($this->fields as $key=>$value) {
$result = $result .$key.":".json_encode($value).",";
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][result:' .$result, Constants::HW_PUSH_LOG_DEBUG_LEVEL);
}
if (strlen($result) > 1){
$result = rtrim($result, ",");
}
$result = $result."}";
return $result;
}
public function buildFields()
{
$keys = array(
'vibration',
'breathLight'
);
foreach ($keys as $key) {
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][key:' . $key . '][value:' . json_encode($this->$key) . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL);
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL);
}
}
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: Notification message push control parameter =>PushMessage(notification) for ios channel
*/
namespace push_admin\push_msg\notification;
/**
* optional for message
*/
use Exception;
class Notification
{
/**
* optional
*/
private $title;
/**
* optional
*/
private $body;
/**
* optional
*/
private $image;
private $fields;
public function __construct($title, $body, $image)
{
$this->title = $title;
$this->body = $body;
$this->image = $image;
$this->fields = array();
}
public function title($value)
{
$this->title = $value;
}
public function body($value)
{
$this->body = $value;
}
public function image($value)
{
$this->image = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{ try {
$this->check_parameter();
} catch (Exception $e) {
echo $e;
}
$keys = array(
'title',
'body',
'image'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
private function check_parameter()
{
if (empty($this->title))
{
throw new Exception("title should be set");
}
if (empty($this->body))
{
throw new Exception("body should be set");
}
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: webpush message push control parameter, which is required for webpush msg=>PushMessage(webpush)
*/
namespace push_admin\push_msg\webpush;
class WebPushConfig
{
private $headers;
private $data;
private $notification;
private $hms_options;
private $fields;
public function __construct()
{
$this->headers = array();
$this->notification = array();
$this->hmsOptions = array();
$this->fields = array();
}
public function headers($value)
{
$this->headers = $value;
}
public function data($value)
{
$this->data = $value;
}
public function notification($value)
{
$this->notification = $value;
}
public function hmsOptions($value)
{
$this->hms_options = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{
$keys = array(
'headers',
'data',
'notification',
'hms_options'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
}
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: WebPush Headers class =>WebPushConfig(headers)
* =>PushMessage(webpush)
*/
namespace push_admin\push_msg\webpush;
class WebPushHeaders
{
private $ttl;
private $topic;
private $urgency;
private $fields;
public function __construct()
{
$this->fields = array();
}
public function ttl($value)
{
$this->ttl = $value;
}
public function topic($value)
{
$this->topic = $value;
}
public function urgency($value)
{
$this->urgency = $value;
}
public function getFields()
{
return $this->fields;
}
public function buildFields()
{
$keys = array(
'ttl',
'topic',
'urgency'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: WebPushHmsOptions class =>WebPushConfig(hms_options)
* =>PushMessage(webpush)
*/
namespace push_admin\push_msg\webpush;
class WebPushHmsOptions
{
private $link;
private $fields;
public function __construct()
{
$this->fields = array();
}
public function link($value) {
$this->link = $value;
}
public function getFields() {
return $this->fields;
}
public function buildFields() {
$keys = array(
'link'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
}
\ No newline at end of file
<?php
/**
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* function: WebPushNotification class =>WebPushConfig(notification)
* =>PushMessage(webpush)
*/
namespace push_admin\push_msg\webpush;
use Exception;
class WebPushNotification
{
private $title;
private $body;
private $icon;
private $image;
private $lang;
private $tag;
private $badge;
private $dir;
private $vibrate;
private $renotify;
private $require_interaction;
private $silent;
private $timestamp;
private $actions;
private $fields;
public function __construct()
{
$this->actions = array();
$this->fields = array();
}
public function title($value) {
$this->title = $value;
}
public function body($value) {
$this->body = $value;
}
public function icon($value) {
$this->icon = $value;
}
public function image($value) {
$this->image = $value;
}
public function lang($value) {
$this->lang = $value;
}
public function tag($value) {
$this->tag = $value;
}
public function badge($value) {
$this->badge = $value;
}
public function dir($value) {
$this->dir = $value;
}
public function vibrate($value) {
$this->vibrate = $value;
}
public function renotify($value) {
$this->renotify = $value;
}
public function require_interaction($value) {
$this->require_interaction = $value;
}
public function silent($value) {
$this->silent = $value;
}
public function timestamp($value) {
$this->timestamp = $value;
}
public function actions($value) {
$this->actions = $value;
}
public function getFields() {
return $this->fields;
}
public function buildFields() {
try{
$this->check_parameter();
}catch (Exception $e) {
echo $e;
}
$keys = array(
'title',
'body',
'icon',
'image',
'lang',
'tag',
'badge',
'dir',
'vibrate',
'renotify',
'require_interaction',
'silent',
'timestamp',
'actions'
);
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->fields[$key] = $this->$key;
}
}
}
private function check_parameter() {
if (($this->renotify) && (gettype($this->renotify) != "boolean")) {
throw new Exception("type of renotify is wrong.");
}
if (($this->require_interaction) && (gettype($this->require_interaction) != "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
This diff is collapsed.
This diff is collapsed.
<?php
namespace JPush;
class Config {
const DISABLE_SOUND = "_disable_Sound";
const DISABLE_BADGE = 0x10000;
const USER_AGENT = 'JPush-API-PHP-Client';
const CONNECT_TIMEOUT = 20;
const READ_TIMEOUT = 120;
const DEFAULT_MAX_RETRY_TIMES = 3;
const DEFAULT_LOG_FILE = "./jpush.log";
const HTTP_GET = 'GET';
const HTTP_POST = 'POST';
const HTTP_DELETE = 'DELETE';
const HTTP_PUT = 'PUT';
}
This diff is collapsed.
<?php
namespace JPush\Exceptions;
class APIConnectionException extends JPushException {
function __toString() {
return "\n" . __CLASS__ . " -- {$this->message} \n";
}
}
This diff is collapsed.
<?php
namespace JPush\Exceptions;
class JPushException extends \Exception {
function __construct($message) {
parent::__construct($message);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
namespace JPush;
const VERSION = '3.6.6';
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment