hms-push-serverdemo-go

module
v0.0.0-...-6347526 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2023 License: Apache-2.0

README

HMS Pushkit Go Severdemo

English | 中文

Table of Contents

Introduction

Golang sample code encapsulates APIs of the HUAWEI Push Kit server. It provides many sample programs for your reference or usage.

The following describes packages of Golang sample code.

Package Description
examples Sample code packages. Each package can run independently.
httpclient Common package for sending network requests.
push Package where APIs of the HUAWEI Push Kit server are encapsulated.

Installation

Before using Golang sample code, check whether the Golang environment has been installed. Golang 1.11 or a later version is recommended. Decompress the Golang sample code package.

Copy the org.huawei.com package in the decompressed folder to the project vendor directory in the path specified by GOPATH. Refresh the project and ensure that the file is successfully copied to the destination directory.

Configuration

Golang sample code uses the Client structure in the push package as the entry. Each method in the Client structure calls an API of the HUAWEI Push Kit server. The following describes methods in the Client structure.

Method Description
SendMessage Sends a message to a device.

To use functions provided by packages in examples, you need to set related parameters in pushcommon.go in the common package.

The following describes parameters in pushcommon.go.

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

The following table describes parameters in pushcommon.go.

Parameter Description
TargetTopic Name of a topic to be subscribed to, unsubscribed from, or queried.
TargetCondition Combination of condition expressions for a message.
TargetToken Token of a target device, which is obtained from the device.
TargetTokenArray Tokens of all target devices, which are obtained from the devices.

Sample Code

1). Send an Android data message. You can obtain the initialized MessageRequest instance of the data message using the NewTransparentMsgRequest method in the push/model package.

Code location: send_data_message

2). Send an Android notification message. You can obtain the initialized MessageRequest instance of the notification message using the NewNotificationMsgRequest method in the push/model package.

Code location: send_notify_message

3). Send a message by topic. You can send a notification message or data message to a device by topic. Specify the topic after obtaining the MessageRequest instance.

Code location: send_topic_message

4). Send a message by conditions. You can send a notification message or data message to a device by conditions. Specify the conditions after obtaining the MessageRequest instance.

Code location: send_condition_message

5). Send a message to a Huawei quick app. You can send a message to a quick app by setting FastAppTarget.

Code location: send_instance_app_message

6). Send a message through the APNs agent. You can send a message through the APNs agent by setting Apns of the message.

Code location: send_apns_message

7). Send a message through the WebPush agent. You can send a message through the WebPush agent by setting WebPush of the message.

Code location: send_webpush_message

8). Send a test message.

Code location: send_test_message

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 Go sample is licensed under the Apache License, version 2.0.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL