Giter Site home page Giter Site logo

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

View Code? Open in Web Editor NEW
51.0 15.0 36.0 59 KB

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

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

License: Apache License 2.0

Go 100.00%
golang huawei push hms push-notifications sendmessage sever

hms-push-serverdemo-go's Introduction

HMS Core Push Kit Sample Code (Golang)

English | 中文

Contents

Introduction

The sample code for Golang encapsulates the server-side APIs of Push Kit, for your reference or direct use.

The following table describes packages of Golang sample code.

Package Description
examples Sample code packages.
httpclient Package for sending network requests.
push Package where Push Kit server APIs are encapsulated.

Installation

Install the Golang environment (Golang 1.11 or later is recommended) and decompress the Golang sample code package.

Copy org.huawei.com in the decompressed package to the vendor directory in the path specified by GOPATH in your project. Refresh the project to ensure that the copied file exists in the directory.

Configuration

Start configuration with the Client structure in the push package. Each method in the Client structure can be used to call an API of the Push Kit server. The following table describes the method in the Client structure.

Method Description
SendMessage Sends a message to a device.

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

The following table describes the parameters in pushcommon.go.

Parameter Description
appId App ID, which is obtained from the app information.
appSecret App secret, which is obtained from the app information.
authUrl URL for Huawei OAuth 2.0 to obtain a token. For details, please refer to OAuth 2.0-based Authentication.
pushUrl Access address of Push Kit. For details, please refer to Downlink Message Sending.

The following table describes the parameters in pushcommon.go.

Parameter Description
TargetTopic Name of the topic to be subscribed to, unsubscribed from, or queried.
TargetCondition Combined condition expression for sending a message.
TargetToken Token of a target device, which is obtained from the target device.
TargetTokenArray Tokens of all target devices, which are obtained from these target 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

You can visit the Reddit community to obtain the latest information about HMS Core and communicate with other developers.

If you have any questions about the sample code, try the following:

  • Visit Stack Overflow, submit your questions, and tag them with huawei-mobile-services. Huawei experts will answer your questions.
  • Visit the HMS Core section in the HUAWEI Developer Forum and communicate with other developers.

If you encounter any issues when using the sample code, submit your issues or submit a pull request.

License

The sample code is licensed under Apache License 2.0.

hms-push-serverdemo-go's People

Contributors

hmspushkit avatar mike-mei 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  avatar  avatar  avatar  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-go's Issues

ForegroundShow flag is being omitted

HMS PushKit ForegroundShow flag defaults to true so this field should be sent explicitly with false in order to don't display a notification when the app is in foreground.

Huawei documentation should also be improved in order to say explicitly that the default value of foreground_show flag is true if it is not sent.

Documentation links:
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-fgrd-show-0000001050040126
https://developer.huawei.com/consumer/en/doc/development/HMSCore-References/https-send-api-0000001050986197#EN-US_TOPIC_0000001134031085__p163211583235

Refresh token is not work

Access token after refresh token is not replace on http request for send push notification.
HTTP request still use previous access token.

Incorrect data type in Color struct

Should Color struct data type be float64 instead of int? hms api gate answers: Illegal payload, blue of color in light settings must rang [0,1] when I pass integer value bigger than 1.

type Color struct {
       	Alpha int `json:"alpha"`
       	Red   int `json:"red"`
       	Green int `json:"green"`
       	Blue  int `json:"blue"`
}

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.