How to send notification to devices from server with HMS Push Kit - Huawei Developers

{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Before we start learning about today’s topic, I strongly recommend you to go through my previous article i.e. How to know more about the client with Huawei Push Kit. It will help you to have a clear picture of HMS Push Kit.
Let’s Begin
Today in this article we are going to see how to send notification to devices from server using HMS Push Kit. To mimic the server part I am using POSTMAN. It is a great tool when trying to dissect RESTful APIs made by others or test ones you have made yourself. It offers a sleek user interface with which to make HTML requests, without the hassle of writing a bunch of code just to test an API's functionality.
1) The push token which we have received from client side (Mobile or web), we will store them in server side database.
2) Why do we need push token?
Earlier in my article we send a notification from Huawei developer console using push token. We will do the same here using POSTMAN.
3) We need our app Client Id and Client Secret to proceed further.
Actually here our client Id and client secret is our app id and app secret which we will be able to find in our AGC App information section.
4) We need to call two URL to serve the purpose. For both URL, protocol is POST.
   https://oauth-login.cloud.huawei.com/oauth2/v3/token
The above URL will help us to get App-Level Access Token. The Access token as we know expires every 60 minutes. So, we need to call them every 60 minutes if it get expires. This token is required to send notification.
i) POSTMAN Header Parameter
In the header parameter of POSTMAN, we need three Key-Value pair.
ii) POSTMAN Body Parameter
In the body parameter of POSTMAN, we need three Key-Value pair.
iii) The Result
After putting the header and the body parameters, we click the send button to get the access token as a result.
https://push-api.cloud.huawei.com/v1/[App ID]/messages:send
After receiving the App-Level Access token, we will use the token in HTTP header parameter to send notification. In the above URL we will replace App ID with our app id which we will obtained from AGC.
i) POSTMAN Params and Header Parameter
In the POSTMAN you will find a button name as Params. Click the button to put the Key and Value of Params.
In the Authorization value, a space character must be added between Bearer and the value of App-Level Access Token.
ii) POSTMAN Body
iii) The Result
Now What?
Well we can do many things like we can subscribe or unsubscribe to a topic, querying or deleting data as a controller or we can send receipts to a developer's receipt processing server using PUSH Kit Server APIs.
For more information, you can click this link https://forums.developer.huawei.com/forumPortal/en/home

Related

In-App Purchases - Purchase/Subscription Process

Consumable Product Purchase Process
The following figure shows the typical process of purchasing a consumable product.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Process description:
1. Initiate a purchase request.
2. Request a delivery. Verify the signature of purchase details before delivering the requested product. If your app has high security requirements, further send a verification request to the Huawei IAP server through the Verifying the Purchase Token for the Order Service API on your app server.
3. Deliver the product and send the delivery token to your app server. Therefore, the delivery token is retrievable to avoid repeated deliveries even if the consumption fails.
4. Call the consumeOwnedPurchase API to consume the product and send a notification to the Huawei IAP server to update the delivery status. consumeOwnedPurchase is transferred to the API call request. After the consumption is complete, the Huawei IAP server resets the product status to available for purchase. Then the product can be purchased again.
Caution:
If you deliver a product after the consumption, the following exception may occur:
After receiving a consumption request from your app, the Huawei IAP server successfully consumes the product, but does not return the consumption result to your app due to network exceptions. As a result, the consumption already occurs, but the product is not delivered.
This exception is difficult to handle. You are advised to consume the product after the delivery.
Note:
1. This process is also applicable to offline games. The difference is that the tasks performed on your app server are executed by your app.
2. For details about the development process, please refer to the Development Guide.
Non-Consumable Product Purchase Process
The following figure shows the typical process of purchasing a non-consumable product.
1. Initiate a purchase.
2. Request a delivery. Verify the signature of purchase details before delivering the requested product. If your app has high security requirements, further send a verification request to the Huawei IAP server through the Verifying the Purchase Token for the Order Service API on your app server.
3. Deliver the product and send the delivery token to your app server. After the signature verification is successful, use the purchaseState field in the purchase data to determine the purchase status of the product. When the value of purchaseState is 0 (indicating that the product has been purchases), deliver the product.
Note:
For a non-consumable product, a user only needs to purchase the product once and can have it permanently. For details about how to provide services, please refer to Delivering a Non-Consumable Product.
For details about the development process, please refer to the Development Guide.
Subscription Process
The following figure shows the typical subscription process.
Note:
For details about the development process, please refer to Subscription Functions and Development Guide.

Development Guides for Integrating the HUAWEI OneHop Kit 1

