webman push插件 java使用pusher客户端连接认证失败

hsk99

问题描述

java中使用pusher客户端类库连接服务时会出现连接失败问题。

出现原因

java的pusher类库 执行连接地址拼接地时候默认会把端口信息拼接上去,从而导致server进行连接校验的时候无法获取到app_key,导致连接认证失败

截图

截图

截图

当前解决方法

去除这里的空格

截图

680 4 0
4个回答

walkor

感谢反馈,已做兼容

  • 暂无评论

截图
大佬想问个问题,webman USR 有人物联服务应用插件,是不是一定要有一个 类似转接器的东西来转换转换数据(接入 4G DTU:USR-G776、USR-G771),如果没有这个是不是就用不了

kspade

楼主有java的pusher 对接的例子没,方便分享一下不
我去年用java 的pusher 对接push 搞了好多天都没对接上,(我java水平不咋地)
后来被迫自己重新建立了一个 websocket git上找了一份java 的 websocket代码 对接使用的,至今都让我很不爽,因为多搞了一套websocket服务

想直接用push 插件 这样舒服些 但是对接不好

hsk99

Java Pusher Client

package com.hsk99;

import java.util.Set;

import com.alibaba.fastjson.JSONObject;
import com.pusher.client.Pusher;
import com.pusher.client.PusherOptions;
import com.pusher.client.channel.ChannelEventListener;
import com.pusher.client.channel.PresenceChannelEventListener;
import com.pusher.client.channel.PrivateChannelEventListener;
import com.pusher.client.channel.PusherEvent;
import com.pusher.client.channel.User;
import com.pusher.client.connection.ConnectionEventListener;
import com.pusher.client.connection.ConnectionState;
import com.pusher.client.connection.ConnectionStateChange;
import com.pusher.client.util.HttpAuthorizer;

/**
 * Pusher CLient
 *
 * @author HSK
 * @date 2022-03-02 13:46:06
 */
public final class App {

    /**
     * Pusher Server Host
     * 
     * @var string
     */
    static String APP_HOST = "127.0.0.1";

    /**
     * Pusher Server Port
     * 
     * @var int
     */
    static int APP_PORT = 8801;

    /**
     * Pusher app key
     * 
     * @var string
     */
    static String APP_KEY = "8ad6857a617ec78364c04b2c353abfa8";

    /**
     * Pusher private authentication address
     */
    static String APP_AUTH = "http://127.0.0.1:8787/app/pusher/connect/auth?access_key=" + APP_KEY
            + "&user_id=89&user_info={'name':'李四89'}";

    /**
     * Run
     * 
     * @author HSK
     * @date 2022-03-02 13:46:06
     * 
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        PusherOptions options = new PusherOptions()
                .setUseTLS(false)
                .setHost(APP_HOST)
                .setWsPort(APP_PORT)
                .setAuthorizer(new HttpAuthorizer(APP_AUTH));
        Pusher pusher = new Pusher(APP_KEY, options);

        pusher.connect(new ConnectionEventListener() {
            @Override
            public void onConnectionStateChange(ConnectionStateChange change) {
                System.out.println("State changed to " + change.getCurrentState() +
                        " from " + change.getPreviousState());
            }

            @Override
            public void onError(String message, String code, Exception e) {
                System.out.println("There was a problem connecting!");
            }
        }, ConnectionState.ALL);

        // Public channels
        pusher.subscribe("public", new ChannelEventListener() {
            @Override
            public void onSubscriptionSucceeded(String channelName) {
            }

            @Override
            public void onEvent(PusherEvent event) {
                System.out.println("Public channels");

                System.out.println("raw data:" + event.getData());

                JSONObject object = JSONObject.parseObject(event.getData());
                System.out.println("object data:" + object);
            }
        }, "message");

        // Private channels
        pusher.subscribePrivate("private-message", new PrivateChannelEventListener() {
            @Override
            public void onSubscriptionSucceeded(String channelName) {
            }

            @Override
            public void onEvent(PusherEvent event) {
                System.out.println("Private channels");

                System.out.println("raw data:" + event.getData());

                JSONObject object = JSONObject.parseObject(event.getData());
                System.out.println("object data:" + object);
            }

            @Override
            public void onAuthenticationFailure(String message, Exception e) {
            }
        }, "message");

        // Presence channels
        pusher.subscribePresence("presence-message", new PresenceChannelEventListener() {
            @Override
            public void onSubscriptionSucceeded(String channelName) {
            }

            @Override
            public void onEvent(PusherEvent event) {
                System.out.println("Presence channels");

                System.out.println("raw data:" + event.getData());

                JSONObject object = JSONObject.parseObject(event.getData());
                System.out.println("object data:" + object);
            }

            @Override
            public void onAuthenticationFailure(String message, Exception e) {
                System.out.println(message);
            }

            @Override
            public void onUsersInformationReceived(String arg0, Set<User> arg1) {
                System.out.println("Unimplemented method 'onUsersInformationReceived'");
                System.out.println(arg0);
                System.out.println(arg1);
            }

            @Override
            public void userSubscribed(String arg0, User arg1) {
                System.out.println("Unimplemented method 'userSubscribed'");
                System.out.println(arg0);
                System.out.println(arg1);
            }

            @Override
            public void userUnsubscribed(String arg0, User arg1) {
                System.out.println("Unimplemented method 'userUnsubscribed'");
                System.out.println(arg0);
                System.out.println(arg1);
            }
        }, "message");

        pusher.connect();

        while (true) {
            Thread.sleep(1000);
        }
    }
}

运行示例

截图

  • 暂无评论
年代过于久远,无法发表回答
🔝