Code Monkey home page Code Monkey logo

hms-core / hms-push-serverdemo-php Goto Github PK

View Code? Open in Web Editor NEW
24.0 15.0 21.0 103 KB

PHP sample code encapsulates APIs of the HUAWEI Push Kit server.It provides many sample PHP programs about quick access to HUAWEI Push Kit for your reference or usage.

Home Page: https://developer.huawei.com/consumer/cn/doc/development/HMS-Guides/push-introduction

License: Apache License 2.0

PHP 100.00%
huawei push hms php push-notifications sendmessage sever

hms-push-serverdemo-php's Introduction

HMS Pushkit PHP Severdemo

English | 中文

Table of Contents

Introduction

PHP sample code encapsulates APIs of the HUAWEI Push Kit server.It provides many sample PHP programs about quick access to HUAWEI Push Kit for your reference or usage.
The following table describes packages of PHP sample code.

Package Description
examples Sample code files. Each PHP file can run independently.
push_admin Package where APIs of the HUAWEI Push Kit server are
encapsulated.

Installation

Before using PHP sample code, check whether the PHP environment has been installed.

Supported Environments

The PHP sample code is debugged based on the XAMPP (MySQL + PHP + PERL) 5.6.26 development suite.

Configuration

The following table describes parameters of the __construct method.

Parameter Description
appid App ID, which is obtained from app information.
appsecret Secret access key of an app, which is obtained from app information.
access_token URL for the Huawei OAuth 2.0 service to obtain a token,
please refer to Generating an App-Level Access Token.
hw_token_server URL for accessing HUAWEI Push Kit, please refer to Sending Messages.

Sample Code

PHP sample code uses the Application structure in the push_admin package as the entry.
Core methods in the Application structure are used to call APIs of the HUAWEI Push Kit server.
The following table lists methods in Application.

Method Description
push_send_msg Sends a message to a device.
common_send_msg Subscribes to a topic, unsubscribes from a topic,
and queries the list of topics subscribed by a device.
__construc Constructor, which obtains key data for sending a message.

1.Send an Android data message.

Code location: examples/test_sample_push_passthrouth_msg.php

2.Send an Android notification message.

Code location: examples/test_sample_push_notification_msg.php

3.Send a message by topic.

Code location: examples/test_sample_push_topic_msg.php

4.Send a message by conditions.

Code location: examples/test_sample_push_condition_msg.php

5.Send a message to a Huawei quick app.

Code location: examples/test_sample_push_instantce_app_msg.php

6.Send a message through the WebPush agent.

Code location: examples/test_sample_push_webpush_msg.php

7.Send a message through the APNs agent.

Code location: examples/test_sample_apns_msg.php

8.Send a test message.

Code location: examples/test_sample_test_push_msg.php

Technical Support

If you want to evaluate more about HMS Core, r/HMSCore on Reddit is for you to keep up with latest news about HMS Core, and to exchange insights with other developers.

If you have questions about how to use HMS samples, try the following options:

  • Stack Overflow is the best place for any programming questions. Be sure to tag your question with huawei-mobile-services.
  • Huawei Developer Forum HMS Core Module is great for general questions, or seeking recommendations and opinions.

If you run into a bug in our samples, please submit an issue to the Repository. Even better you can submit a Pull Request with a fix.

License

Pushkit PHP sample is licensed under the Apache License, version 2.0.

hms-push-serverdemo-php's People

Contributors

hmspushkit avatar mike-mei avatar rmibelgium avatar syslogic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hms-push-serverdemo-php's Issues

Token refresh fails

In method refresh_token() it is being assumed that an array is being returned, which is not the case:

array_key_exists("access_token", $result)

Therefore it should rather be:

property_exists($result, "access_token")

Previously type-checking the $result could prevent passing the wrong data-type:

if (
    $result == null ||
    is_array($result) && !array_key_exists("access_token", $result) ||
    is_object($result) && !property_exists($result, "access_token")
)  {
    return null;
}

minor fixes on unix environment

Hello,
I'm not PHP developer, I'm only able to modify and use foreign code :-) For this reason I will not send pull request :-)

There were problems with carriage return "%0D" char in $appid and $appsecret (probably caused by windows CRLF vs unix LF?)

url_https_post curl send body:grant_type=client_credentials&client_secret=blabla123blabla%0D&client_id=123456%0D

Solution in is trim() before usage.
Without this fix, the refresh token failed, result was null

Second problem:
it does not worked, it was not able to find and create instance of class TestPushMsgCommon()
include_once (dirname(__FILE__) . './push_common/test_sample_push_msg_common.php');
it works after change to:
include_once (dirname(__FILE__) . '/push_common/test_sample_push_msg_common.php');

environment:
Linux & PHP 5.2, macOS & PHP 7.1

Missing folder and files /push_admin/push_msg/instanceapp

Maybe I am a newb, but I can't locate that folder and the files in it and getting errors as a result:

/push_admin/push_msg/instanceapp/InstanceAppConfig.php
/push_admin/push_msg/instanceapp/InstanceAppPushbody.php
/push_admin/push_msg/instanceapp/InstanceAppRingtone.php

Where do you find those files or do you generate them somehow?

Notification treated as advertisement

my push notification being treated as advertisement, and never alert and vibrate. my request body as below.

{ "validate_only": false, "message": { "android": { "notification": { "important": "HIGH", "title": "message title", "body": " message body", "click_action": { "type": 1, "intent": "#Intent;compo=com.rvr/.Activity;S.W=U;end" }, "style": 1, "buttons": [ { "name": "Learn more", "action_type": 1, "intent_type": 0, "intent": "intent://com.huawei.codelabpush/deeplink?#Intent;scheme=pushscheme;launchFlags=0x4000000;i.age=180;S.name=abc;end", "data": "{\"key1\":\"value1\",\"key2\":\"value2\",\"keyn\":\"valuen\"}" } ], "big_title": "HUAWEI Push Kit", "big_body": "HUAWEI Push Kit is a messaging service provided by Huawei for developers. It establishes a messaging channel from the cloud to devices." } }, "token": [ "my_token" ] } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.