4 Star 6 Fork 4

华为移动服务 / hms-push-serverdemo-go

Gitee — Enterprise-level DevOps R&D management platform
Join Gitee
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

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 target.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

Download Golang sample code in Downloading Server 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: examples/send_data_message/main.go

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: examples/send_notify_message/main.go

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: examples/send_topic_message/main.go

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: examples/send_condition_message/main.go

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

Code location: examples/send_instance_app_message/main.go

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: examples/send_apns_message/main.go

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: examples/send_webpush_message/main.go

8). Send a test message.

Code location: examples/send_test_message/main.go

Question or issues

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.

Repository Comments ( 0 )

Sign in for post a comment

About

华为推送服务服务端Golang示例代码,对华为推送的服务端接口进行封装,包含丰富的示例程序,方便您参考或直接使用。 expand collapse
Go
Apache-2.0
Cancel

Releases

No release

hms-push-serverdemo-go

Contributors

All

Activities

load more
can not load any more
Go
1
https://gitee.com/hms-core/hms-push-serverdemo-go.git
git@gitee.com:hms-core/hms-push-serverdemo-go.git
hms-core
hms-push-serverdemo-go
hms-push-serverdemo-go
master

Search

181749 a2d7925e 1850385 181749 9f8568a7 1850385