You've likely already read the Preparations for Integrating the HUAWEI OneHop Kit 1, and have made all of the necessary preparations to integrate the HUAWEI OneHop Kit to your app. Thus, this article directly addresses the process of integrating the kit.
Via HUAWEI OneHop, app developers can enable app data and status synchronization between devices, such as editing a document synced from a smartphone on a tablet.
1. Cross-device App Synchronization Procedure
Cross-device app synchronization involves the integration and adaptation of the apps on the mobile phone and the tablet. Currently, only supported on the Huawei smartphones and tablets.
Smartphone apps: As the service initiator and data source, the phone app is responsible for sending the data to be synced, such as the video link and progress.
Tablet apps: As the service succeeding end, the tablet app receives the data and service status synced from the mobile phone.
The following figure shows the overall process.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
The app integration process on the smartphone is as follows:
Preparation: Ensure that the app on the smartphone is running in the foreground to trigger the HUAWEI OneHop service.
Event listening: The app registers the OneHop listening API with the system and starts the OneHop event listening.
Event processing: After detecting the tapping action of the user, the system notifies the app of the tapping event using the callback function.
Data synchronization: The app on the mobile phone syncs data to the app on the tablet.
The app integration process on the tablet is as follows:
Preparation: The app on the tablet is not required to run in the foreground. After receiving the data synced from the mobile phone, the tablet system automatically starts the corresponding app. If the app is not installed on the tablet, the system will prompt the user to go to HUAWEI AppGallery to download it.
Event listening: The app registers the OneHop listening API with the system and starts the OneHop event listening.
Data receiving: The system transfers the data synced from the mobile phone to the app using the callback function. In this case, the developer needs to parse the data and sync the app status from the mobile phone.
2. API Description
Development Package Description
OneHop Kit and the HwOneHopSDK class used to implement the APIs, are contained in a JAR package. The member functions of the HwOneHopSDK class can be invoked by certain apps.
Class Description
For more information on obtaining authorization and API descriptions, please click on the following link: https://developer.huawei.com/consumer/en/doc/development/connectivity-Guides/OneHop--guide

Development Guides for Integrating the HUAWEI OneHop Kit 1

You've likely already read the Preparations for Integrating the HUAWEI OneHop Kit 1, and have made all of the necessary preparations to integrate the HUAWEI OneHop Kit to your app. Thus, this article directly addresses the process of integrating the kit.
Via HUAWEI OneHop, app developers can enable app data and status synchronization between devices, such as editing a document synced from a smartphone on a tablet.
1. Cross-device App Synchronization Procedure
Cross-device app synchronization involves the integration and adaptation of the apps on the mobile phone and the tablet. Currently, only supported on the Huawei smartphones and tablets.
Smartphone apps: As the service initiator and data source, the phone app is responsible for sending the data to be synced, such as the video link and progress.
Tablet apps: As the service succeeding end, the tablet app receives the data and service status synced from the mobile phone.
The following figure shows the overall process.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
The app integration process on the smartphone is as follows:
Preparation: Ensure that the app on the smartphone is running in the foreground to trigger the HUAWEI OneHop service.
Event listening: The app registers the OneHop listening API with the system and starts the OneHop event listening.
Event processing: After detecting the tapping action of the user, the system notifies the app of the tapping event using the callback function.
Data synchronization: The app on the mobile phone syncs data to the app on the tablet.
The app integration process on the tablet is as follows:
Preparation: The app on the tablet is not required to run in the foreground. After receiving the data synced from the mobile phone, the tablet system automatically starts the corresponding app. If the app is not installed on the tablet, the system will prompt the user to go to HUAWEI AppGallery to download it.
Event listening: The app registers the OneHop listening API with the system and starts the OneHop event listening.
Data receiving: The system transfers the data synced from the mobile phone to the app using the callback function. In this case, the developer needs to parse the data and sync the app status from the mobile phone.
2. API Description
Development Package Description
OneHop Kit and the HwOneHopSDK class used to implement the APIs, are contained in a JAR package. The member functions of the HwOneHopSDK class can be invoked by certain apps.
Class Description
For more information on obtaining authorization and API descriptions, please click on the following link: https://developer.huawei.com/consumer/en/doc/development/connectivity-Guides/OneHop--guide

Development Guide for Integrating the HUAWEI OneHop Kit 2

HUAWEI OneHop is a core part of Huawei's device distributed technology. It augments traditional NFC technology with additional short-distance technologies to enable efficient collaboration between smartphones and other devices with a single tap. There are a few things that you should know when integrating HUAWEI OneHop Kit:
Steps for Developing Cross-device Shortcuts
You can trigger OneHop shortcuts by doing the following:
(1) Select the device type.
(2) Select a OneHop shortcut that is supported by the device.
(3) On the device, download and integrate the OneHop development package.
(4) Check that the NFC works properly.
(5) Test and complete the certification.
Steps for Integrating the HUAWEI OneHop Kit to Printers
The diagram below shows the full integration process.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
The app on the device invokes OneHop Kit to enable Wi-Fi P2P GO mode and write the Wi-Fi data into the NFC tag. During this step, the app on the printer needs to invoke the APIs to initialize and enable the OneHop service.
Users select the file they want to transfer from their phone, then tap the phone against the NFC tag on the device.
The phone obtains the Wi-Fi connection data and establishes a connection with the device.
The phone sends an image transfer notification to the OneHop Kit integrated on the device. The OneHop Kit receives the notification, then sends this notification to the app on the device to prompt the user to start transferring files.
The user accepts, and the phone sends the file to the device. The device then sends a notification to the app on the device to proceed to the next step. Once the app on the device has received the notification, it starts the printing process.
Note
To enable OneHop Kit to read and write NFC tags, the app on the device must have the corresponding driver APIs it needs to use OneHop. For details, refer to the documentation on driver_adapt.h in API Description.
There are two possible exceptions which may occur during the process. (1) The Wi-Fi-P2P connection disconnects unexpectedly during the transfer; (2) No action is taken within 60 seconds and the OneHop Kit sends a service termination value to the app on the device via a status modification callback to stop the OneHop service.
For details about API definitions, refer to the API Description.
Code Sample
This is how the OneHop demo program invokes APIs to initiate OneHop printing:
Note: For details about codes, refer to Sample Code for integrating OneHop for Linux devices. For details about API descriptions, refer to API for integrating OneHop for Linux devices
NFC Tag Handling and Data Parsing
NFC tag handling: App developers do not need to do this. NFC tags are programmed and attached by hardware vendors and distributed using hardware devices.
Data format parsing: App developers do not need to do this. The system automatically parses the OneHop data in the NFC tag and triggers the corresponding operation procedure.

