Git Product home page Git Product logo

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

View Code? Open in Web Editor NEW
43.0 15.0 32.0 147 KB

Java 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

Java 100.00%
huawei push hms java push-notifications sendmessage sever

hms-push-serverdemo-java's Introduction

HMS Core Push Kit Sample Code (Java)

English | 中文

Contents

Introduction

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

The following table describes packages of Java sample code.

Package Description
examples Sample code packages.
messaging Package where Push Kit server APIs are encapsulated.

Environment Requirements

JDK 8.0 or later is recommended.

Configuration

Set the following parameters.

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

Sample Code

1. Send an Android data message.

Code location: examples/SendDataMessage.java

2. Send an Android notification message.

Code location: examples/SendNotifyMessage.java

3. Send a message by topic.

Code location: examples/SendTopicMessage.java

4. Send a message by conditions.

Code location: examples/SendConditionMessage.java

5. Send a message to a Huawei quick app.

Code location: examples/SendInstanceAppMessage.java

6. Send a message through the WebPush agent.

Code location: examples/SendWebpushMessage.java

7. Send a message through the APNs agent.

Code location: examples/SendApnsMessage.java

8. Send a test message.

Code location: examples/SendTestMessage.java

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-java's People

Contributors

hmspushkit avatar huawei-mobile-services-core 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

Watchers

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

hms-push-serverdemo-java's Issues

Message.check()存在无意义代码

类Message.check()中存在如下代码:
boolean isEmptyData = StringUtils.isEmpty(data);
isEmptyData并没有参与判断,因此属于无意义代码,如果真的没有用,建议删除。

maven 仓库

这个能统一上传到maven官方仓库吗 方便集成 也方便版本管理

提个简单的建议

Description
SDK的封装可以参考小米的push-SDK

Expected behavior
1.希望SDK提供异步操作的方法
2.希望对消息的返回体封装丰富一些,后面会提供demo(毕竟这个实际影响业务编写)
3.希望增加metric接口方便线上监控

Current behavior
1.目前SDK里面集成fastjson这种有安全漏洞的序列化依赖
2.目前SDK对消息的返回体真是处理的太粗糙了

Screenshots
定义了一个SendResponse返回体,只有80000000才会封装
1.对于非80000000的返回code和message没有封装(特别是message竟然没有了,影响实际业务编写)
2.对于http的exception,直接把状态码给。。。。(这个503频控让业务咋搞,实在不行咱学苹果不限速了)
image

Environment
all Environment

Other
一步步来,看好你

How to use Socks 5 proxy

Hi everyone, I tried pushing the notification with http proxy, it works fine. But I want to use a socks 5 proxy, can you give me example for solve my problem?

AndroidNotification.check(Notification)中提示信息需要更新

根据文档:https://developer.huawei.com/consumer/cn/doc/development/HMSCore-References/https-send-api-0000001050986197#ZH-CN_TOPIC_0000001134031085__p1732019820230,style的取值为0、1、3。
AndroidNotification.check(Notification)中有一段提示信息“style should be one of 0:default, 1: big text, 2: big picture”,这里推测2.big picture应该是已经下线或隐藏,那么提示信息建议改为:"style should be one of 0:default, 1: big text, 1: inbox"

ApnsConfig.Builder中addPayloadAps和addPayload内容相同。

原代码:

        public Builder addPayloadAps(Aps aps) {
            this.aps = aps;
            return this;
        }

        public Builder addPayload(Aps aps) {
            this.aps = aps;
            return this;
        }

两个方法内容相同。ApnsConfig.Builder中缺乏setAps()方法,addPayloadAps()和addPayload()方法容易让人觉得和参数payloadAps和payload相关,容易有误解。建议改为:

        public Builder setAps(Aps aps) {
            this.aps = aps;
            return this;
        }

ApnsHmsOptions类中目标用户类型枚举值错误

根据文档:https://developer.huawei.com/consumer/cn/doc/development/HMSCore-References/https-send-api-0000001050986197#ZH-CN_TOPIC_0000001134031085__p188911438143814
目标用户类型,取值如下:
1:测试用户
2:正式用户
3:VoIP用户

但是ApnsHmsOptions类中:

    private static final int TEST_USER = 1;
    private static final int FORMAL_USER = 1;
    private static final int VOIP_USER = 1;

期望改为

    private static final int TEST_USER = 1;
    private static final int FORMAL_USER = 2;
    private static final int VOIP_USER = 3;

考虑到没有枚举类TargetUserType,因此建议上面的三个枚举值从private改为public。

Alert.Builder中的方法名不应以大写开头

Java中通常方法名是以小写开头的,在Alert.Builder类中,存在两个方法以大写开头,建议修改。
原始代码:

        public Builder AddAllLocArgs(List<String> locArgs) {
            this.locArgs.addAll(locArgs);
            return this;
        }

        public Builder AddLocArg(String locArg) {
            this.locArgs.add(locArg);
            return this;
        }

期望修改后:

        public Builder addAllLocArgs(List<String> locArgs) {
            this.locArgs.addAll(locArgs);
            return this;
        }

        public Builder addLocArg(String locArg) {
            this.locArgs.add(locArg);
            return this;
        }

ResponceCodeProcesser中缺少部分错误码

根据文档:https://developer.huawei.com/consumer/cn/doc/development/HMSCore-References/https-send-api-0000001050986197#ZH-CN_TOPIC_0000001134031085__p173287813234
存在如下错误码:

  • 80100017:同时发送的Topic任务超过100个。
  • 80100018:消息体内容验签不通过。
  • 80300011:无权限发送高级别通知消息。
  • 80600003:请求Oauth服务失败。

但是ResponceCodeProcesser类中并不存在这些错误码,建议增加:

    // 错误码80100016后增加
    put(80100017, "Send task cannot be more than 100 concurrently");
    put(80100018, "The message body cannot pass the verification");
    // 错误码80300010后增加
    put(80300011, "No permission to send high-level notification messages");
    put(80600003, "Request OAuth service failed");

BadgeNotification构造器初始化问题

Description
BadgeNotification类中,原始代码:
public BadgeNotification(Integer addNum, String badgeClass) {
this.addNum = builder().addNum; <----这一行
this.badgeClass = badgeClass;
}

Expected behavior
应该改为:
public BadgeNotification(Integer addNum, String badgeClass) {
this.addNum = addNum;
this.badgeClass = badgeClass;
}

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.