├── 3rd-party └── .gitignore ├── LICENSE ├── README.md ├── README_ZH.md ├── build └── .gitignore ├── dist └── .gitignore ├── doc └── .gitignore ├── src ├── config.ini ├── example │ ├── push_common │ │ └── test_sample_push_msg_common.php │ ├── test_sample_apns_msg.php │ ├── test_sample_push_condition_msg.php │ ├── test_sample_push_instantce_app_msg.php │ ├── test_sample_push_notification_msg.php │ ├── test_sample_push_passthrouth_msg.php │ ├── test_sample_push_quick_app_msg.php │ ├── test_sample_push_topic_msg.php │ ├── test_sample_push_webpush_msg.php │ └── test_sample_test_push_msg.php └── push_admin │ ├── Application.php │ ├── Constants.php │ ├── PushConfig.php │ ├── PushLogConfig.php │ └── push_msg │ ├── PushMessage.php │ ├── ValidatorUtil.php │ ├── android │ ├── AndroidConfig.php │ ├── AndroidNotification.php │ ├── Badge.php │ ├── ClickAction.php │ ├── LightSetting.php │ └── LightSettingColor.php │ ├── apns │ ├── Alert.php │ ├── ApnsConfig.php │ ├── ApnsHeaders.php │ ├── ApnsHmsOptions.php │ └── Aps.php │ ├── notification │ └── Notification.php │ ├── quickapp │ ├── QuickAppConfig.php │ ├── QuickAppPushbody.php │ └── QuickAppRingtone.php │ └── webpush │ ├── WebPushConfig.php │ ├── WebPushHeaders.php │ ├── WebPushHmsOptions.php │ ├── WebPushNotification.php │ └── WebPushNotificationAction.php └── test └── .gitignore /3rd-party/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | 3 | Version 2.0, January 2004 4 | 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 16 | 17 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 18 | 19 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 20 | 21 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 22 | 23 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 24 | 25 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 26 | 27 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 28 | 29 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 30 | 31 | 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 32 | 33 | 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 34 | 35 | 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 36 | 37 | You must give any other recipients of the Work or Derivative Works a copy of this License; and 38 | You must cause any modified files to carry prominent notices stating that You changed the files; and 39 | You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 40 | If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 41 | 42 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 43 | 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 44 | 45 | 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 46 | 47 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 48 | 49 | 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 50 | 51 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 52 | 53 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HMS Pushkit PHP Severdemo 2 | English | [中文](README_ZH.md) 3 | 4 | ## Table of Contents 5 | * [Introduction](#introduction) 6 | * [Installation](#installation) 7 | * [Configuration](#configuration) 8 | * [Supported Environments](#supported-environments) 9 | * [Sample Code](#sample-code) 10 | * [Technical Support](#technical-support) 11 | * [License](#license) 12 | 13 | ## Introduction 14 | PHP sample code encapsulates APIs of the HUAWEI Push Kit server.It provides many sample 15 | PHP programs about quick access to HUAWEI Push Kit for your reference or usage. 16 | The following table describes packages of PHP sample code. 17 | 18 | | Package | Description 19 | | :--- | :--- 20 | | [examples](src/example) | Sample code files. Each PHP file can run independently. 21 | | [push_admin](src/push_admin) | Package where APIs of the HUAWEI Push Kit server are
encapsulated. 22 | 23 | ## Installation 24 | 25 | Before using PHP sample code, check whether the PHP environment has been installed. 26 | 27 | ## Supported Environments 28 | 29 | The PHP sample code is debugged based on the XAMPP (MySQL + PHP + PERL) 5.6.26 development suite. 30 | 31 | ## Configuration 32 | 33 | The following table describes parameters of the ____construct__ method. 34 | 35 | | Parameter | Description 36 | | :--- | :--- 37 | | __appid__ | App ID, which is obtained from app information. 38 | | __appsecret__ | Secret access key of an app, which is obtained from app information. 39 | | __access_token__ | URL for the Huawei OAuth 2.0 service to obtain a token,
please refer to [Generating an App-Level Access Token](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/oauth2-0000001212610981). 40 | | __hw_token_server__ | URL for accessing HUAWEI Push Kit, please refer to [Sending Messages](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-server-dev-0000001050040110?ha_source=hms1). 41 | 42 | ## Sample Code 43 | 44 | PHP sample code uses the Application structure in the push_admin package as the entry. 45 | Core methods in the Application structure are used to call APIs of the HUAWEI Push Kit server. 46 | The following table lists methods in Application. 47 | 48 | | Method | Description 49 | | :--- | :--- 50 | | __push_send_msg__ | Sends a message to a device. 51 | | __common_send_msg__ | Subscribes to a topic, unsubscribes from a topic,
and queries the list of topics subscribed by a device. 52 | | ____construc__ | Constructor, which obtains key data for sending a message. 53 | 54 | #### 1.Send an Android data message. 55 | Code location: [examples/test_sample_push_passthrouth_msg.php](src/example/test_sample_push_passthrouth_msg.php) 56 | 57 | #### 2.Send an Android notification message. 58 | Code location: [examples/test_sample_push_notification_msg.php](src/example/test_sample_push_notification_msg.php) 59 | 60 | #### 3.Send a message by topic. 61 | Code location: [examples/test_sample_push_topic_msg.php](src/example/test_sample_push_topic_msg.php) 62 | 63 | #### 4.Send a message by conditions. 64 | Code location: [examples/test_sample_push_condition_msg.php](src/example/test_sample_push_condition_msg.php) 65 | 66 | #### 5.Send a message to a Huawei quick app. 67 | Code location: [examples/test_sample_push_instantce_app_msg.php](src/example/test_sample_push_instantce_app_msg.php) 68 | 69 | #### 6.Send a message through the WebPush agent. 70 | Code location: [examples/test_sample_push_webpush_msg.php](src/example/test_sample_push_webpush_msg.php) 71 | 72 | #### 7.Send a message through the APNs agent. 73 | Code location: [examples/test_sample_apns_msg.php](src/example/test_sample_apns_msg.php) 74 | 75 | #### 8.Send a test message. 76 | Code location: [examples/test_sample_test_push_msg.php](src/example/test_sample_test_push_msg.php) 77 | 78 | ## Technical Support 79 | If you want to evaluate more about HMS Core, 80 | [r/HMSCore on Reddit](https://www.reddit.com/r/HuaweiDevelopers/) is for you to keep up with latest news about HMS Core, and to exchange insights with other developers. 81 | 82 | If you have questions about how to use HMS samples, try the following options: 83 | - [Stack Overflow](https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Votes) is the best place for any programming questions. Be sure to tag your question with 84 | `huawei-mobile-services`. 85 | - [Huawei Developer Forum](https://forums.developer.huawei.com/forumPortal/en/home?fid=0101187876626530001) HMS Core Module is great for general questions, or seeking recommendations and opinions. 86 | 87 | If you run into a bug in our samples, please submit an [issue](https://github.com/HMS-Core/hms-push-serverdemo-php/issues) to the Repository. Even better you can submit a [Pull Request](https://github.com/HMS-Core/hms-push-serverdemo-php/pulls) with a fix. 88 | 89 | ## License 90 | Pushkit PHP sample is licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). 91 | -------------------------------------------------------------------------------- /README_ZH.md: -------------------------------------------------------------------------------- 1 | # 华为推送服务服务端PHP示例代码 2 | [English](README.md) | 中文 3 | 4 | ## 目录 5 | * [简介](#简介) 6 | * [安装](#安装) 7 | * [环境要求](#环境要求) 8 | * [配置](#配置) 9 | * [示例代码](#示例代码) 10 | * [技术支持](#技术支持) 11 | * [授权许可](#授权许可) 12 | 13 | ## 简介 14 | PHP示例代码对华为推送服务(HUAWEI Push Kit)服务端接口进行封装,包含丰富的示例程序,方便您参考或直接使用。 15 | 示例代码主要包括以下组成: 16 | 17 | | 包名 | 说明 18 | | :--- | :--- 19 | | [examples](src/example) | 示例代码文件,每个PHP文件都可以独立运行 20 | | [push_admin](src/push_admin) | 推送服务的服务端接口封装包 21 | 22 | ## 安装 23 | 24 | 使用本示例代码前,请确保您的设备上已安装PHP开发环境。 25 | 26 | ## 环境要求 27 | 28 | 本示例代码经过XAMPP (MySQL + PHP + PERL) 5.6.26开发套件调试。 29 | 30 | ## 配置 31 | 32 | __construct方法包括如下参数: 33 | 34 | | 参数 | 说明 35 | | :--- | :--- 36 | | __appid__ | 应用ID,从应用消息中获取 37 | | __appsecret__ | 应用访问密钥,从应用信息中获取 38 | | __access_token__ | 华为OAuth 2.0获取token的地址。具体请参考[基于OAuth 2.0开放鉴权-客户端模式](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/oauth2-0000001212610981)。 39 | | __hw_token_server__ | 推送服务的访问地址。具体请参考[推送服务-下行消息](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/android-server-dev-0000001050040110?ha_source=hms1)。 40 | 41 | ## 示例代码 42 | 43 | 本示例代码以push_admin包中的Application结构体为入口。Application结构体中的核心方法完成了对推送服务服务端接口的调用。 44 | Application包括如下方法: 45 | 46 | | 方法 | 说明 47 | | :--- | :--- 48 | | __push_send_msg__ | 向设备发送消息 49 | | __common_send_msg__ | 订阅主题、退订主题、查询设备订阅的主题列表 50 | | ____construc__ | 构造函数,获取发送消息的关键数据 51 | 52 | #### 1. 发送Android透传消息 53 | 代码位置: [examples/test_sample_push_passthrouth_msg.php](src/example/test_sample_push_passthrouth_msg.php) 54 | 55 | #### 2. 发送Android通知栏消息 56 | 代码位置: [examples/test_sample_push_notification_msg.php](src/example/test_sample_push_notification_msg.php) 57 | 58 | #### 3. 基于主题发送消息 59 | 代码位置: [examples/test_sample_push_topic_msg.php](src/example/test_sample_push_topic_msg.php) 60 | 61 | #### 4. 基于条件发送消息 62 | 代码位置: [examples/test_sample_push_condition_msg.php](src/example/test_sample_push_condition_msg.php) 63 | 64 | #### 5. 向华为快应用发送消息 65 | 代码位置: [examples/test_sample_push_instantce_app_msg.php](src/example/test_sample_push_instantce_app_msg.php) 66 | 67 | #### 6. 基于WebPush代理发送消息 68 | 代码位置: [examples/test_sample_push_webpush_msg.php](src/example/test_sample_push_webpush_msg.php) 69 | 70 | #### 7. 基于APNs代理发送消息 71 | 代码位置: [examples/test_sample_apns_msg.php](src/example/test_sample_apns_msg.php) 72 | 73 | #### 8. 发送测试消息. 74 | 代码位置: [examples/test_sample_test_push_msg.php](src/example/test_sample_test_push_msg.php) 75 | 76 | ## 技术支持 77 | 如果您对HMS Core还处于评估阶段,可在[Reddit社区](https://www.reddit.com/r/HuaweiDevelopers/)获取关于HMS Core的最新讯息,并与其他开发者交流见解。 78 | 79 | 如果您对使用HMS示例代码有疑问,请尝试: 80 | - 开发过程遇到问题上[Stack Overflow](https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Votes),在`huawei-mobile-services`标签下提问,有华为研发专家在线一对一解决您的问题。 81 | - 到[华为开发者论坛](https://developer.huawei.com/consumer/cn/forum/blockdisplay?fid=18) HMS Core板块与其他开发者进行交流。 82 | 83 | 如果您在尝试示例代码中遇到问题,请向仓库提交[issue](https://github.com/HMS-Core/hms-push-serverdemo-php/issues),也欢迎您提交[Pull Request](https://github.com/HMS-Core/hms-push-serverdemo-php/pulls)。 84 | 85 | ## 授权许可 86 | 华为推送服务PHP示例代码经过[Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0)授权许可。 87 | -------------------------------------------------------------------------------- /build/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /dist/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /src/config.ini: -------------------------------------------------------------------------------- 1 | ___ ___ __ __ __________ ____ ___ _________ ___ ___ __________ ___ _____________ 2 | / | \/ \ / \ \______ \ | \/ _____// | \ \______ \/ | \______ \ 3 | / ~ \ \/\/ / | ___/ | /\_____ \/ ~ \ | ___/ ~ \ ___/ 4 | \ Y /\ / | | | | / / \ Y / | | \ Y / | 5 | \___|_ / \__/\ / |____| |______/ /_______ /\___|_ / |____| \___|_ /|____| 6 | \/ \/ \/ \/ \/ 7 | 8 | ******************************************************************************************** 9 | ********** instruction: 1)two part:private personal data and public url ********** 10 | ********** 2)don't change split character such as =/" ********** 11 | ********** 3)don't new line for HW_PUSH_TOKEN_ARR ********** 12 | ********** 4)Space will be removed, cannot be a variable ********** 13 | ******************************************************************************************** 14 | 15 | ******************************************************************************************** 16 | ********** here is private variable personal data,you must change it! ********** 17 | ******************************************************************************************** 18 | HW_APPID="xxxxx" 19 | HW_APPSECRET="xxxxx" 20 | 21 | ### Business Push Token,For common push msg #### 22 | HW_PUSH_TOKEN_ARR="xxxxx" 23 | 24 | ### Business Push Token,For IOS apn #### 25 | APN_PUSH_TOKEN_ARR="xxxxx" 26 | 27 | ### Business Push Token,For webpush #### 28 | WEBPUSH_PUSH_TOKEN_ARR="xxxxx" 29 | 30 | ### FAST APP INFO : different from ordinal app#### 31 | HW_FAST_APPID="xxxxx" 32 | HW_FAST_APPSECRET="xxxxx" 33 | HW_FAST_PUSH_TOKEN="xxxxx" 34 | 35 | 36 | ******************************************************************************************** 37 | ********** below is public url entry,please don't modify if not necessary ********** 38 | ******************************************************************************************** 39 | ### Token Server for push msg and top subscribe/unsubscribe #### 40 | HW_TOKEN_SERVER="https://oauth-login.cloud.huawei.com/oauth2/v2/token" 41 | 42 | 43 | ### Push Server address #### 44 | HW_PUSH_SERVER="https://push-api.cloud.huawei.com/v1/{appid}/messages:send" 45 | 46 | 47 | ### Topic Server address #### 48 | HW_TOPIC_SUBSCRIBE_SERVER="https://push-api.cloud.huawei.com/v1/{appid}/topic:subscribe" 49 | HW_TOPIC_UNSUBSCRIBE_SERVER="https://push-api.cloud.huawei.com/v1/{appid}/topic:unsubscribe" 50 | HW_TOPIC_QUERY_SUBSCRIBER_SERVER="https://push-api.cloud.huawei.com/v1/{appid}/topic:list" 51 | 52 | ### LogLevel:ERROR(1),WARN(2),INFO(3),DEBUG(4) #### 53 | HW_DEFAULT_LOG_LEVEL=3 54 | -------------------------------------------------------------------------------- /src/example/push_common/test_sample_push_msg_common.php: -------------------------------------------------------------------------------- 1 | LogMessage(str_pad("HW_APPID", $this->str_len, '=') . ">" . $pushConfig->HW_APPID); 114 | PushLogConfig::getSingleInstance()->LogMessage(str_pad("HW_APPSECRET", $this->str_len, '=') . ">" . $pushConfig->HW_APPSECRET); 115 | PushLogConfig::getSingleInstance()->LogMessage(str_pad("HW_TOKEN_SERVER", $this->str_len, '=') . ">" . $pushConfig->HW_TOKEN_SERVER); 116 | PushLogConfig::getSingleInstance()->LogMessage(str_pad("HW_PUSH_TOKEN_ARR", $this->str_len, '=') . ">" . $pushConfig->HW_PUSH_TOKEN_ARR); 117 | PushLogConfig::getSingleInstance()->LogMessage(str_pad("WEBPUSH_PUSH_TOKEN_ARR", $this->str_len, '=') . ">" . $pushConfig->WEBPUSH_PUSH_TOKEN_ARR); 118 | PushLogConfig::getSingleInstance()->LogMessage(str_pad("APN_PUSH_TOKEN_ARR", $this->str_len, '=') . ">" . $pushConfig->APN_PUSH_TOKEN_ARR); 119 | PushLogConfig::getSingleInstance()->LogMessage(str_pad("HW_TOPIC_SUBSCRIBE_SERVER", $this->str_len, '=') . ">" . $pushConfig->HW_TOPIC_SUBSCRIBE_SERVER); 120 | PushLogConfig::getSingleInstance()->LogMessage(str_pad("HW_TOPIC_UNSUBSCRIBE_SERVER", $this->str_len, '=') . ">" . $pushConfig->HW_TOPIC_UNSUBSCRIBE_SERVER); 121 | PushLogConfig::getSingleInstance()->LogMessage(str_pad("HW_TOPIC_QUERY_SUBSCRIBER_SERVER", $this->str_len, '=') . ">" . $pushConfig->HW_TOPIC_QUERY_SUBSCRIBER_SERVER); 122 | PushLogConfig::getSingleInstance()->LogMessage(str_pad("HW_FAST_APPID", $this->str_len, '=') . ">" . $pushConfig->HW_FAST_APPID); 123 | PushLogConfig::getSingleInstance()->LogMessage(str_pad("HW_FAST_APPSECRET", $this->str_len, '=') . ">" . $pushConfig->HW_FAST_APPSECRET); 124 | PushLogConfig::getSingleInstance()->LogMessage(str_pad("HW_FAST_PUSH_TOKEN", $this->str_len, '=') . ">" . $pushConfig->HW_FAST_PUSH_TOKEN); 125 | 126 | $this->appsecret = $pushConfig->HW_APPSECRET; 127 | $this->appid = $pushConfig->HW_APPID; 128 | $this->hw_token_server = $pushConfig->HW_TOKEN_SERVER; 129 | $this->hw_push_server = $pushConfig->HW_PUSH_SERVER; 130 | $this->hw_push_token_key = $pushConfig->HW_PUSH_TOKEN_ARR; 131 | $this->apn_push_token_key = $pushConfig->APN_PUSH_TOKEN_ARR; 132 | $this->webpush_push_token_key = $pushConfig->WEBPUSH_PUSH_TOKEN_ARR; 133 | 134 | $this->fast_appsecret = $pushConfig->HW_FAST_APPSECRET; 135 | $this->fast_appid = $pushConfig->HW_FAST_APPID; 136 | $this->fast_push_token = $pushConfig->HW_FAST_PUSH_TOKEN; 137 | 138 | } 139 | 140 | function sendPushMsgMessageByMsgType($msg_type, $topic = "") 141 | { 142 | $application_server = $this->hw_push_server; 143 | $this->printLogMethodOperate("push msg start" . $this->log_suffix_show_start, __FUNCTION__ . ':' . __LINE__); 144 | 145 | $this->push_msg_type = $msg_type; 146 | $message = $this->getMessageByMsgType($msg_type); 147 | 148 | $this->printLogMethodOperate("msg body:" . json_encode($message->getFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 149 | 150 | $application = $this->createApplication($application_server); 151 | $this->printLogMethodOperate("application server:" . json_encode($application->getApplicationFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 152 | 153 | $application->push_send_msg($message->getFields()); 154 | $this->printLogMethodOperate("push msg end" . $this->log_suffix_show_end, __FUNCTION__ . ':' . __LINE__); 155 | } 156 | 157 | function sendPushMsgRealMessage($message,$push_msg_type="") 158 | { 159 | $this->printLogMethodOperate("sendPushMsgRealMessage start push_msg_type:" .$push_msg_type, __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 160 | if (!empty($push_msg_type)) { 161 | $this->push_msg_type = $push_msg_type; 162 | } 163 | $this->printLogMethodOperate("sendPushMsgRealMessage start push_msg_type:" .$this->push_msg_type, __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 164 | $application_server = $this->hw_push_server; 165 | $application = $this->createApplication($application_server); 166 | $this->printLogMethodOperate("application server:" . json_encode($application->getApplicationFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 167 | 168 | $application->push_send_msg($message); 169 | $this->printLogMethodOperate("push msg end" . $this->log_suffix_show_end, __FUNCTION__ . ':' . __LINE__); 170 | } 171 | 172 | function sendPushTopicMsgMessage($topic = "") 173 | { 174 | if (empty($topic)) { 175 | $topic = $this->default_topic; 176 | } 177 | $testTopicCommonSample = new TestTopicCommonSample($topic); 178 | 179 | $this->printLogMethodOperate("start subscribe topic:" . $topic, __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_INFO_LEVEL); 180 | // subscribe msg 181 | $testTopicCommonSample->sendTopicMessage(Constants::TOPIC_SUBSCRIBE_MSG_TYPE); 182 | // query subscribe msg 183 | $testTopicCommonSample->sendTopicMessage(Constants::TOPIC_SUBSCRIBE_QUERY_MSG_TYPE); 184 | } 185 | 186 | /** 187 | * $result==>{"msg":"success","code":"80000000","requestId":"157561883923402813000201", 188 | * "topics":[{"name":"defaultTopic","addDate":"2019-12-06"}, 189 | * {"name":"push-test","addDate":"2019-12-06"}, 190 | * {"name":"targetTopic","addDate":"2019-12-06"}, 191 | * {"name":"weather","addDate":"2019-12-06"}]} 192 | */ 193 | private function isTopicInTopicList($result, $topic) 194 | { 195 | $this->printLogMethodOperate("isTopicInTopicList topic[" . $topic . "],result:" . json_encode($result) . "", __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_INFO_LEVEL); 196 | if (empty($result)) { 197 | return FALSE; 198 | } 199 | 200 | $arrResult = json_decode(json_encode($result), true); 201 | $this->printLogMethodOperate("isTopicInTopicList arrResult:" . json_encode($arrResult) . "][code:" . $arrResult["code"], __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 202 | 203 | if (empty($arrResult["code"])) { 204 | return FALSE; 205 | } 206 | $this->printLogMethodOperate("isTopicInTopicList code:" . $arrResult["code"], __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 207 | 208 | if (! in_array($arrResult["code"], array( 209 | "80000000", 210 | 80000000 211 | ))) { 212 | return FALSE; 213 | } 214 | if (empty($arrResult["topics"])) { 215 | return FALSE; 216 | } 217 | 218 | $topicArr = $arrResult["topics"]; 219 | $this->printLogMethodOperate("isTopicInTopicList topicArr:" . json_encode($topicArr), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 220 | if (empty($topicArr)) { 221 | return FALSE; 222 | } 223 | 224 | foreach ($topicArr as $topicObject) { 225 | if ($topicObject["name"] == $topic) { 226 | return TRUE; 227 | } 228 | } 229 | $this->printLogMethodOperate("isTopicInTopicList False,topic is not subscribe", __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 230 | return FALSE; 231 | } 232 | 233 | private function getDefaultAndroidNotificationContent($titel) 234 | { 235 | $prefixTitleData = ''; 236 | switch ($this->push_msg_type) { 237 | case Constants::PUSHMSG_NOTIFICATION_MSG_TYPE: 238 | { 239 | $prefixTitleData = ' notification '; 240 | break; 241 | } 242 | case Constants::PUSHMSG_PASS_THROUGHT_MSG_TYPE: 243 | { 244 | $prefixTitleData = ' passthrough '; 245 | break; 246 | } 247 | 248 | case Constants::PUSHMSG_FASTAPP_MSG_TYPE: 249 | { 250 | $prefixTitleData = ' fastapp '; 251 | break; 252 | } 253 | case Constants::PUSHMSG_TOPIC_MSG_TYPE: 254 | { 255 | $prefixTitleData = ' topic '; 256 | break; 257 | } 258 | case Constants::PUSHMSG_CONDITION_MSG_TYPE: 259 | { 260 | $prefixTitleData = ' condition '; 261 | break; 262 | } 263 | 264 | case Constants::APN_MSG_TYPE: 265 | { 266 | $prefixTitleData = ' apn '; 267 | break; 268 | } 269 | case Constants::WEB_PUSH_MSG_TYPE: 270 | { 271 | $prefixTitleData = ' webpush '; 272 | break; 273 | } 274 | } 275 | 276 | return $prefixTitleData . $titel . $prefixTitleData; 277 | } 278 | 279 | private function createAndroidNotification() 280 | { 281 | // generate click_action msg body for android notification-3-click_action 282 | $click_action = new ClickAction(); 283 | $click_action->type(2); 284 | $click_action->type(1); 285 | 286 | $click_action->intent("#Intent;compo=com.rvr/.Activity;S.W=U;end"); 287 | $click_action->action("test add"); 288 | $click_action->url("https://www.baidu.com"); 289 | $click_action->rich_resource("test rich resource"); 290 | $click_action->buildFields(); 291 | 292 | // generate Badge for android notification-3-badge 293 | $badge = new Badge(); 294 | $badge->add_num(99); 295 | $badge->setclass("Classic"); 296 | $badge->set_num(99); 297 | $badge->buildFields(); 298 | 299 | // generate Light Settings for android notification-3-badge 300 | $lightSetting = new LightSetting(); 301 | $lightSetting->light_on_duration("3.5"); 302 | $lightSetting->light_off_duration("5S"); 303 | // set light setting color 304 | $LightSettingColor = new LightSettingColor(); 305 | $LightSettingColor->setgenFullcolor(0, 0, 1, 1); 306 | $LightSettingColor->buildFields(); 307 | $lightSetting->color($LightSettingColor->getFields()); 308 | $lightSetting->buildFields(); 309 | 310 | // 构建android notification消息体-2 for android config 311 | $android_notification = new AndroidNotification(); 312 | $android_notification->title($this->getDefaultAndroidNotificationContent("default hw title ")); 313 | $android_notification->body($this->getDefaultAndroidNotificationContent("default hw body")); 314 | $android_notification->icon("https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png"); 315 | $android_notification->color("#AACCDD"); 316 | $android_notification->sound("https://att.chinauui.com/day_120606/20120606_7fcf2235b44f1eab0b4dadtAkAGMTBHK.mp3"); 317 | $android_notification->tag("tagBoom"); 318 | $android_notification->body_loc_key("M.String.body"); 319 | $android_notification->body_loc_args(array( 320 | "Boy", 321 | "Dog" 322 | )); 323 | $android_notification->title_loc_key("M.String.title"); 324 | $android_notification->title_loc_args(array( 325 | "Girl", 326 | "Cat" 327 | )); 328 | $android_notification->channel_id("RingRing"); 329 | $android_notification->notify_summary("Some Summary"); 330 | $android_notification->image("https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"); 331 | $android_notification->style(0); 332 | $android_notification->big_title("Big Boom Title"); 333 | $android_notification->big_body("Big Boom Body"); 334 | $android_notification->auto_clear(86400000); 335 | $android_notification->notify_id(486); 336 | $android_notification->group("Espace"); 337 | $android_notification->importance(NotificationPriority::NOTIFICATION_PRIORITY_NORMAL); 338 | $android_notification->ticker("i am a ticker"); 339 | $android_notification->auto_cancel(false); 340 | $android_notification->when("2019-11-05"); 341 | $android_notification->use_default_vibrate(true); 342 | $android_notification->use_default_light(false); 343 | $android_notification->visibility("PUBLIC"); 344 | $android_notification->foreground_show(true); 345 | $android_notification->vibrate_config(array( 346 | "1.5", 347 | "2.000000001", 348 | "3" 349 | )); 350 | $android_notification->click_action($click_action->getFields()); 351 | $android_notification->badge($badge->getFields()); 352 | $android_notification->light_settings($lightSetting->getFields()); 353 | 354 | $android_notification->buildFields(); 355 | 356 | return $android_notification; 357 | } 358 | 359 | private function createAndroidConfig() 360 | { 361 | $android_notification = $this->createAndroidNotification(); 362 | 363 | $android_config = new AndroidConfig(); 364 | $android_config->collapse_key(- 1); 365 | $android_config->urgency(AndroidConfigDeliveryPriority::PRIORITY_HIGH); 366 | $android_config->ttl("1448s"); 367 | $android_config->bi_tag("Trump"); 368 | if ($this->push_msg_type == Constants::PUSHMSG_FASTAPP_MSG_TYPE) { 369 | $android_config->fast_app_target(1); 370 | } 371 | else{ 372 | $android_config->notification($android_notification->getFields()); 373 | } 374 | $android_config->buildFields(); 375 | return $android_config; 376 | } 377 | 378 | private function createNotification() 379 | { 380 | $notification = new Notification("Big News", "This is a Big News!", "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2_0.png"); 381 | $notification->buildFields(); 382 | return $notification; 383 | } 384 | 385 | private function createApnsConfig() 386 | { 387 | // ApnsHeaders 388 | $apnsHeaders = new ApnsHeaders(); 389 | $apnsHeaders->apns_topic("hmspush"); 390 | $apnsHeaders->apns_priority(ApnConstant::ANP_PRIORITY_SEND_IMMEDIATELY); 391 | $apnsHeaders->buildFields(); 392 | 393 | // ApnHmsOptions 394 | $apnsHmsOptions = new ApnsHmsOptions(); 395 | $apnsHmsOptions->target_user_type(ApnConstant::APN_TARGET_USER_TEST_USER); 396 | $apnsHmsOptions->buildFields(); 397 | 398 | // Aps 399 | // Alert 400 | $alert = new Alert(); 401 | $alert->title("hw default ios message title"); 402 | $alert->body("hw default ios message body"); 403 | $alert->action_loc_key("PLAY"); 404 | $alert->buildFields(); 405 | 406 | $aps = new Aps(); 407 | $aps->alert($alert->getFields()); 408 | $aps->badge(5); 409 | $aps->buildFields(); 410 | 411 | $apnsConfig = new ApnsConfig(); 412 | $apnsConfig->headers($apnsHeaders->getFields()); 413 | $apnsConfig->hms_options($apnsHmsOptions->getFields()); 414 | 415 | $apn_payload["aps"] = $aps->getFields(); 416 | $apn_payload["acme1"] = "bar"; 417 | $apn_payload["acme2"] = array( 418 | "bang", 419 | "whiz" 420 | ); 421 | $apnsConfig->payload($apn_payload); 422 | 423 | $apnsConfig->buildFields(); 424 | 425 | return $apnsConfig; 426 | } 427 | 428 | private function createWebPush() 429 | { 430 | $webPushConfig = new WebPushConfig(); 431 | $webPushConfig->data("test webpush data"); 432 | 433 | $webPushHeaders = new WebPushHeaders(); 434 | $webPushHeaders->topic("12313ceshi"); 435 | $webPushHeaders->ttl("990"); 436 | $webPushHeaders->urgency(Constants::WEBPUSH_URGENCY_VERY_LOW); 437 | $webPushHeaders->buildFields(); 438 | $webPushConfig->headers($webPushHeaders->getFields()); 439 | 440 | $webPushHmsOptions = new WebPushHmsOptions(); 441 | $webPushHmsOptions->link("https://www.huawei.com/"); 442 | $webPushHmsOptions->buildFields(); 443 | $webPushConfig->hmsOptions($webPushHmsOptions->getFields()); 444 | 445 | $webPUshNotionfication = new WebPushNotification(); 446 | $webPUshNotionfication->title("notication string"); 447 | $webPUshNotionfication->body("web push body"); 448 | $webPUshNotionfication->icon("https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"); 449 | $webPUshNotionfication->image("https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"); 450 | $webPUshNotionfication->lang("string"); 451 | $webPUshNotionfication->tag("string"); 452 | $webPUshNotionfication->badge("string"); 453 | $webPUshNotionfication->dir("auto"); 454 | $webPUshNotionfication->vibrate(array( 455 | 1, 456 | 2, 457 | 3 458 | )); 459 | $webPUshNotionfication->renotify(false); 460 | $webPUshNotionfication->require_interaction(false); 461 | $webPUshNotionfication->silent(false); 462 | $webPUshNotionfication->timestamp(1545201266); 463 | $webPushNotificationAction = new WebPushNotificationAction(); 464 | $webPushNotificationAction->title("string"); 465 | $webPushNotificationAction->action("123"); 466 | $webPushNotificationAction->icon("https://developer-portalres-drcn.dbankcdn.com/system/modules/org.opencms.portal.template.core/resources/images/icon_Promotion.png"); 467 | $webPushNotificationAction->buildFields(); 468 | $webPUshNotionfication->actions(array( 469 | $webPushNotificationAction->getFields() 470 | )); 471 | $webPUshNotionfication->buildFields(); 472 | $webPushConfig->notification($webPUshNotionfication->getFields()); 473 | $webPushConfig->buildFields(); 474 | 475 | return $webPushConfig; 476 | } 477 | 478 | private function printLogMethodOperate($dataFlow, $functionName = "", $logLevel = "") 479 | { 480 | $logModule = Constants::HW_PUSH_LOG_PUSH_MSG_MODULE; 481 | 482 | if (empty($logLevel)) { 483 | $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL; 484 | } 485 | 486 | if (empty($functionName)) { 487 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . $dataFlow, $logLevel, $logModule); 488 | } else { 489 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[' . $functionName . ']' . $dataFlow, $logLevel, $logModule); 490 | } 491 | } 492 | 493 | private function createApplication($application_server) 494 | { 495 | $this->printLogMethodOperate("createApplication push_msg_type:".$this->push_msg_type, __FUNCTION__ . ':' . __LINE__,Constants::HW_PUSH_LOG_DEBUG_LEVEL); 496 | if ($this->push_msg_type == Constants::PUSHMSG_FASTAPP_MSG_TYPE){ 497 | $this->printLogMethodOperate("createApplication PUSHMSG_FASTAPP_MSG_TYPE", __FUNCTION__ . ':' . __LINE__,Constants::HW_PUSH_LOG_DEBUG_LEVEL); 498 | $application = new Application($this->fast_appid, $this->fast_appsecret, $this->hw_token_server, $application_server); 499 | return $application; 500 | } 501 | $application = new Application($this->appid, $this->appsecret, $this->hw_token_server, $application_server); 502 | return $application; 503 | } 504 | 505 | private function getMessageByMsgType($msg_type) 506 | { 507 | switch ($msg_type) { 508 | case Constants::PUSHMSG_NOTIFICATION_MSG_TYPE: 509 | { 510 | return $this->createNotificationMsg(); 511 | } 512 | case Constants::PUSHMSG_PASS_THROUGHT_MSG_TYPE: 513 | { 514 | return $this->createPassThroughMsg(); 515 | } 516 | 517 | case Constants::PUSHMSG_FASTAPP_MSG_TYPE: 518 | { 519 | return $this->createFastAppMsg(); 520 | } 521 | case Constants::PUSHMSG_TOPIC_MSG_TYPE: 522 | { 523 | return $this->createTopicMsg(); 524 | } 525 | case Constants::PUSHMSG_CONDITION_MSG_TYPE: 526 | { 527 | return $this->createConditionMsg(); 528 | } 529 | 530 | case Constants::APN_MSG_TYPE: 531 | { 532 | return $this->createApnsMsg(); 533 | } 534 | case Constants::WEB_PUSH_MSG_TYPE: 535 | { 536 | return $this->createWebPushMsg(); 537 | } 538 | } 539 | } 540 | 541 | private function createFastAppConfigNotificationData(){ 542 | $instanceAppConfig = new InstanceAppConfig(); 543 | $instanceAppConfig->pushtype(0); 544 | 545 | $instanceAppPushbody = new InstanceAppPushbody(); 546 | $instanceAppPushbody->title("test fast app"); 547 | $instanceAppPushbody->description("test fast app description"); 548 | $instanceAppPushbody->page("/"); 549 | $instanceAppPushbody->params(array( 550 | "key1"=>"test1", 551 | "key2"=>"test2" 552 | )); 553 | 554 | $instanceAppRingtone = new InstanceAppRingtone(); 555 | $instanceAppRingtone->breathLight(true); 556 | $instanceAppRingtone->vibration(true); 557 | $instanceAppRingtone->buildFields(); 558 | 559 | $instanceAppPushbody->ringtone($instanceAppRingtone->getFields()); 560 | $instanceAppPushbody->buildFields(); 561 | 562 | $instanceAppConfig->pushbody($instanceAppPushbody->getFields()); 563 | $instanceAppConfig->buildFields(); 564 | 565 | return $instanceAppConfig; 566 | 567 | } 568 | 569 | private function createFastAppConfigPassThroughData(){ 570 | $instanceAppConfig = new InstanceAppConfig(); 571 | $instanceAppConfig->pushtype(1); 572 | 573 | $instanceAppPushbody = new InstanceAppPushbody(); 574 | $instanceAppPushbody->messageId("111110001"); 575 | $instanceAppPushbody->data("hw default passthroug test"); 576 | $instanceAppPushbody->buildFields(); 577 | 578 | $instanceAppConfig->pushbody($instanceAppPushbody->getFields()); 579 | $instanceAppConfig->buildFields(); 580 | 581 | return $instanceAppConfig; 582 | 583 | } 584 | 585 | private function createFastAppMsg() 586 | { 587 | $this->printLogMethodOperate("push msg notification start", __FUNCTION__ . ':' . __LINE__); 588 | $message = new PushMessage(); 589 | 590 | $message->data($this->createFastAppConfigNotificationData()->getFields()); 591 | 592 | $message->android($this->createAndroidConfig() 593 | ->getFields()); 594 | 595 | $message->token(array( 596 | $this->fast_push_token 597 | )); 598 | 599 | $message->buildFields(); 600 | $this->printLogMethodOperate("push msg notification end", __FUNCTION__ . ':' . __LINE__); 601 | return $message; 602 | } 603 | 604 | private function createNotificationMsg() 605 | { 606 | $this->printLogMethodOperate("push msg notification start", __FUNCTION__ . ':' . __LINE__); 607 | $message = new PushMessage(); 608 | 609 | $message->android($this->createAndroidConfig() 610 | ->getFields()); 611 | $message->notification($this->createNotification() 612 | ->getFields()); 613 | 614 | $message->token(array( 615 | $this->hw_push_token_key 616 | )); 617 | 618 | $message->buildFields(); 619 | $this->printLogMethodOperate("push msg notification end", __FUNCTION__ . ':' . __LINE__); 620 | return $message; 621 | } 622 | 623 | private function createTopicMsg() 624 | { 625 | $this->printLogMethodOperate("push msg createTopicMsg start", __FUNCTION__ . ':' . __LINE__); 626 | $message = new PushMessage(); 627 | 628 | $message->android($this->createAndroidConfig() 629 | ->getFields()); 630 | // $message->notification($this->createNotification()->buildFields()); 631 | 632 | $message->topic($this->default_topic); 633 | 634 | $message->buildFields(); 635 | $this->printLogMethodOperate("push msg createTopicMsg end", __FUNCTION__ . ':' . __LINE__); 636 | return $message; 637 | } 638 | 639 | private function createConditionMsg() 640 | { 641 | $this->printLogMethodOperate("push msg createTopicMsg start", __FUNCTION__ . ':' . __LINE__); 642 | $message = new PushMessage(); 643 | 644 | $message->android($this->createAndroidConfig() 645 | ->getFields()); 646 | // $message->notification($this->createNotification()->buildFields()); 647 | $message->condition("'defaultTopic' in topics"); 648 | // $message->condition("'weather' in topics || ('TopicB' in topics && 'TopicC' in topics)"); 649 | 650 | $message->buildFields(); 651 | $this->printLogMethodOperate("push msg createTopicMsg end", __FUNCTION__ . ':' . __LINE__); 652 | return $message; 653 | } 654 | 655 | private function createPassThroughMsg() 656 | { 657 | $this->printLogMethodOperate("push msg passthrough start", __FUNCTION__ . ':' . __LINE__); 658 | $message = new PushMessage(); 659 | 660 | $message->data("1111"); 661 | $message->token(array( 662 | $this->hw_push_token_key 663 | )); 664 | 665 | $message->buildFields(); 666 | $this->printLogMethodOperate("push msg passthrough end", __FUNCTION__ . ':' . __LINE__); 667 | return $message; 668 | } 669 | 670 | private function createApnsMsg() 671 | { 672 | $this->printLogMethodOperate("push msg apns start", __FUNCTION__ . ':' . __LINE__); 673 | $message = new PushMessage(); 674 | $apnsConfig = $this->createApnsConfig(); 675 | $message->apns($apnsConfig->getFields()); 676 | 677 | $message->token(array( 678 | $this->apn_push_token_key 679 | )); 680 | $message->buildFields(); 681 | 682 | $this->printLogMethodOperate("push msg apns end", __FUNCTION__ . ':' . __LINE__); 683 | return $message; 684 | } 685 | 686 | private function createWebPushMsg() 687 | { 688 | $this->printLogMethodOperate("push msg webpush start", __FUNCTION__ . ':' . __LINE__); 689 | $message = new PushMessage(); 690 | 691 | $message->webpush($this->createWebPush() 692 | ->getFields()); 693 | $message->token(array( 694 | $this->webpush_push_token_key 695 | )); 696 | 697 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[web-token:' . json_encode($message->get_token()) . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); 698 | 699 | $message->buildFields(); 700 | 701 | $this->printLogMethodOperate("push msg webpush end", __FUNCTION__ . ':' . __LINE__); 702 | return $message; 703 | } 704 | } 705 | 706 | class TestTopicCommonSample 707 | { 708 | 709 | private $topic = "defaultTopic"; 710 | 711 | private $topic_msg_create_type = 1; 712 | 713 | private $appsecret; 714 | 715 | private $appid; 716 | 717 | private $hw_token_server; 718 | 719 | private $hw_topic_subscriber_server; 720 | 721 | private $hw_topic_unsubscriber_server; 722 | 723 | private $hw_topic_query_subscriber_server; 724 | 725 | private $tokenServerKey; 726 | 727 | private $log_suffix_show = "............................."; 728 | 729 | public function __construct($topic_value = "", $default_msg_create_type = "") 730 | { 731 | if (! empty($topic_value)) { 732 | $this->topic = $topic_value; 733 | } 734 | if (! empty($default_msg_create_type)) { 735 | $this->topic_msg_create_type = $default_msg_create_type; 736 | } 737 | 738 | $pushConfig = PushConfig::getSingleInstance(); 739 | 740 | $this->appsecret = $pushConfig->HW_APPSECRET; 741 | $this->appid = $pushConfig->HW_APPID; 742 | $this->hw_token_server = $pushConfig->HW_TOKEN_SERVER; 743 | $this->tokenServerKey = $pushConfig->HW_PUSH_TOKEN_ARR; 744 | 745 | $this->hw_topic_subscriber_server = $pushConfig->HW_TOPIC_SUBSCRIBE_SERVER; 746 | $this->hw_topic_unsubscriber_server = $pushConfig->HW_TOPIC_UNSUBSCRIBE_SERVER; 747 | $this->hw_topic_query_subscriber_server = $pushConfig->HW_TOPIC_QUERY_SUBSCRIBER_SERVER; 748 | } 749 | 750 | private function createTopicData() 751 | { 752 | $topicMsg = new TopicMsg(); 753 | $topicMsg->topic($this->topic); 754 | $topicMsg->tokenArray(array( 755 | $this->tokenServerKey 756 | )); 757 | $topicMsg->buildFields(); 758 | 759 | return $topicMsg; 760 | } 761 | 762 | private function createApplication($application_server) 763 | { 764 | $application = new Application($this->appid, $this->appsecret, $this->hw_token_server, $application_server); 765 | return $application; 766 | } 767 | 768 | private function printLogMethodOperate($msg_type, $dataFlow, $functionName = "", $logLevel = "") 769 | { 770 | $dataFlow = 'subscribe topic ' . $dataFlow; 771 | $logModule = Constants::HW_PUSH_LOG_TOPIC_SUBSCRIBE_MODULE; 772 | switch ($msg_type) { 773 | case Constants::TOPIC_UNSUBSCRIBE_MSG_TYPE: 774 | { 775 | $dataFlow = 'unsubscribe topic' . $dataFlow; 776 | $logModule = Constants::HW_PUSH_LOG_TOPIC_UNSUBSCRIBE_MODULE; 777 | } 778 | break; 779 | } 780 | if (empty($logLevel)) { 781 | $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL; 782 | } 783 | 784 | if (empty($functionName)) { 785 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule); 786 | } else { 787 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[' . $functionName . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule); 788 | } 789 | } 790 | 791 | private function printLogMsgOperate($msg_type, $dataFlow, $functionName = "", $logLevel = "") 792 | { 793 | $logModule = Constants::HW_PUSH_LOG_TOPIC_SUBSCRIBE_MODULE; 794 | switch ($msg_type) { 795 | case Constants::TOPIC_UNSUBSCRIBE_MSG_TYPE: 796 | { 797 | $logModule = Constants::HW_PUSH_LOG_TOPIC_UNSUBSCRIBE_MODULE; 798 | } 799 | break; 800 | } 801 | if (empty($logLevel)) { 802 | $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL; 803 | } 804 | 805 | if (empty($functionName)) { 806 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule); 807 | } else { 808 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[' . $functionName . ']' . $dataFlow . $this->log_suffix_show, $logLevel, $logModule); 809 | } 810 | } 811 | 812 | /** 813 | * topic subscribe/unsubscribe 814 | */ 815 | function sendTopicMessage($msg_type) 816 | { 817 | $this->printLogMethodOperate($msg_type, "start", __FUNCTION__ . ':' . __LINE__); 818 | $topicMsg = $this->createTopicData(); 819 | if ($this->topic_msg_create_type == 1) { 820 | $this->printLogMsgOperate($msg_type, "topicMsg:" . json_encode($topicMsg->getFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 821 | } 822 | 823 | $application_server = $this->hw_topic_subscriber_server; 824 | if ($msg_type == Constants::TOPIC_UNSUBSCRIBE_MSG_TYPE) { 825 | $application_server = $this->hw_topic_unsubscriber_server; 826 | } else if ($msg_type == Constants::TOPIC_SUBSCRIBE_QUERY_MSG_TYPE) { 827 | $application_server = $this->hw_topic_query_subscriber_server; 828 | $topicMsg = array( 829 | 'token' => $this->tokenServerKey 830 | ); 831 | } 832 | $application = $this->createApplication($application_server); 833 | $this->printLogMsgOperate($msg_type, "application server:" . json_encode($application->getApplicationFields()), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 834 | 835 | $topicResult = ""; 836 | if ($msg_type == Constants::TOPIC_SUBSCRIBE_QUERY_MSG_TYPE) { 837 | $topicResult = $application->common_send_msg($topicMsg); 838 | } else { 839 | $topicResult = $application->common_send_msg($topicMsg->getFields()); 840 | } 841 | 842 | $this->printLogMethodOperate($msg_type, "end", __FUNCTION__ . ':' . __LINE__); 843 | return $topicResult; 844 | } 845 | } 846 | 847 | class TopicMsg 848 | { 849 | 850 | // madatory 851 | private $topic; 852 | 853 | // madatory 854 | private $tokenArray; 855 | 856 | private $fields; 857 | 858 | public function __construct() 859 | { 860 | $this->fields = array(); 861 | } 862 | 863 | public function topic($value) 864 | { 865 | $this->topic = $value; 866 | } 867 | 868 | public function tokenArray($value) 869 | { 870 | $this->tokenArray = $value; 871 | } 872 | 873 | public function getFields() 874 | { 875 | return $this->fields; 876 | } 877 | 878 | public function buildFields() 879 | { 880 | $keys = array( 881 | 'topic', 882 | 'tokenArray' 883 | ); 884 | foreach ($keys as $key) { 885 | if (isset($this->$key)) { 886 | $this->fields[$key] = $this->$key; 887 | } 888 | } 889 | } 890 | } 891 | 892 | 893 | -------------------------------------------------------------------------------- /src/example/test_sample_apns_msg.php: -------------------------------------------------------------------------------- 1 | sendPushMsgMessageByMsgType(Constants::APN_MSG_TYPE); 30 | 31 | $message_arr = array( 32 | '{ 33 | "token": [*push_token*], 34 | "apns": { 35 | "hms_options": { 36 | "target_user_type": 1 37 | }, 38 | "payload": { 39 | "aps": { 40 | "alert": { 41 | "title": "hw1 message title", 42 | "body": "hw message body", 43 | "action-loc-key": "PLAY" 44 | }, 45 | "badge": 5 46 | }, 47 | "acme1": "bar", 48 | "acme2": ["bang", 49 | "whiz"] 50 | } 51 | } 52 | }', 53 | '{ 54 | "token": [*push_token*], 55 | "apns": { 56 | "hms_options": { 57 | "target_user_type": 1 58 | }, 59 | "payload": { 60 | "aps": { 61 | "alert": { 62 | "title": "hw2 message title", 63 | "body": "hw3 message body", 64 | "action-loc-key": "PLAY" 65 | }, 66 | "badge": 5 67 | }, 68 | "acme1": "bar", 69 | "acme2": ["bang", 70 | "whiz"], 71 | "sound": "default", 72 | "launch-image": "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png" 73 | } 74 | } 75 | }', 76 | '{ 77 | "token": [*push_token*], 78 | "apns": { 79 | "hms_options": { 80 | "target_user_type": 1 81 | }, 82 | "payload":{ 83 | "aps" : { 84 | "alert" : { 85 | "title" : "Game3 Request", 86 | "body" : "Bob3 wants to play poker", 87 | "action-loc-key" : "PLAY" 88 | }, 89 | "badge" : 5 90 | }, 91 | "acme1" : "bar", 92 | "acme2" : [ "bang", "whiz" ] 93 | } 94 | } 95 | }' 96 | ); 97 | 98 | foreach ($message_arr as $message) { 99 | $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->apn_push_token_key.'"',$message); 100 | $testPushMsgSample->sendPushMsgRealMessage(json_decode($message)); 101 | } 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /src/example/test_sample_push_condition_msg.php: -------------------------------------------------------------------------------- 1 | sendPushMsgMessageByMsgType(Constants::PUSHMSG_CONDITION_MSG_TYPE); 31 | 32 | $message = '{ 33 | "android": { 34 | "collapse_key": -1, 35 | "urgency": "HIGH", 36 | "ttl": "1448s", 37 | "bi_tag": "Trump", 38 | "notification": { 39 | "title": " condition1 default hw title condition ", 40 | "body": " condition1 default hw body condition ", 41 | "color": "#AACCDD", 42 | "tag": "tagBoom", 43 | "click_action": { 44 | "type": 1, 45 | "intent": "#Intent;compo=com.rvr\/.Activity;S.W=U;end", 46 | "action": "test add" 47 | }, 48 | "body_loc_key": "M.String.body", 49 | "body_loc_args": ["Boy", 50 | "Dog"], 51 | "title_loc_key": "M.String.title", 52 | "title_loc_args": ["Girl", 53 | "Cat"], 54 | "channel_id": "RingRing", 55 | "notify_summary": "Some Summary", 56 | "style": 0, 57 | "big_title": "Big Boom Title", 58 | "big_body": "Big Boom Body", 59 | "auto_clear": 86400000, 60 | "notify_id": 486, 61 | "group": "Espace", 62 | "badge": { 63 | "add_num": 99, 64 | "class": "Classic", 65 | "set_num": 99 66 | }, 67 | "ticker": "i am a ticker", 68 | "auto_cancel": false, 69 | "when": "2019-11-05", 70 | "importance": "NORMAL", 71 | "use_default_vibrate": true, 72 | "use_default_light": false, 73 | "vibrate_config": ["1.5", 74 | "2.000000001", 75 | "3"], 76 | "visibility": "PUBLIC", 77 | "light_settings": { 78 | "color": { 79 | "alpha": 0, 80 | "red": 0, 81 | "green": 1, 82 | "blue": 1 83 | }, 84 | "light_on_duration": "3.5", 85 | "light_off_duration": "5S" 86 | }, 87 | "foreground_show": true 88 | } 89 | }, 90 | "condition": *condition* 91 | }'; 92 | 93 | $topic = '111'; 94 | $message=str_ireplace("*condition*", '"\''.$topic.'\' in topics"',$message); 95 | 96 | $testPushMsgSample->sendPushMsgRealMessage(json_decode($message)); 97 | 98 | -------------------------------------------------------------------------------- /src/example/test_sample_push_instantce_app_msg.php: -------------------------------------------------------------------------------- 1 | sendPushMsgMessageByMsgType(Constants::PUSHMSG_FASTAPP_MSG_TYPE); 29 | 30 | 31 | $message = '{ 32 | "data": "{\"pushtype\":1,\"pushbody\":{\"messageId\":\"111110001\",\"data\":\"test pass-through msg\"}}", 33 | "ssss":"{k1:v1}", 34 | "android": { 35 | "collapse_key": -1, 36 | "urgency": "HIGH", 37 | "ttl": "1448s", 38 | "bi_tag": "Trump", 39 | "fast_app_target": 1 40 | }, 41 | "token": [ 42 | *push_token* 43 | ] 44 | }'; 45 | 46 | 47 | $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->fast_push_token.'"',$message); 48 | $testPushMsgSample->sendPushMsgRealMessage(json_decode($message),Constants::PUSHMSG_FASTAPP_MSG_TYPE); 49 | 50 | -------------------------------------------------------------------------------- /src/example/test_sample_push_notification_msg.php: -------------------------------------------------------------------------------- 1 | sendPushMsgMessageByMsgType(Constants::PUSHMSG_NOTIFICATION_MSG_TYPE); 29 | 30 | 31 | $message_arr = array( 32 | '{ 33 | "notification": { 34 | "title": "Big News1", 35 | "body": "This is a Big News!", 36 | "image": "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png" 37 | }, 38 | "android": { 39 | "notification": { 40 | "click_action": { 41 | "type": 1, 42 | "intent": "#Intent;compo=com.rvr/.Activity;S.W=U;end" 43 | } 44 | 45 | } 46 | }, 47 | "token": [*push_token*] 48 | }', 49 | '{ 50 | "notification": { 51 | "title": "Big News", 52 | "body": "This is a Big News!", 53 | "image": "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png" 54 | }, 55 | "android": { 56 | "notification": { 57 | "title": " real notification default hw title notification2 ", 58 | "body": " real notification default hw body notification ", 59 | "color": "#AACCDD", 60 | "click_action": { 61 | "type": 1, 62 | "intent": "#Intent;compo=com.rvr/.Activity;S.W=U;end" 63 | } 64 | 65 | } 66 | }, 67 | "token": [*push_token*] 68 | }' 69 | ); 70 | 71 | foreach ($message_arr as $message) { 72 | $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->hw_push_token_key.'"',$message); 73 | $testPushMsgSample->sendPushMsgRealMessage(json_decode($message)); 74 | } 75 | -------------------------------------------------------------------------------- /src/example/test_sample_push_passthrouth_msg.php: -------------------------------------------------------------------------------- 1 | sendPushMsgMessageByMsgType(Constants::PUSHMSG_PASS_THROUGHT_MSG_TYPE); 29 | 30 | $message_arr = array( 31 | '{ 32 | "data": "hw test default data1", 33 | "token": [*push_token*] 34 | }', 35 | '{ 36 | "data": "k=v,k=v2", 37 | "android": { 38 | "collapse_key": -1, 39 | "ttl": "10000s", 40 | "bi_tag": "the_sample_bi_tag_for_receipt_service" 41 | }, 42 | "token": [*push_token*] 43 | }', 44 | '{ 45 | "data": "k=v,k=v", 46 | "android": { 47 | "data": "pass through real data3", 48 | "collapse_key": -1, 49 | "ttl": "10000s", 50 | "bi_tag": "the_sample_bi_tag_for_receipt_service" 51 | }, 52 | "token": [*push_token*] 53 | }' 54 | ); 55 | 56 | 57 | 58 | foreach ($message_arr as $message) { 59 | $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->hw_push_token_key.'"',$message); 60 | $testPushMsgSample->sendPushMsgRealMessage(json_decode($message)); 61 | } -------------------------------------------------------------------------------- /src/example/test_sample_push_quick_app_msg.php: -------------------------------------------------------------------------------- 1 | sendPushMsgMessageByMsgType(Constants::PUSHMSG_FASTAPP_MSG_TYPE); 29 | 30 | 31 | $message = '{ 32 | "data": "{\"pushtype\":1,\"pushbody\":{\"messageId\":\"111110001\",\"data\":\"test pass-through msg\"}}", 33 | "ssss":"{k1:v1}", 34 | "android": { 35 | "collapse_key": -1, 36 | "urgency": "HIGH", 37 | "ttl": "1448s", 38 | "bi_tag": "Trump", 39 | "fast_app_target": 1 40 | }, 41 | "token": [ 42 | *push_token* 43 | ] 44 | }'; 45 | 46 | 47 | $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->fast_push_token.'"',$message); 48 | $testPushMsgSample->sendPushMsgRealMessage(json_decode($message),Constants::PUSHMSG_FASTAPP_MSG_TYPE); 49 | 50 | -------------------------------------------------------------------------------- /src/example/test_sample_push_topic_msg.php: -------------------------------------------------------------------------------- 1 | sendPushTopicMsgMessage($topic); 36 | } 37 | 38 | $testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_TOPIC_MSG_TYPE,$topic); 39 | 40 | $message_arr = array('{ 41 | "data": "1111", 42 | "android": { 43 | "notification": { 44 | "title": " topic1 default hw title topic ", 45 | "body": " topic1 default hw body topic ", 46 | "color": "#AACCDD", 47 | "tag": "tagBoom", 48 | "click_action": { 49 | "type": 1, 50 | "intent": "#Intent;compo=com.rvr\/.Activity;S.W=U;end", 51 | "action": "test add" 52 | } 53 | } 54 | }, 55 | "topic": *topic* 56 | }','{ 57 | "data": "1111", 58 | "android": { 59 | "notification": { 60 | "title": " topic2 default hw title topic ", 61 | "body": " topic2 default hw body topic ", 62 | "click_action": { 63 | "type": 1, 64 | "intent": "#Intent;compo=com.rvr\/.Activity;S.W=U;end" 65 | } 66 | } 67 | }, 68 | "topic": *topic* 69 | }'); 70 | 71 | foreach ($message_arr as $message) { 72 | $message=str_ireplace("*topic*", '"'.$topic.'"',$message); 73 | $testPushMsgSample->sendPushMsgRealMessage(json_decode($message)); 74 | } 75 | -------------------------------------------------------------------------------- /src/example/test_sample_push_webpush_msg.php: -------------------------------------------------------------------------------- 1 | sendPushMsgMessageByMsgType(Constants::WEB_PUSH_MSG_TYPE); 29 | 30 | $message_arr = array('{ 31 | "token": [*push_token*], 32 | "webpush": { 33 | "headers": { 34 | "ttl": "990", 35 | "topic": "12313ceshi", 36 | "urgency": "very-low" 37 | }, 38 | "data": "test webpush data", 39 | "notification": { 40 | "title": "web2 push title test", 41 | "body": "web2 push body", 42 | "icon": "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png", 43 | "image": "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png", 44 | "lang": "string", 45 | "tag": "string", 46 | "badge": "string", 47 | "dir": "auto", 48 | "vibrate": [1, 49 | 2, 50 | 3], 51 | "renotify": false, 52 | "require_interaction": false, 53 | "silent": false, 54 | "timestamp": 1545201266, 55 | "actions": [{ 56 | "title": "string", 57 | "icon": "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png", 58 | "action": "123" 59 | }] 60 | }, 61 | "hms_options": { 62 | "link": "https://www.huawei.com/" 63 | } 64 | } 65 | }', 66 | '{ 67 | "token": [*push_token*], 68 | "webpush": { 69 | "headers": { 70 | "ttl": "11990", 71 | "topic": "test", 72 | "urgency": "low" 73 | }, 74 | "data": "test webpush data", 75 | "notification": { 76 | "title": "hw default web push title test", 77 | "body": "hw default web push body", 78 | "require_interaction": false, 79 | "silent": false, 80 | "timestamp": 1545201266, 81 | "actions": [{ 82 | "title": "string", 83 | "icon": "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png", 84 | "action": "123" 85 | }] 86 | }, 87 | "hms_options": { 88 | "link": "https://www.huawei.com/" 89 | } 90 | } 91 | }' 92 | ); 93 | 94 | foreach ($message_arr as $message) { 95 | $message=str_ireplace("*push_token*", '"'.$testPushMsgSample->webpush_push_token_key.'"',$message); 96 | $testPushMsgSample->sendPushMsgRealMessage(json_decode($message)); 97 | } 98 | -------------------------------------------------------------------------------- /src/example/test_sample_test_push_msg.php: -------------------------------------------------------------------------------- 1 | sendPushMsgMessageByMsgType(Constants::PUSHMSG_NOTIFICATION_MSG_TYPE); 24 | -------------------------------------------------------------------------------- /src/push_admin/Application.php: -------------------------------------------------------------------------------- 1 | push msg 21 | * common_send_msg => topic msg 22 | */ 23 | namespace push_admin; 24 | 25 | include_once (dirname(__FILE__) . '/Constants.php'); 26 | include_once (dirname(__FILE__) . '/PushLogConfig.php'); 27 | 28 | class Application 29 | { 30 | 31 | private $appid; 32 | 33 | private $appsecret; 34 | 35 | private $token_expiredtime; 36 | 37 | private $access_token; 38 | 39 | private $validate_only; 40 | 41 | private $hw_token_server; 42 | 43 | private $hw_push_server; 44 | 45 | private $fields; 46 | 47 | 48 | public function __construct($appid, $appsecret, $hw_token_server, $hw_push_server) 49 | { 50 | $this->appid = $appid; 51 | $this->appsecret = $appsecret; 52 | $this->hw_token_server = $hw_token_server; 53 | $this->hw_push_server = $hw_push_server; 54 | $this->token_expiredtime = null; 55 | $this->accesstoken = null; 56 | $this->validate_only = false; 57 | } 58 | 59 | public function appid($value) 60 | { 61 | $this->appid = $value; 62 | } 63 | 64 | public function appsecret($value) 65 | { 66 | $this->appsecret = $value; 67 | } 68 | 69 | public function validate_only($value) 70 | { 71 | $this->validate_only = $value; 72 | } 73 | 74 | public function getApplicationFields() 75 | { 76 | $keys = array( 77 | 'appid', 78 | 'appsecret', 79 | 'hw_token_server', 80 | 'hw_push_server', 81 | 'validate_only', 82 | 'accesstoken', 83 | 'token_expiredtime' 84 | ); 85 | foreach ($keys as $key) { 86 | if (isset($this->$key)) { 87 | $this->fields[$key] = $this->$key; 88 | } 89 | } 90 | 91 | return $this->fields; 92 | } 93 | 94 | private function printLogMethodOperate($dataFlow, $functionName = "", $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL) 95 | { 96 | if (empty($functionName)) { 97 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . $dataFlow, $logLevel); 98 | } else { 99 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . ']' . '[' . $functionName . ']' . $dataFlow, $logLevel); 100 | } 101 | } 102 | 103 | private function is_token_expired() 104 | { 105 | if (empty($this->accesstoken)) { 106 | return true; 107 | } 108 | if (time() > $this->token_expiredtime) { 109 | return true; 110 | } 111 | return false; 112 | } 113 | 114 | private function refresh_token() 115 | { 116 | $result = json_decode($this->curl_https_post($this->hw_token_server, http_build_query(array( 117 | "grant_type" => "client_credentials", 118 | "client_secret" => $this->appsecret, 119 | "client_id" => $this->appid 120 | )), array( 121 | "Content-Type: application/x-www-form-urlencoded;charset=utf-8" 122 | ))); 123 | $this->printLogMethodOperate('refresh_token result:' . json_encode($result), __FUNCTION__ . ':' . __LINE__); 124 | if ($result == null || ! array_key_exists("access_token", $result)) { 125 | $this->printLogMethodOperate('refresh_token result error!', __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_ERROR_LEVEL); 126 | return null; 127 | } 128 | $this->printLogMethodOperate('refresh_token result:' . json_encode($result), __FUNCTION__ . ':' . __LINE__); 129 | $this->accesstoken = $result->access_token; 130 | $this->token_expiredtime = time() + $result->expires_in; 131 | return $this->access_token; 132 | } 133 | 134 | private function curl_https_post($url, $data = array(), $header = array()) 135 | { 136 | $this->printLogMethodOperate('curl_https_post enter url:' . $url, __FUNCTION__ . ':' . __LINE__); 137 | $ch = curl_init($url); 138 | 139 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 140 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 141 | $this->printLogMethodOperate('curl_https_post curl send headers:' . json_encode($header), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 142 | 143 | // resolve SSL: no alternative certificate subject name matches target host name 144 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // check verify 145 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 146 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 147 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 148 | curl_setopt($ch, CURLOPT_TIMEOUT, 5); 149 | curl_setopt($ch, CURLOPT_POST, 1); // regular post request 150 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // Post submit data 151 | 152 | $this->printLogMethodOperate('curl_https_post curl send body:' . $data, __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 153 | 154 | $ret = @curl_exec($ch); 155 | if ($ret === false) { 156 | $this->printLogMethodOperate('curl_exec error #' . curl_errno($ch) . ' : ' . curl_error($ch), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_ERROR_LEVEL); 157 | return null; 158 | } 159 | 160 | $info = curl_getinfo($ch); 161 | 162 | $this->printLogMethodOperate('curl_https_post curl send info:' . json_encode($info), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 163 | 164 | curl_close($ch); 165 | 166 | return $ret; 167 | } 168 | 169 | /** 170 | * push_send_msg for push msg 171 | */ 172 | public function push_send_msg($msg) 173 | { 174 | $this->printLogMethodOperate('push_send_msg enter msg:' . json_encode($msg), __FUNCTION__ . ':' . __LINE__); 175 | $body = array( 176 | "validate_only" => $this->validate_only, 177 | "message" => $msg 178 | ); 179 | 180 | $this->printLogMethodOperate('push_send_msg new body:' . json_encode($body), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 181 | 182 | if ($this->is_token_expired()) { 183 | $this->refresh_token(); 184 | } 185 | 186 | if (empty($this->accesstoken)){ 187 | $this->printLogMethodOperate("accesstoken is empty!", 188 | __FUNCTION__ . ':' . __LINE__,Constants::HW_PUSH_LOG_ERROR_LEVEL); 189 | return null; 190 | } 191 | 192 | $result = json_decode($this->curl_https_post(str_replace('{appid}', $this->appid, $this->hw_push_server), json_encode($body), array( 193 | "Content-Type: application/json", 194 | "Authorization: Bearer {$this->accesstoken}" 195 | ) // Use bearer auth 196 | )); 197 | 198 | $this->printLogMethodOperate("push_send_msg leave,result:" . json_encode($result), __FUNCTION__ . ':' . __LINE__); 199 | // $result ==> eg: {"code":"80000000","msg":"Success","requestId":"157278422841836431010901"} 200 | 201 | if (! empty($result)) { 202 | $arrResult = json_decode(json_encode($result), true); 203 | if (!empty($arrResult["code"]) && !in_array($arrResult["code"], array( "80000000",80000000))) { 204 | $this->printLogMethodOperate("push_send_msg leave,result:" . json_encode($result), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_WARN_LEVEL); 205 | } 206 | } 207 | 208 | return $result; 209 | } 210 | 211 | /** 212 | * common_send_msg for topic msg/other 213 | */ 214 | public function common_send_msg($msg) 215 | { 216 | $this->printLogMethodOperate('common_send_msg enter msg:' . json_encode($msg), __FUNCTION__ . ':' . __LINE__); 217 | if ($this->is_token_expired()) { 218 | $this->refresh_token(); 219 | } 220 | 221 | if (empty($this->accesstoken)){ 222 | $this->printLogMethodOperate("accesstoken is empty!", 223 | __FUNCTION__ . ':' . __LINE__,Constants::HW_PUSH_LOG_ERROR_LEVEL); 224 | return null; 225 | } 226 | 227 | $result = json_decode($this->curl_https_post(str_replace('{appid}', $this->appid, $this->hw_push_server), json_encode($msg), array( 228 | "Content-Type: application/json", 229 | "Authorization: Bearer {$this->accesstoken}" 230 | ) // Use bearer auth 231 | )); 232 | 233 | // $result ==> eg: {"code":"80000000","msg":"Success","requestId":"157278422841836431010901"} 234 | $this->printLogMethodOperate('common_send_msg leave result:' . json_encode($result), __FUNCTION__ . ':' . __LINE__); 235 | 236 | 237 | if (! empty($result)) { 238 | $arrResult = json_decode(json_encode($result), true); 239 | if (isset($arrResult["code"]) && $arrResult["code"] != "80000000") { 240 | $this->printLogMethodOperate("push_send_msg leave,result:" . json_encode($result), __FUNCTION__ . ':' . __LINE__, Constants::HW_PUSH_LOG_WARN_LEVEL); 241 | } 242 | } 243 | 244 | return $result; 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /src/push_admin/Constants.php: -------------------------------------------------------------------------------- 1 | log_read_flag == false) { 53 | $file_path = "../config.ini"; 54 | if (file_exists($file_path)) { 55 | $file_contents = file($file_path); 56 | // read line 57 | for ($i = 0; $i < count($file_contents); $i ++) { 58 | $this->processConfigData($file_contents[$i]); 59 | } 60 | $this->log_read_flag = true; 61 | } else { 62 | echo $file_path . " not exist,please config first!!!
"; 63 | } 64 | } 65 | } 66 | 67 | public static function getSingleInstance() 68 | { 69 | static $obj; 70 | if (! isset($obj)) { 71 | $obj = new PushConfig(); 72 | } 73 | return $obj; 74 | } 75 | 76 | private function processConfigData($lineData) 77 | { 78 | if (empty($lineData)) { 79 | return; 80 | } 81 | if (strncmp($lineData, "#", 1) == 0) { 82 | return; 83 | } 84 | $lineData = str_replace("\"", "", $lineData); 85 | $lineData = str_replace("\'", "", $lineData); 86 | $lineData = str_replace(" ", "", $lineData); 87 | $lineData = str_replace(";", "", $lineData); 88 | 89 | $order=array("\r\n","\n","\r"); 90 | $lineData=str_replace($order,"",$lineData); 91 | $lineData = str_replace(PHP_EOL, '', $lineData); 92 | $resultPos = stripos($lineData, "="); 93 | if (FALSE == $resultPos) { 94 | return; 95 | } 96 | $key = substr($lineData, 0, $resultPos); 97 | 98 | if (FALSE == $key) { 99 | return; 100 | } 101 | 102 | $value = $this->processConfigValueData(substr($lineData, $resultPos + 1)); 103 | switch ($key) { 104 | case "HW_APPID": 105 | { 106 | $this->HW_APPID = $value; 107 | } 108 | break; 109 | case "HW_APPSECRET": 110 | { 111 | $this->HW_APPSECRET = $value; 112 | } 113 | break; 114 | case "HW_TOKEN_SERVER": 115 | { 116 | $this->HW_TOKEN_SERVER = $value; 117 | } 118 | break; 119 | case "HW_PUSH_SERVER": 120 | { 121 | $this->HW_PUSH_SERVER = $value; 122 | } 123 | break; 124 | case "HW_TOPIC_SUBSCRIBE_SERVER": 125 | { 126 | $this->HW_TOPIC_SUBSCRIBE_SERVER = $value; 127 | } 128 | break; 129 | case "HW_TOPIC_UNSUBSCRIBE_SERVER": 130 | { 131 | $this->HW_TOPIC_UNSUBSCRIBE_SERVER = $value; 132 | } 133 | break; 134 | case "HW_TOPIC_QUERY_SUBSCRIBER_SERVER": 135 | { 136 | $this->HW_TOPIC_QUERY_SUBSCRIBER_SERVER = $value; 137 | } 138 | break; 139 | 140 | case "HW_PUSH_TOKEN_ARR": 141 | { 142 | $this->HW_PUSH_TOKEN_ARR = $value; 143 | } 144 | break; 145 | 146 | case "APN_PUSH_TOKEN_ARR": 147 | { 148 | $this->APN_PUSH_TOKEN_ARR = $value; 149 | } 150 | break; 151 | 152 | case "WEBPUSH_PUSH_TOKEN_ARR": 153 | { 154 | $this->WEBPUSH_PUSH_TOKEN_ARR = $value; 155 | } 156 | break; 157 | case "HW_DEFAULT_LOG_LEVEL": 158 | { 159 | $this->HW_DEFAULT_LOG_LEVEL = $value; 160 | } 161 | break; 162 | 163 | case "HW_FAST_APPID": 164 | { 165 | $this->HW_FAST_APPID = $value; 166 | } 167 | break; 168 | case "HW_FAST_APPSECRET": 169 | { 170 | $this->HW_FAST_APPSECRET = $value; 171 | } 172 | break; 173 | case "HW_FAST_PUSH_TOKEN": 174 | { 175 | $this->HW_FAST_PUSH_TOKEN = $value; 176 | } 177 | break; 178 | 179 | } 180 | } 181 | 182 | private function processConfigValueData($lineDataMapValue) 183 | { 184 | $key = stripos($lineDataMapValue, "\""); 185 | if (FALSE == $key) { 186 | return $lineDataMapValue; 187 | } 188 | if ($key > 0) { 189 | return str_replace("\"", "", substr($lineDataMapValue, $key)); 190 | } 191 | return $lineDataMapValue; 192 | } 193 | } 194 | 195 | -------------------------------------------------------------------------------- /src/push_admin/PushLogConfig.php: -------------------------------------------------------------------------------- 1 | LogFile = @fopen(Constants::HW_PUSH_LOG_FILE_NAME, 'a+'); 46 | if (! is_resource($this->LogFile)) { 47 | throw new Exception(Constants::HW_PUSH_LOG_FILE_NAME . 'invalid file Stream'); 48 | } 49 | 50 | fwrite($this->LogFile, $this->logBanner); 51 | 52 | $pushConfig = PushConfig::getSingleInstance(); 53 | 54 | $this->default_log_level = $pushConfig->HW_DEFAULT_LOG_LEVEL; 55 | if (empty($this->default_log_level)){ 56 | $this->default_log_level = Constants::HW_PUSH_LOG_INFO_LEVEL; 57 | } 58 | } 59 | 60 | /** 61 | * single instance 62 | */ 63 | public static function getSingleInstance() 64 | { 65 | static $obj; 66 | if (! isset($obj)) { 67 | $obj = new PushLogConfig(); 68 | } 69 | return $obj; 70 | } 71 | 72 | /** 73 | * core log process 74 | */ 75 | public function LogMessage($msg, $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL, $module = null, $timeZone = 'Asia/shanghai', $timeFormat = "%Y-%m-%d %H:%M:%S") 76 | { 77 | if (empty($logLevel)) { 78 | $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL; 79 | } 80 | 81 | if ($logLevel > $this->default_log_level) { 82 | return; 83 | } 84 | date_default_timezone_set($timeZone); 85 | $time = strftime($timeFormat, time()); 86 | $msg = str_replace("\t", '', $msg); 87 | $msg = str_replace("\n", '', $msg); 88 | $strLogLevel = $this->levelToString($logLevel); 89 | if (isset($module)) { 90 | $module = '[' . str_pad(str_replace(array( 91 | "\n", 92 | "\t" 93 | ), array( 94 | "", 95 | "" 96 | ), $module), $this->LOG_MODULE_FIXED_LEN) . ']'; 97 | $logLine = "$time\t$strLogLevel\t$module\t$msg\r\n"; 98 | } else { 99 | $logLine = "$time\t$strLogLevel\t$msg\r\n"; 100 | } 101 | 102 | print_r($logLine . '
'); 103 | fwrite($this->LogFile, $logLine); 104 | } 105 | 106 | private function levelToString($logLevel) 107 | { 108 | $ret = 'LOG::UNKNOWN'; 109 | switch ($logLevel) { 110 | case Constants::HW_PUSH_LOG_DEBUG_LEVEL: 111 | $ret = 'LOG::DEBUG'; 112 | break; 113 | case Constants::HW_PUSH_LOG_INFO_LEVEL: 114 | $ret = 'LOG::INFO'; 115 | break; 116 | case Constants::HW_PUSH_LOG_WARN_LEVEL: 117 | $ret = 'LOG::WARNING'; 118 | break; 119 | case Constants::HW_PUSH_LOG_ERROR_LEVEL: 120 | $ret = 'LOG::ERROR'; 121 | break; 122 | } 123 | return $ret; 124 | } 125 | } 126 | 127 | -------------------------------------------------------------------------------- /src/push_admin/push_msg/PushMessage.php: -------------------------------------------------------------------------------- 1 | fields = array(); 49 | $this->token = null; 50 | $this->condition = null; 51 | $this->topic = null; 52 | $this->notification = null; 53 | } 54 | 55 | public function data($value) 56 | { 57 | $this->data = $value; 58 | } 59 | 60 | public function notification($value) 61 | { 62 | $this->notification = $value; 63 | } 64 | 65 | public function android($value) 66 | { 67 | $this->android = $value; 68 | } 69 | 70 | public function token($value) 71 | { 72 | $this->token = $value; 73 | } 74 | public function get_token(){ 75 | return $this->token; 76 | } 77 | 78 | public function topic($value) 79 | { 80 | $this->topic = $value; 81 | } 82 | 83 | public function condition($value) 84 | { 85 | $this->condition = $value; 86 | } 87 | 88 | public function apns($value) 89 | { 90 | $this->apns = $value; 91 | } 92 | 93 | public function webpush($value) 94 | { 95 | $this->webpush = $value; 96 | } 97 | 98 | public function getFields() 99 | { 100 | return $this->fields; 101 | } 102 | 103 | public function buildFields() 104 | { 105 | $keys = array( 106 | 'data', 107 | 'notification', 108 | 'android', 109 | 'token', 110 | 'topic', 111 | 'condition', 112 | 'apns', 113 | 'webpush' 114 | ); 115 | foreach ($keys as $key) { 116 | if (isset($this->$key)) { 117 | $this->fields[$key] = $this->$key; 118 | } 119 | } 120 | } 121 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/ValidatorUtil.php: -------------------------------------------------------------------------------- 1 | urgency = null; 52 | $this->notification = null; 53 | $this->fields = array(); 54 | } 55 | 56 | public function getFields() 57 | { 58 | return $this->fields; 59 | } 60 | 61 | public function collapse_key($value) 62 | { 63 | $this->collapse_key = $value; 64 | } 65 | 66 | public function category($value) 67 | { 68 | $this->category = $value; 69 | } 70 | 71 | public function urgency($value) 72 | { 73 | $this->urgency = $value; 74 | } 75 | 76 | public function ttl($value) 77 | { 78 | $this->ttl = $value; 79 | } 80 | 81 | public function bi_tag($value) 82 | { 83 | $this->bi_tag = $value; 84 | } 85 | 86 | public function fast_app_target($value) 87 | { 88 | $this->fast_app_target = $value; 89 | } 90 | 91 | public function notification($value) 92 | { 93 | $this->notification = $value; 94 | } 95 | 96 | public function data($value) 97 | { 98 | $this->data = $value; 99 | } 100 | 101 | public function buildFields() 102 | { 103 | try { 104 | $this->check_parameter(); 105 | } catch (Exception $e) { 106 | // echo $e; 107 | PushLogConfig::getSingleInstance()->LogMessage($e,Constants::HW_PUSH_LOG_ERROR_LEVEL); 108 | return; 109 | } 110 | $keys = array( 111 | 'collapse_key', 112 | 'category', 113 | 'urgency', 114 | 'ttl', 115 | 'bi_tag', 116 | 'fast_app_target', 117 | 'notification', 118 | 'data' 119 | ); 120 | foreach ($keys as $key) { 121 | if (isset($this->$key)) { 122 | $this->fields[$key] = $this->$key; 123 | } 124 | } 125 | } 126 | 127 | private function check_parameter() 128 | { 129 | if (! empty($this->collapse_key) && ($this->collapse_key < - 1 || $this->collapse_key > 100)) { 130 | throw new Exception("Collapse Key should be [-1, 100]"); 131 | } 132 | if (! empty($this->fast_app_target) && ! in_array($this->fast_app_target, array( 133 | 1, 134 | 2 135 | ))) { 136 | throw new Exception("Invalid fast app target type[one of 1 or 2]"); 137 | } 138 | 139 | if (! empty($this->urgency) && ! in_array($this->urgency, array( 140 | AndroidConfigDeliveryPriority::PRIORITY_HIGH, 141 | AndroidConfigDeliveryPriority::PRIORITY_NORMAL 142 | ))) { 143 | throw new Exception("delivery priority shouid be [HIGH, NOMAL]"); 144 | } 145 | 146 | if (! empty($this->ttl)) { 147 | if (FALSE == ValidatorUtil::validatePattern(Constants::TTL_PATTERN, $this->ttl)) { 148 | throw new Exception("The TTL's format is wrong"); 149 | } 150 | } 151 | } 152 | 153 | public function get_all_vars() 154 | { 155 | var_dump(get_object_vars($this)); 156 | } 157 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/android/AndroidNotification.php: -------------------------------------------------------------------------------- 1 | click_action = array(); 111 | $this->body_loc_args = array(); 112 | $this->title_loc_args = array(); 113 | $this->badge = array(); 114 | $this->light_settings = array(); 115 | $this->foreground_show = true; 116 | $this->fields = array(); 117 | } 118 | 119 | public function title($value) 120 | { 121 | $this->title = $value; 122 | } 123 | 124 | public function body($value) 125 | { 126 | $this->body = $value; 127 | } 128 | 129 | public function icon($value) 130 | { 131 | $this->icon = $value; 132 | } 133 | 134 | public function color($value) 135 | { 136 | $this->color = $value; 137 | } 138 | 139 | public function sound($value) 140 | { 141 | $this->sound = $value; 142 | } 143 | 144 | public function tag($value) 145 | { 146 | $this->tag = $value; 147 | } 148 | 149 | public function click_action($value) 150 | { 151 | $this->click_action = $value; 152 | } 153 | 154 | public function body_loc_key($value) 155 | { 156 | $this->body_loc_key = $value; 157 | } 158 | 159 | public function body_loc_args($value) 160 | { 161 | $this->body_loc_args = $value; 162 | } 163 | 164 | public function title_loc_key($value) 165 | { 166 | $this->title_loc_key = $value; 167 | } 168 | 169 | public function title_loc_args($value) 170 | { 171 | $this->title_loc_args = $value; 172 | } 173 | 174 | public function channel_id($value) 175 | { 176 | $this->channel_id = $value; 177 | } 178 | 179 | public function notify_summary($value) 180 | { 181 | $this->notify_summary = $value; 182 | } 183 | 184 | // added 185 | public function image($value) 186 | { 187 | $this->image = $value; 188 | } 189 | 190 | public function notify_icon($value) 191 | { 192 | $this->notify_icon = $value; 193 | } 194 | 195 | public function style($value) 196 | { 197 | $this->style = $value; 198 | } 199 | 200 | public function big_title($value) 201 | { 202 | $this->big_title = $value; 203 | } 204 | 205 | public function big_body($value) 206 | { 207 | $this->big_body = $value; 208 | } 209 | 210 | public function auto_clear($value) 211 | { 212 | $this->auto_clear = $value; 213 | } 214 | 215 | public function notify_id($value) 216 | { 217 | $this->notify_id = $value; 218 | } 219 | 220 | public function group($value) 221 | { 222 | $this->group = $value; 223 | } 224 | 225 | public function badge($value) 226 | { 227 | $this->badge = $value; 228 | } 229 | 230 | public function ticker($value) 231 | { 232 | $this->ticker = $value; 233 | } 234 | 235 | public function auto_cancel($value) 236 | { 237 | $this->auto_cancel = $value; 238 | } 239 | 240 | public function when($value) 241 | { 242 | $this->when = $value; 243 | } 244 | 245 | public function importance($value) 246 | { 247 | $this->importance = $value; 248 | } 249 | 250 | public function use_default_vibrate($value) 251 | { 252 | $this->use_default_vibrate = $value; 253 | } 254 | 255 | public function use_default_light($value) 256 | { 257 | $this->use_default_light = $value; 258 | } 259 | 260 | public function vibrate_config($value) 261 | { 262 | $this->vibrate_config = $value; 263 | } 264 | 265 | public function visibility($value) 266 | { 267 | $this->visibility = $value; 268 | } 269 | 270 | public function light_settings($value) 271 | { 272 | $this->light_settings = $value; 273 | } 274 | 275 | public function foreground_show($value) 276 | { 277 | $this->foreground_show = $value; 278 | } 279 | 280 | public function getFields() 281 | { 282 | return $this->fields; 283 | } 284 | 285 | public function buildFields() 286 | { 287 | try { 288 | $this->check_parameter(); 289 | } catch (Exception $e) { 290 | PushLogConfig::getSingleInstance()->LogMessage($e,Constants::HW_PUSH_LOG_ERROR_LEVEL); 291 | return; 292 | } 293 | 294 | $keys = array( 295 | 'title', 296 | 'body', 297 | 'image', 298 | 'icon', 299 | 'color', 300 | 'sound', 301 | 'tag', 302 | 'click_action', 303 | 'body_loc_key', 304 | 'body_loc_args', 305 | 'title_loc_key', 306 | 'title_loc_args', 307 | 'channel_id', 308 | 'notify_summary', 309 | 'notify_icon', 310 | 'style', 311 | 'big_title', 312 | 'big_body', 313 | 'auto_clear', 314 | 'notify_id', 315 | 'group', 316 | 'badge', 317 | 'ticker', 318 | 'auto_cancel', 319 | 'when', 320 | 'importance', 321 | 'use_default_vibrate', 322 | 'use_default_light', 323 | 'vibrate_config', 324 | 'visibility', 325 | 'light_settings', 326 | 'foreground_show' 327 | ); 328 | foreach ($keys as $key) { 329 | if (isset($this->$key)) { 330 | $this->fields[$key] = $this->$key; 331 | } 332 | } 333 | } 334 | 335 | private function check_parameter() 336 | { 337 | if (empty($this->title)) 338 | { 339 | throw new Exception("title should be set"); 340 | } 341 | if (empty($this->body)) 342 | { 343 | throw new Exception("body should be set"); 344 | } 345 | 346 | if (! empty($this->color)) { 347 | if (FALSE == ValidatorUtil::validatePattern(Constants::COLOR_PATTERN, $this->color)) { 348 | throw new Exception("Wrong color format, color must be in the form #RRGGBB"); 349 | } 350 | } 351 | 352 | if (! empty($this->body_loc_args) && empty($this->body_loc_key)) { 353 | throw new Exception("bodyLocKey is required when specifying bodyLocArgs"); 354 | } 355 | 356 | if (! empty($this->title_loc_args) && empty($this->title_loc_key)) { 357 | throw new Exception("titleLocKey is required when specifying titleLocArgs"); 358 | } 359 | 360 | if (! empty($this->image)) { 361 | if (FALSE == ValidatorUtil::validatePattern(Constants::URL_PATTERN, $this->image)) { 362 | throw new Exception("notifyIcon must start with https"); 363 | } 364 | } 365 | 366 | if (($this->style) && (gettype($this->style) != "integer")) { 367 | throw new Exception("type of style is wrong."); 368 | } 369 | 370 | if (! in_array($this->style, array( 371 | 0, 372 | 1 373 | ))) { 374 | throw new Exception("style should be one of 0:default, 1: big text"); 375 | } 376 | 377 | // importance 378 | if (! empty($this->importance) && ! in_array($this->importance, array( 379 | NotificationPriority::NOTIFICATION_PRIORITY_LOW, 380 | NotificationPriority::NOTIFICATION_PRIORITY_NORMAL, 381 | NotificationPriority::NOTIFICATION_PRIORITY_HIGH, 382 | ))) { 383 | throw new Exception("notification priority shouid be [LOW,NORMAL,HIGH]"); 384 | } 385 | 386 | // vibrate_config 387 | if (! empty($this->vibrate_config)) { 388 | foreach ($this->vibrate_config as $key) { 389 | if (FALSE == ValidatorUtil::validatePattern(Constants::VIBRATE_PATTERN, $key)) { 390 | throw new Exception("Wrong vibrate timing format"); 391 | } 392 | } 393 | } 394 | 395 | // visibility 396 | if (! empty($this->visibility) && ! in_array($this->visibility, array( 397 | Visibility::VISIBILITY_UNSPECIFIED, 398 | Visibility::PRIVATE_STR, 399 | Visibility::PUBLIC_STR, 400 | Visibility::SECRET_STR 401 | ))) { 402 | throw new Exception("visibility shouid be [VISIBILITY_UNSPECIFIED, PRIVATE, PUBLIC, SECRET]"); 403 | } 404 | 405 | // auto_clear 406 | if (($this->auto_clear) && (gettype($this->auto_clear) != "integer")) { 407 | throw new Exception("type of auto_clear is wrong."); 408 | } 409 | // notify_id 410 | if (($this->notify_id) && (gettype($this->notify_id) != "integer")) { 411 | throw new Exception("type of notify_id is wrong."); 412 | } 413 | 414 | 415 | } 416 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/android/Badge.php: -------------------------------------------------------------------------------- 1 | AndroidNotification(badge) 20 | * =>AndroidConfig(notification) 21 | * =>PushMessage(android) 22 | */ 23 | namespace push_admin\push_msg\android; 24 | 25 | use Exception; 26 | 27 | class Badge 28 | { 29 | 30 | private $add_num; 31 | 32 | private $class; 33 | 34 | private $set_num; 35 | 36 | private $fields; 37 | 38 | public function __construct() 39 | { 40 | $this->fields = array(); 41 | } 42 | 43 | public function add_num($value) 44 | { 45 | $this->add_num = $value; 46 | } 47 | 48 | public function setclass($value) 49 | { 50 | $this->class = $value; 51 | } 52 | 53 | public function set_num($value) 54 | { 55 | $this->set_num = $value; 56 | } 57 | 58 | public function getFields() 59 | { 60 | return $this->fields; 61 | } 62 | 63 | public function buildFields() 64 | { 65 | try { 66 | $this->check_parameter(); 67 | } catch (Exception $e) { 68 | echo $e; 69 | } 70 | $keys = array( 71 | 'add_num', 72 | 'class', 73 | 'set_num' 74 | ); 75 | foreach ($keys as $key) { 76 | if (isset($this->$key)) { 77 | $this->fields[$key] = $this->$key; 78 | } 79 | } 80 | } 81 | 82 | private function check_parameter() 83 | { 84 | if (($this->add_num) && (gettype($this->add_num) != "integer")) { 85 | throw new Exception("type of add_num is wrong."); 86 | } 87 | if (is_int($this->add_num) && ($this->add_num < 1 || $this->add_num > 100)) { 88 | throw new Exception("add_num should locate between 0 and 100"); 89 | } 90 | if (($this->set_num) && (gettype($this->set_num) != "integer")) { 91 | throw new Exception("type of set_num is wrong."); 92 | } 93 | if (is_int($this->set_num) && ($this->set_num < 1 || $this->set_num > 100)) { 94 | throw new Exception("set_num should locate between 0 and 100"); 95 | } 96 | 97 | } 98 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/android/ClickAction.php: -------------------------------------------------------------------------------- 1 | AndroidNotification(clickaction) 20 | * =>AndroidConfig(notification) 21 | * =>PushMessage(android) 22 | */ 23 | namespace push_admin\push_msg\android; 24 | 25 | include_once (dirname(__FILE__) . '/../ValidatorUtil.php'); 26 | 27 | use push_admin\ValidatorUtil; 28 | 29 | use Exception; 30 | 31 | class ClickAction 32 | { 33 | 34 | private $type; 35 | 36 | private $intent; 37 | 38 | private $url; 39 | 40 | private $rich_resource; 41 | 42 | // added 43 | private $action; 44 | 45 | private $fields; 46 | 47 | public function __construct() 48 | { 49 | $this->rich_resource = null; 50 | $this->url = null; 51 | } 52 | 53 | public function type($value) 54 | { 55 | $this->type = $value; 56 | } 57 | 58 | public function intent($value) 59 | { 60 | $this->intent = $value; 61 | } 62 | 63 | public function url($value) 64 | { 65 | $this->url = $value; 66 | } 67 | 68 | public function rich_resource($value) 69 | { 70 | $this->rich_resource = $value; 71 | } 72 | 73 | // added 74 | public function action($value) 75 | { 76 | $this->action = $value; 77 | } 78 | 79 | public function getFields() 80 | { 81 | return $this->fields; 82 | } 83 | 84 | public function buildFields() 85 | { 86 | try { 87 | $this->check_parameter(); 88 | } catch (Exception $e) { 89 | echo $e; 90 | } 91 | $keys = array( 92 | 'type', 93 | 'intent', 94 | 'url', 95 | 'rich_resource', 96 | // add 97 | 'action' 98 | ); 99 | foreach ($keys as $key) { 100 | if (isset($this->$key)) { 101 | $this->fields[$key] = $this->$key; 102 | } 103 | } 104 | } 105 | 106 | private function check_parameter() 107 | { 108 | if (($this->type) && (gettype($this->type) != "integer")) { 109 | throw new Exception("type of type is wrong."); 110 | } 111 | if (!in_array($this->type, array(1,2,3,4))){ 112 | throw new Exception("click type should be one of 1: customize action, 2: open url, 3: open app, 4: open rich media"); 113 | } 114 | $PATTERN = "/^https.*/"; 115 | switch($this->type){ 116 | case 1:{ 117 | if (is_null($this->intent) && is_null($this->action)) { 118 | throw new Exception("when type=1,intent/action at least one is valid"); 119 | } 120 | } 121 | break; 122 | case 2:{ 123 | if (is_null($this->url)){ 124 | throw new Exception("url is required when click type=2"); 125 | } 126 | if (FALSE == ValidatorUtil::validatePattern($PATTERN,$this->url)){ 127 | throw new Exception("url must start with https"); 128 | } 129 | } 130 | break; 131 | case 4:{ 132 | if (is_null($this->richResource)){ 133 | throw new Exception("richResource is required when click type=4"); 134 | } 135 | 136 | if (FALSE == ValidatorUtil::validatePattern($PATTERN,$this->richResource)){ 137 | throw new Exception("richResource must start with https"); 138 | } 139 | } 140 | break; 141 | } 142 | 143 | 144 | 145 | } 146 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/android/LightSetting.php: -------------------------------------------------------------------------------- 1 | AndroidNotification(light_setting) 20 | * =>AndroidConfig(notification) 21 | * =>PushMessage(android) 22 | */ 23 | namespace push_admin\push_msg\android; 24 | include_once (dirname(__FILE__) . '/../ValidatorUtil.php'); 25 | 26 | use push_admin\ValidatorUtil; 27 | use Exception; 28 | 29 | class LightSetting 30 | { 31 | 32 | private $color; 33 | 34 | private $light_on_duration; 35 | 36 | private $light_off_duration; 37 | 38 | private $fields; 39 | 40 | public function __construct() 41 | { 42 | $this->color = array(); 43 | $this->fields = array(); 44 | } 45 | 46 | public function color($value) 47 | { 48 | $this->color = $value; 49 | } 50 | 51 | public function light_on_duration($value) 52 | { 53 | $this->light_on_duration = $value; 54 | } 55 | 56 | public function light_off_duration($value) 57 | { 58 | $this->light_off_duration = $value; 59 | } 60 | 61 | public function getFields() 62 | { 63 | return $this->fields; 64 | } 65 | 66 | public function buildFields() 67 | { 68 | try { 69 | $this->check_parameter(); 70 | } catch (Exception $e) { 71 | echo $e; 72 | } 73 | $keys = array( 74 | 'color', 75 | 'light_on_duration', 76 | 'light_off_duration' 77 | ); 78 | foreach ($keys as $key) { 79 | if (isset($this->$key)) { 80 | $this->fields[$key] = $this->$key; 81 | } 82 | } 83 | } 84 | 85 | private function check_parameter() 86 | { 87 | if (empty($this->color)){ 88 | throw new Exception("color must be selected when light_settings is set"); 89 | } 90 | if (empty($this->light_on_duration)){ 91 | throw new Exception("light_on_duration must be selected when light_settings is set"); 92 | } 93 | if (empty($this->light_off_duration)){ 94 | throw new Exception("light_off_duration must be selected when light_settings is set"); 95 | } 96 | $LIGTH_DURATION_PATTERN = "/\\d+|\\d+[sS]|\\d+.\\d{1,9}|\\d+.\\d{1,9}[sS]/"; 97 | if ( FALSE == ValidatorUtil::validatePattern($LIGTH_DURATION_PATTERN,$this->light_on_duration)) { 98 | throw new Exception("light_on_duration format is wrong"); 99 | } 100 | if (FALSE == ValidatorUtil::validatePattern($LIGTH_DURATION_PATTERN,$this->light_off_duration) ) { 101 | throw new Exception("light_off_duration format is wrong"); 102 | } 103 | 104 | 105 | } 106 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/android/LightSettingColor.php: -------------------------------------------------------------------------------- 1 | LightSetting(color) 20 | * =>AndroidNotification(light_setting) 21 | * =>AndroidConfig(notification) 22 | * =>PushMessage(android) 23 | */ 24 | namespace push_admin\push_msg\android; 25 | 26 | use Exception; 27 | 28 | class LightSettingColor 29 | { 30 | 31 | private $alpha; 32 | 33 | private $red; 34 | 35 | private $green; 36 | 37 | private $blue; 38 | 39 | private $fields; 40 | 41 | public function __construct() 42 | { 43 | $this->alpha = 1; 44 | $this->red = 0; 45 | $this->green = 0; 46 | $this->blue = 0; 47 | $this->fields = array(); 48 | } 49 | 50 | public function setgenFullcolor($alpha, $red, $green, $blue) 51 | { 52 | $this->alpha = $alpha; 53 | $this->red = $red; 54 | $this->green = $green; 55 | $this->blue = $blue; 56 | } 57 | 58 | public function alpha($value) 59 | { 60 | $this->alpha = $value; 61 | } 62 | 63 | public function red($value) 64 | { 65 | $this->red = $value; 66 | } 67 | 68 | public function green($value) 69 | { 70 | $this->green = $value; 71 | } 72 | 73 | public function blue($value) 74 | { 75 | $this->blue = $value; 76 | } 77 | 78 | public function getFields() 79 | { 80 | return $this->fields; 81 | } 82 | 83 | public function buildFields() 84 | { 85 | try { 86 | $this->check_parameter(); 87 | } catch (Exception $e) { 88 | echo $e; 89 | } 90 | $keys = array( 91 | 'alpha', 92 | 'red', 93 | 'green', 94 | 'blue' 95 | ); 96 | foreach ($keys as $key) { 97 | if (isset($this->$key)) { 98 | $this->fields[$key] = $this->$key; 99 | } 100 | } 101 | } 102 | 103 | private function check_parameter() 104 | { 105 | if (empty($this->alpha) && (gettype($this->alpha) != "integer")) { 106 | throw new Exception("type of alpha is wrong."); 107 | } 108 | if (empty($this->red) && (gettype($this->red) != "integer")) { 109 | throw new Exception("type of red is wrong."); 110 | } 111 | if (empty($this->green) && (gettype($this->green) != "integer")) { 112 | throw new Exception("type of green is wrong."); 113 | } 114 | if (empty($this->blue) && (gettype($this->blue) != "integer")) { 115 | throw new Exception("type of blue is wrong."); 116 | } 117 | } 118 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/apns/Alert.php: -------------------------------------------------------------------------------- 1 | =>PushMessage(apns) for ios channel 20 | */ 21 | namespace push_admin\push_msg\apns; 22 | 23 | include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php'); 24 | use push_admin\PushLogConfig; 25 | use push_admin\Constants; 26 | 27 | 28 | class Alert { 29 | 30 | private $title; 31 | private $body; 32 | private $title_loc_key; 33 | private $title_loc_args; 34 | private $action_loc_key; 35 | private $loc_key; 36 | private $loc_args; 37 | private $launch_image; 38 | 39 | private $fields; 40 | 41 | public function title($value) { 42 | $this->title = $value; 43 | } 44 | public function body($value) { 45 | $this->body = $value; 46 | } 47 | public function title_loc_key($value) { 48 | $this->title_loc_key = $value; 49 | } 50 | public function title_loc_args($value) { 51 | $this->title_loc_args = $value; 52 | } 53 | public function action_loc_key($value) { 54 | $this->action_loc_key = $value; 55 | } 56 | public function loc_key($value) { 57 | $this->loc_key = $value; 58 | } 59 | public function loc_args($value) { 60 | $this->loc_args = $value; 61 | } 62 | public function launch_image($value) { 63 | $this->launch_image = $value; 64 | } 65 | public function getFields() 66 | { 67 | return $this->fields; 68 | } 69 | 70 | public function buildFields() 71 | { 72 | $keys = array( 73 | 'title', 74 | 'body', 75 | 'title-loc-key', 76 | 'title-loc-args', 77 | 'action-loc-key', 78 | 'loc-key', 79 | 'loc-args', 80 | 'launch-image' 81 | ); 82 | foreach ($keys as $key) { 83 | 84 | $value = str_replace('-', '_', $key); 85 | 86 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][before key:' . $key . '][after key:' . $value . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); 87 | if (isset($this->$value)) { 88 | $this->fields[$key] = $this->$value; 89 | } 90 | } 91 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); 92 | 93 | } 94 | 95 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/apns/ApnsConfig.php: -------------------------------------------------------------------------------- 1 | =>PushMessage(apns) for ios channel 20 | */ 21 | namespace push_admin\push_msg\apns; 22 | 23 | 24 | include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php'); 25 | use push_admin\PushLogConfig; 26 | use push_admin\Constants; 27 | 28 | class ApnsConfig 29 | { 30 | private $payload; 31 | private $headers; 32 | private $hms_options; 33 | 34 | private $fields; 35 | 36 | public function __construct() 37 | { 38 | $this->fields = array(); 39 | } 40 | 41 | public function payload($value) 42 | { 43 | $this->payload = $value; 44 | } 45 | public function headers($value) 46 | { 47 | $this->headers = $value; 48 | } 49 | public function hms_options($value) 50 | { 51 | $this->hms_options = $value; 52 | } 53 | public function getFields() 54 | { 55 | return $this->fields; 56 | } 57 | 58 | public function buildFields() 59 | { 60 | 61 | $keys = array( 62 | 'headers', 63 | 'hms_options', 64 | 'payload' 65 | ); 66 | foreach ($keys as $key) { 67 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][key:' . $key . '][value:' . json_encode($this->$key) . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); 68 | if (isset($this->$key)) { 69 | $this->fields[$key] = $this->$key; 70 | } 71 | } 72 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); 73 | 74 | } 75 | 76 | } 77 | 78 | -------------------------------------------------------------------------------- /src/push_admin/push_msg/apns/ApnsHeaders.php: -------------------------------------------------------------------------------- 1 | authorization = $value; 50 | } 51 | 52 | public function apns_id($value) 53 | { 54 | $this->apns_id = $value; 55 | } 56 | 57 | public function apns_expiration($value) 58 | { 59 | $this->apns_expiration = $value; 60 | } 61 | 62 | public function apns_priority($value) 63 | { 64 | $this->apns_priority = $value; 65 | } 66 | 67 | public function apns_topic($value) 68 | { 69 | $this->apns_topic = $value; 70 | } 71 | 72 | public function apns_collapse_id($value) 73 | { 74 | $this->apns_collapse_id = $value; 75 | } 76 | 77 | public function getFields() 78 | { 79 | return $this->fields; 80 | } 81 | 82 | public function buildFields() 83 | { 84 | try { 85 | $this->check_parameter(); 86 | } catch (Exception $e) { 87 | echo $e; 88 | } 89 | $keys = array( 90 | 'authorization', 91 | 'apns-id', 92 | 'apns-expiration', 93 | 'apns-priority', 94 | 'apns-topic', 95 | 'apns-collapse-id' 96 | ); 97 | foreach ($keys as $key) { 98 | 99 | $value = str_replace('-', '_', $key); 100 | 101 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][before key:' . $key . '][after key:' . $value . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); 102 | if (isset($this->$value)) { 103 | $this->fields[$key] = $this->$value; 104 | } 105 | } 106 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); 107 | } 108 | 109 | private function check_parameter() 110 | { 111 | if (! empty($this->authorization)) { 112 | if (FALSE == ValidatorUtil::validatePattern(Constants::APN_AUTHORIZATION_PATTERN, $this->authorization)) { 113 | throw new Exception("authorization must start with bearer"); 114 | } 115 | } 116 | if (! empty($this->apns_id)) { 117 | if (FALSE == ValidatorUtil::validatePattern(Constants::APN_ID_PATTERN, $this->apns_id)) { 118 | throw new Exception("apns-id format error"); 119 | } 120 | } 121 | if (! empty($this->apns_priority)) { 122 | if (! in_array($this->apns_priority, array( 123 | ApnConstant::ANP_PRIORITY_SEND_BY_GROUP, 124 | ApnConstant::ANP_PRIORITY_SEND_IMMEDIATELY 125 | ))) { 126 | throw new Exception("apns-priority should be SEND_BY_GROUP:5 or SEND_IMMEDIATELY:10"); 127 | } 128 | } 129 | if (! empty($this->apns_collapse_id)) { 130 | if (strlen($this->apns_priority) >= 64) { 131 | throw new Exception("Number of apnsCollapseId bytes should be less than 64"); 132 | } 133 | } 134 | } 135 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/apns/ApnsHmsOptions.php: -------------------------------------------------------------------------------- 1 | fields; 30 | } 31 | public function target_user_type($value) 32 | { 33 | $this->target_user_type = $value; 34 | } 35 | public function buildFields() 36 | { 37 | try { 38 | $this->check_parameter(); 39 | } catch (Exception $e) { 40 | echo $e; 41 | } 42 | $keys = array( 43 | 'target_user_type' 44 | ); 45 | foreach ($keys as $key) { 46 | if (isset($this->$key)) { 47 | $this->fields[$key] = $this->$key; 48 | } 49 | } 50 | } 51 | 52 | private function check_parameter() 53 | { 54 | if (!empty($this->target_user_type) 55 | && !in_array($this->target_user_type,array(1,2,3))) { 56 | throw new Exception("target_user_type range TEST_USER:1,FORMAL_USER:2,VOIP_USER:3"); 57 | } 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/push_admin/push_msg/apns/Aps.php: -------------------------------------------------------------------------------- 1 | alert = $value; 37 | } 38 | public function badge($value) { 39 | $this->badge = $value; 40 | } 41 | public function sound($value) { 42 | $this->sound = $value; 43 | } 44 | public function content_available($value) { 45 | $this->content_available = $value; 46 | } 47 | public function category($value) { 48 | $this->category = $value; 49 | } 50 | public function thread_id($value) { 51 | $this->thread_id = $value; 52 | } 53 | 54 | public function getFields() 55 | { 56 | return $this->fields; 57 | } 58 | 59 | public function buildFields() 60 | { 61 | $keys = array( 62 | 'alert', 63 | 'badge', 64 | 'sound', 65 | 'content-available', 66 | 'category', 67 | 'thread-id' 68 | ); 69 | foreach ($keys as $key) { 70 | 71 | $value = str_replace('-', '_', $key); 72 | 73 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][before key:' . $key . '][after key:' . $value . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); 74 | if (isset($this->$value)) { 75 | $this->fields[$key] = $this->$value; 76 | } 77 | } 78 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); 79 | 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/notification/Notification.php: -------------------------------------------------------------------------------- 1 | PushMessage(notification) for ios channel 20 | */ 21 | namespace push_admin\push_msg\notification; 22 | 23 | /** 24 | * optional for message 25 | */ 26 | use Exception; 27 | class Notification 28 | { 29 | 30 | /** 31 | * optional 32 | */ 33 | private $title; 34 | 35 | /** 36 | * optional 37 | */ 38 | private $body; 39 | 40 | /** 41 | * optional 42 | */ 43 | private $image; 44 | 45 | private $fields; 46 | 47 | public function __construct($title, $body, $image) 48 | { 49 | $this->title = $title; 50 | $this->body = $body; 51 | $this->image = $image; 52 | $this->fields = array(); 53 | } 54 | 55 | public function title($value) 56 | { 57 | $this->title = $value; 58 | } 59 | 60 | public function body($value) 61 | { 62 | $this->body = $value; 63 | } 64 | 65 | public function image($value) 66 | { 67 | $this->image = $value; 68 | } 69 | 70 | public function getFields() 71 | { 72 | return $this->fields; 73 | } 74 | 75 | public function buildFields() 76 | { try { 77 | $this->check_parameter(); 78 | } catch (Exception $e) { 79 | echo $e; 80 | } 81 | $keys = array( 82 | 'title', 83 | 'body', 84 | 'image' 85 | ); 86 | foreach ($keys as $key) { 87 | if (isset($this->$key)) { 88 | $this->fields[$key] = $this->$key; 89 | } 90 | } 91 | } 92 | 93 | private function check_parameter() 94 | { 95 | if (empty($this->title)) 96 | { 97 | throw new Exception("title should be set"); 98 | } 99 | if (empty($this->body)) 100 | { 101 | throw new Exception("body should be set"); 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/quickapp/QuickAppConfig.php: -------------------------------------------------------------------------------- 1 | =>PushMessage(apns) for ios channel 20 | */ 21 | namespace push_admin\push_msg\instanceapp; 22 | 23 | 24 | include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php'); 25 | use push_admin\PushLogConfig; 26 | use push_admin\Constants; 27 | 28 | class InstanceAppConfig 29 | { 30 | //push_type 0:notification;1,pass-through 31 | private $pushtype; 32 | private $pushbody; 33 | private $fields; 34 | 35 | public function __construct() 36 | { 37 | } 38 | 39 | public function pushtype($value) 40 | { 41 | $this->pushtype = $value; 42 | } 43 | public function pushbody($value) 44 | { 45 | $this->pushbody = $value; 46 | } 47 | 48 | public function getFields() 49 | { 50 | $result = "{"; 51 | foreach ($this->fields as $key=>$value) { 52 | $result = $result .$key.":".json_encode($value).","; 53 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][result:' .$result, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 54 | } 55 | if (strlen($result) > 1){ 56 | $result = rtrim($result, ","); 57 | } 58 | $result = $result."}"; 59 | return $result; 60 | } 61 | 62 | public function buildFields() 63 | { 64 | 65 | $keys = array( 66 | 'pushtype', 67 | 'pushbody' 68 | ); 69 | foreach ($keys as $key) { 70 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][key:' . $key . '][value:' . json_encode($this->$key) . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); 71 | if (isset($this->$key)) { 72 | $this->fields[$key] = $this->$key; 73 | } 74 | } 75 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); 76 | 77 | } 78 | 79 | } 80 | 81 | -------------------------------------------------------------------------------- /src/push_admin/push_msg/quickapp/QuickAppPushbody.php: -------------------------------------------------------------------------------- 1 | =>PushMessage(apns) for ios channel 20 | */ 21 | namespace push_admin\push_msg\instanceapp; 22 | 23 | 24 | include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php'); 25 | use push_admin\PushLogConfig; 26 | use push_admin\Constants; 27 | 28 | class InstanceAppPushbody 29 | { 30 | // for pass-through 31 | private $messageId; 32 | private $data; 33 | 34 | // for notification 35 | private $title; 36 | private $description; 37 | private $page; 38 | private $params; 39 | private $ringtone; 40 | 41 | private $fields; 42 | 43 | public function __construct() 44 | { 45 | } 46 | 47 | public function messageId($value) 48 | { 49 | $this->messageId = $value; 50 | } 51 | public function data($value) 52 | { 53 | $this->data = $value; 54 | } 55 | 56 | public function title($value) 57 | { 58 | $this->title = $value; 59 | } 60 | public function description($value) 61 | { 62 | $this->description = $value; 63 | } 64 | 65 | public function page($value) 66 | { 67 | $this->page = $value; 68 | } 69 | public function params($value) 70 | { 71 | $this->params = $value; 72 | } 73 | 74 | public function ringtone($value) 75 | { 76 | $this->ringtone = $value; 77 | } 78 | 79 | public function getFields() 80 | { 81 | $result = "{"; 82 | foreach ($this->fields as $key=>$value) { 83 | $result = $result .$key.":".json_encode($value).","; 84 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][result:' .$result, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 85 | } 86 | if (strlen($result) > 1){ 87 | $result = rtrim($result, ","); 88 | } 89 | $result = $result."}"; 90 | return $result; 91 | } 92 | 93 | public function buildFields() 94 | { 95 | 96 | $keys = array( 97 | 'messageId', 98 | 'data', 99 | 'title', 100 | 'description', 101 | 'page', 102 | 'params', 103 | 'ringtone' 104 | ); 105 | foreach ($keys as $key) { 106 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][key:' . $key . '][value:' . json_encode($this->$key) . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); 107 | if (isset($this->$key)) { 108 | $this->fields[$key] = $this->$key; 109 | } 110 | } 111 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); 112 | 113 | } 114 | 115 | } 116 | 117 | -------------------------------------------------------------------------------- /src/push_admin/push_msg/quickapp/QuickAppRingtone.php: -------------------------------------------------------------------------------- 1 | =>PushMessage(apns) for ios channel 20 | */ 21 | namespace push_admin\push_msg\instanceapp; 22 | 23 | include_once (dirname(__FILE__) . '/../../../push_admin/PushLogConfig.php'); 24 | use push_admin\PushLogConfig; 25 | use push_admin\Constants; 26 | 27 | class InstanceAppRingtone 28 | { 29 | 30 | private $vibration; 31 | private $breathLight; 32 | 33 | private $fields; 34 | 35 | public function __construct() 36 | { 37 | $this->fields = array(); 38 | } 39 | 40 | public function vibration($value) 41 | { 42 | $this->vibration = $value; 43 | } 44 | 45 | public function breathLight($value) 46 | { 47 | $this->breathLight = $value; 48 | } 49 | 50 | public function getFields() 51 | { 52 | $result = "{"; 53 | foreach ($this->fields as $key=>$value) { 54 | $result = $result .$key.":".json_encode($value).","; 55 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][result:' .$result, Constants::HW_PUSH_LOG_DEBUG_LEVEL); 56 | } 57 | if (strlen($result) > 1){ 58 | $result = rtrim($result, ","); 59 | } 60 | $result = $result."}"; 61 | return $result; 62 | } 63 | 64 | public function buildFields() 65 | { 66 | $keys = array( 67 | 'vibration', 68 | 'breathLight' 69 | ); 70 | foreach ($keys as $key) { 71 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][key:' . $key . '][value:' . json_encode($this->$key) . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL); 72 | if (isset($this->$key)) { 73 | $this->fields[$key] = $this->$key; 74 | } 75 | } 76 | PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL); 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /src/push_admin/push_msg/webpush/WebPushConfig.php: -------------------------------------------------------------------------------- 1 | PushMessage(webpush) 20 | */ 21 | namespace push_admin\push_msg\webpush; 22 | 23 | class WebPushConfig 24 | { 25 | 26 | private $headers; 27 | 28 | private $data; 29 | 30 | private $notification; 31 | 32 | private $hms_options; 33 | 34 | private $fields; 35 | 36 | public function __construct() 37 | { 38 | $this->headers = array(); 39 | $this->notification = array(); 40 | $this->hmsOptions = array(); 41 | $this->fields = array(); 42 | } 43 | 44 | public function headers($value) 45 | { 46 | $this->headers = $value; 47 | } 48 | 49 | public function data($value) 50 | { 51 | $this->data = $value; 52 | } 53 | 54 | public function notification($value) 55 | { 56 | $this->notification = $value; 57 | } 58 | 59 | public function hmsOptions($value) 60 | { 61 | $this->hms_options = $value; 62 | } 63 | 64 | public function getFields() 65 | { 66 | return $this->fields; 67 | } 68 | 69 | public function buildFields() 70 | { 71 | $keys = array( 72 | 'headers', 73 | 'data', 74 | 'notification', 75 | 'hms_options' 76 | ); 77 | foreach ($keys as $key) { 78 | if (isset($this->$key)) { 79 | $this->fields[$key] = $this->$key; 80 | } 81 | } 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/push_admin/push_msg/webpush/WebPushHeaders.php: -------------------------------------------------------------------------------- 1 | WebPushConfig(headers) 20 | * =>PushMessage(webpush) 21 | */ 22 | namespace push_admin\push_msg\webpush; 23 | 24 | class WebPushHeaders 25 | { 26 | 27 | private $ttl; 28 | 29 | private $topic; 30 | 31 | private $urgency; 32 | 33 | private $fields; 34 | 35 | public function __construct() 36 | { 37 | $this->fields = array(); 38 | } 39 | 40 | public function ttl($value) 41 | { 42 | $this->ttl = $value; 43 | } 44 | 45 | public function topic($value) 46 | { 47 | $this->topic = $value; 48 | } 49 | 50 | public function urgency($value) 51 | { 52 | $this->urgency = $value; 53 | } 54 | 55 | public function getFields() 56 | { 57 | return $this->fields; 58 | } 59 | 60 | public function buildFields() 61 | { 62 | $keys = array( 63 | 'ttl', 64 | 'topic', 65 | 'urgency' 66 | ); 67 | foreach ($keys as $key) { 68 | if (isset($this->$key)) { 69 | $this->fields[$key] = $this->$key; 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/webpush/WebPushHmsOptions.php: -------------------------------------------------------------------------------- 1 | WebPushConfig(hms_options) 20 | * =>PushMessage(webpush) 21 | */ 22 | namespace push_admin\push_msg\webpush; 23 | 24 | 25 | class WebPushHmsOptions 26 | { 27 | private $link; 28 | 29 | private $fields; 30 | 31 | public function __construct() 32 | { 33 | $this->fields = array(); 34 | } 35 | 36 | public function link($value) { 37 | $this->link = $value; 38 | } 39 | 40 | 41 | 42 | public function getFields() { 43 | return $this->fields; 44 | } 45 | 46 | public function buildFields() { 47 | 48 | 49 | $keys = array( 50 | 'link' 51 | ); 52 | foreach ($keys as $key) { 53 | if (isset($this->$key)) { 54 | $this->fields[$key] = $this->$key; 55 | } 56 | } 57 | } 58 | 59 | 60 | 61 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/webpush/WebPushNotification.php: -------------------------------------------------------------------------------- 1 | WebPushConfig(notification) 20 | * =>PushMessage(webpush) 21 | */ 22 | namespace push_admin\push_msg\webpush; 23 | 24 | use Exception; 25 | class WebPushNotification 26 | { 27 | 28 | private $title; 29 | private $body; 30 | private $icon; 31 | private $image; 32 | private $lang; 33 | private $tag; 34 | private $badge; 35 | private $dir; 36 | private $vibrate; 37 | private $renotify; 38 | 39 | private $require_interaction; 40 | private $silent; 41 | private $timestamp; 42 | 43 | private $actions; 44 | 45 | private $fields; 46 | 47 | public function __construct() 48 | { 49 | $this->actions = array(); 50 | $this->fields = array(); 51 | } 52 | 53 | public function title($value) { 54 | $this->title = $value; 55 | } 56 | public function body($value) { 57 | $this->body = $value; 58 | } 59 | public function icon($value) { 60 | $this->icon = $value; 61 | } 62 | public function image($value) { 63 | $this->image = $value; 64 | } 65 | public function lang($value) { 66 | $this->lang = $value; 67 | } 68 | public function tag($value) { 69 | $this->tag = $value; 70 | } 71 | 72 | public function badge($value) { 73 | $this->badge = $value; 74 | } 75 | 76 | public function dir($value) { 77 | $this->dir = $value; 78 | } 79 | public function vibrate($value) { 80 | $this->vibrate = $value; 81 | } 82 | public function renotify($value) { 83 | $this->renotify = $value; 84 | } 85 | public function require_interaction($value) { 86 | $this->require_interaction = $value; 87 | } 88 | 89 | 90 | public function silent($value) { 91 | $this->silent = $value; 92 | } 93 | public function timestamp($value) { 94 | $this->timestamp = $value; 95 | } 96 | public function actions($value) { 97 | $this->actions = $value; 98 | } 99 | 100 | 101 | public function getFields() { 102 | return $this->fields; 103 | } 104 | 105 | public function buildFields() { 106 | try{ 107 | $this->check_parameter(); 108 | }catch (Exception $e) { 109 | echo $e; 110 | } 111 | 112 | $keys = array( 113 | 'title', 114 | 'body', 115 | 'icon', 116 | 'image', 117 | 'lang', 118 | 'tag', 119 | 'badge', 120 | 'dir', 121 | 'vibrate', 122 | 'renotify', 123 | 'require_interaction', 124 | 'silent', 125 | 'timestamp', 126 | 'actions' 127 | ); 128 | foreach ($keys as $key) { 129 | if (isset($this->$key)) { 130 | $this->fields[$key] = $this->$key; 131 | } 132 | } 133 | } 134 | 135 | private function check_parameter() { 136 | if (($this->renotify) && (gettype($this->renotify) != "boolean")) { 137 | throw new Exception("type of renotify is wrong."); 138 | } 139 | if (($this->require_interaction) && (gettype($this->require_interaction) != "boolean")) { 140 | throw new Exception("type of requireInteraction is wrong."); 141 | } 142 | if (($this->silent) && (gettype($this->silent) != "boolean")) { 143 | throw new Exception("type of silent is wrong."); 144 | } 145 | 146 | 147 | } 148 | 149 | } -------------------------------------------------------------------------------- /src/push_admin/push_msg/webpush/WebPushNotificationAction.php: -------------------------------------------------------------------------------- 1 | WebPushNotification(action) 20 | * =>WebPushConfig(notification) 21 | * =>PushMessage(webpush) 22 | */ 23 | namespace push_admin\push_msg\webpush; 24 | 25 | class WebPushNotificationAction 26 | { 27 | 28 | private $title; 29 | 30 | private $icon; 31 | 32 | private $action; 33 | 34 | private $fields; 35 | 36 | public function __construct() 37 | { 38 | $this->fields = array(); 39 | } 40 | 41 | public function title($value) 42 | { 43 | $this->title = $value; 44 | } 45 | 46 | public function action($value) 47 | { 48 | $this->action = $value; 49 | } 50 | 51 | public function icon($value) 52 | { 53 | $this->icon = $value; 54 | } 55 | 56 | public function getFields() 57 | { 58 | return $this->fields; 59 | } 60 | 61 | public function buildFields() 62 | { 63 | $keys = array( 64 | 'title', 65 | 'icon', 66 | 'action' 67 | ); 68 | foreach ($keys as $key) { 69 | if (isset($this->$key)) { 70 | $this->fields[$key] = $this->$key; 71 | } 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | --------------------------------------------------------------------------------