Integrating New Capabilities of Game Service SDK 5.0.4.302 Using Unity

Background​Recently, I found that Unity had released a demo for Game Service SDK 5.0.4.302. Let’s try this version.
Demo download from GitHub
SDK changes
I discovered that the last version of the Unity plugin for the Game Service SDK was 4.0.1.300, whereas the latest version is 5.0.4.302.
This version contains the following changes:
Added GetGamePlayer and GetGamePlayer(bool isRequirePlayerId) to obtain a player’s unique ID.
Added SetGameTrialProcess to listen to trial duration ending, which is used for preventing game addiction.
Added AccountAuthParamsHelper to obtain further information about a HUAWEI ID, including OpenID, UnionID, and the email address.
Added the OpenId, UnionId, AccessToken, and OpenIdSign parameters to the Player object.
Added AppPlayerInfo to save the information of the current player.
You can view change history details about the Game Service SDK on the official website.
Testing the APIs​In this post, I just ran the Unity demo. If you’re not sure how to package and run a demo, check this post.
AccountAuthParamsHelper​According to the C# source code, Unity supports request authorization in the following way:
AccountAuthParamsHelper authParamsHelper = new AccountAuthParamsHelper(); authParamsHelper.SetAuthorizationCode().SetAccessToken().SetIdToken().SetUid().SetId().SetEmail().CreateParams();
By using this code, you can request information including the authorization code, access token, ID token, UID, ID, and email address.
This part is also included in this document. You can complete configurations as required.
I tapped Login then login in the test app, which displayed the following page.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
I selected Obtain your email address and tapped Authorise and log in. A welcome pop-up was displayed, containing the following information.
The OpenID, UnionID, access token, authorization code, and ID token could be found in the log information.
However, the email address I requested was not obtained. Why did this happen? I contacted Huawei technical support and found that no email address had been configured for the signed-in HUAWEI ID. So, I went to Settings > Account center > Account and security on my Huawei phone and discovered that there was indeed no email address.
After I configured an email address, the address could be obtained. The following figure shows the test result.
Huawei technical support also told me that UIDs currently cannot be obtained.
The latest plugin version allows you to obtain further information about a HUAWEI ID, including a player’s UnionID and OpenID.
GetGamePlayer​This API maps the getGamePlayer API of Game Service SDK 5.0.4.302. According to official documentation, only displayName, openId, unionId, accessToken in the Player object have values. This is how I tested it.
I tapped Player then getGamePlayer in the test app, which displayed the following page.
The result was identical to that described in Huawei’s official documentation.
GetGamePlayer(bool isRequirePlayerId)​This API maps the getGamePlayer(boolean isRequirePlayerId) API of Game Service SDK 5.0.4.302 and allows you to obtain the player ID and OpenID at the same time.
I tapped Player then getGamePlayer(isRequirePlayerId) in the test app, which displayed the following page.
This was also consistent with Huawei’s description.
Usage Description of GetGamePlayer and GetGamePlayer(bool isRequirePlayerId)​For details about how to use the two APIs, please check this document.
setGameTrialProcess​Official documentation states that this API is required for games released in the Chinese mainland in order to prevent game addiction. I skipped this step as my app will be released outside the Chinese mainland. In order to test this API you must submit a request to Huawei.
AppPlayerInfo​This class is used when the savePlayerInfo API is called. I did not test this API as we saved our player information independently, meaning we did not use this API.
Test Summary​Compared with Game Service SDK 4.0.1.300, this version of the Unity plugin has the following major changes:
Allowed you to set what information is obtainable from a HUAWEI ID, including OpenID, UnionID, and the email address.
Added the getGamePlayer API to allow games that have replaced player IDs with OpenIDs or UnionIDs to obtain player information. The getCurrentPlayer API is also available if you use the player ID as a unique user identifier.
Allowed games released in the Chinese mainland to call setGameTrialProcess for game trial support.
Can we use game Service for multiplayer game?

Categories

Resources